energyRegionCoupledFvPatchScalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "Time.H"
30 
31 // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  template<>
36  const char* Foam::NamedEnum
37  <
39  3
40  >::names[] =
41  {
42  "solid",
43  "fluid",
44  "undefined"
45  };
46 }
47 
48 
49 const Foam::NamedEnum
50 <
52  3
53 > Foam::energyRegionCoupledFvPatchScalarField::methodTypeNames_;
54 
55 
56 // * * * * * * * * * * * * * * * * Private members * * * * * * * * * * * * *//
57 
58 void Foam::energyRegionCoupledFvPatchScalarField::setMethod() const
59 {
60  if (method_ == UNDEFINED)
61  {
62  if
63  (
64  this->db().foundObject<compressible::turbulenceModel>
65  (
67  )
68  )
69  {
70  method_ = FLUID;
71  }
72  else
73  {
74  method_ = SOLID;
75  }
76  }
77 
78  if (!nbrThermoPtr_)
79  {
80  nbrThermoPtr_ =
81  (
82  &regionCoupledPatch_.nbrMesh().lookupObject<basicThermo>
83  (
85  )
86  );
87  }
88 
89  if (!thermoPtr_)
90  {
91  thermoPtr_ =
92  (
93  &this->db().lookupObject<basicThermo>
94  (
96  )
97  );
98  }
99 }
100 
101 
102 Foam::tmp<Foam::scalarField> Foam::energyRegionCoupledFvPatchScalarField::
103 kappa() const
104 {
105  switch (method_)
106  {
107  case FLUID:
108  {
109  const compressible::turbulenceModel& turbModel =
110  this->db().lookupObject<compressible::turbulenceModel>
111  (
113  );
114 
115  return turbModel.kappaEff(patch().index());
116  }
117  break;
118 
119  case SOLID:
120  {
121  const basicThermo& thermo =
122  this->db().lookupObject<basicThermo>
123  (
125  );
126 
127  return thermo.kappa(patch().index());
128  }
129  break;
130 
131  case UNDEFINED:
132  {
133  FatalErrorIn("energyRegionCoupledFvPatchScalarField::kappa() const")
134  << " on mesh " << this->db().name() << " patch "
135  << patch().name()
136  << " could not find a method in. Methods are: "
137  << methodTypeNames_.toc()
138  << " Not turbulenceModel or thermophysicalProperties"
139  << " were found"
140  << exit(FatalError);
141  }
142  break;
143  }
144  return scalarField(0);
145 }
146 
147 
148 Foam::tmp<Foam::scalarField> Foam::energyRegionCoupledFvPatchScalarField::
149 weights() const
150 {
151  const fvPatch& patch = regionCoupledPatch_.patch();
152 
153  const scalarField deltas
154  (
155  patch.nf() & patch.delta()
156  );
157 
158  const scalarField alphaDelta(kappa()/deltas);
159 
160  const fvPatch& nbrPatch = regionCoupledPatch_.neighbFvPatch();
161 
162  const energyRegionCoupledFvPatchScalarField& nbrField =
163  refCast
164  <
166  >
167  (
168  nbrPatch.lookupPatchField<volScalarField, scalar>("T")
169  );
170 
171  // Needed in the first calculation of weights
172  nbrField.setMethod();
173 
174  const scalarField nbrAlpha
175  (
176  regionCoupledPatch_.regionCoupledPatch().interpolate
177  (
178  nbrField.kappa()
179  )
180  );
181 
182  const scalarField nbrDeltas
183  (
184  regionCoupledPatch_.regionCoupledPatch().interpolate
185  (
186  nbrPatch.nf() & nbrPatch.delta()
187  )
188  );
189 
190  const scalarField nbrAlphaDelta(nbrAlpha/nbrDeltas);
191 
192  tmp<scalarField> tw(new scalarField(deltas.size()));
193  scalarField& w = tw();
194 
195  forAll(alphaDelta, faceI)
196  {
197  scalar di = alphaDelta[faceI];
198  scalar dni = nbrAlphaDelta[faceI];
199 
200  w[faceI] = di/(di + dni);
201  }
202 
203  return tw;
204 }
205 
206 
207 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
208 
211 (
212  const fvPatch& p,
214 )
215 :
217  regionCoupledPatch_(refCast<const regionCoupledBaseFvPatch>(p)),
218  method_(UNDEFINED),
219  nbrThermoPtr_(NULL),
220  thermoPtr_(NULL)
221 {}
222 
223 
226 (
228  const fvPatch& p,
230  const fvPatchFieldMapper& mapper
231 )
232 :
233  coupledFvPatchField<scalar>(ptf, p, iF, mapper),
234  regionCoupledPatch_(refCast<const regionCoupledBaseFvPatch>(p)),
235  method_(ptf.method_),
236  nbrThermoPtr_(NULL),
237  thermoPtr_(NULL)
238 {}
239 
240 
243 (
244  const fvPatch& p,
246  const dictionary& dict
247 )
248 :
250  regionCoupledPatch_(refCast<const regionCoupledBaseFvPatch>(p)),
251  method_(UNDEFINED),
252  nbrThermoPtr_(NULL),
253  thermoPtr_(NULL)
254 {
255 
256  if (!isA<regionCoupledBase>(this->patch().patch()))
257  {
259  (
260  "energyRegionCoupledFvPatchScalarField::"
261  "energyRegionCoupledFvPatchScalarField\n"
262  "(\n"
263  " const fvPatch& p,\n"
264  " const DimensionedField<scalar, volMesh>& iF,\n"
265  " const dictionary& dict\n"
266  ")\n"
267  ) << "\n patch type '" << p.type()
268  << "' not type '" << regionCoupledBase::typeName << "'"
269  << "\n for patch " << p.name()
270  << " of field " << dimensionedInternalField().name()
271  << " in file " << dimensionedInternalField().objectPath()
272  << exit(FatalError);
273  }
274 }
275 
276 
279 (
281 )
282 :
284  regionCoupledPatch_(ptf.regionCoupledPatch_),
285  method_(ptf.method_),
286  nbrThermoPtr_(NULL),
287  thermoPtr_(NULL)
288 {}
289 
290 
293 (
296 )
297 :
299  regionCoupledPatch_(ptf.regionCoupledPatch_),
300  method_(ptf.method_),
301  nbrThermoPtr_(NULL),
302  thermoPtr_(NULL)
303 {}
304 
305 
306 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
307 
309 snGrad() const
310 {
311  Debug("snGrad");
312  return
313  regionCoupledPatch_.patch().deltaCoeffs()
314  *(*this - patchInternalField());
315 }
316 
317 
319 snGrad(const scalarField&) const
320 {
321  Debug("snGrad");
322  return snGrad();
323 }
324 
325 
327 (
328  const Pstream::commsTypes
329 )
330 {
331  if (!updated())
332  {
333  updateCoeffs();
334  }
335 
336  label patchi = patch().index();
337  const scalarField& pp = thermoPtr_->p().boundaryField()[patchi];
338 
339  const scalarField lWeights(weights());
340 
342  (
343  thermoPtr_->he
344  (
345  pp,
346  lWeights*patchInternalTemperatureField()
347  + (1.0 - lWeights)*patchNeighbourTemperatureField(),
348  patchi
349  )
350  );
351 
353 }
354 
355 
359 {
360  const fvPatch& nbrPatch = regionCoupledPatch_.neighbFvPatch();
361 
362  const labelUList& nbrFaceCells = nbrPatch.faceCells();
363 
364  setMethod();
365 
366  const scalarField nbrIntT
367  (
368  nbrThermoPtr_->T().internalField(), nbrFaceCells
369  );
370 
371  scalarField intNbrT
372  (
373  regionCoupledPatch_.regionCoupledPatch().interpolate(nbrIntT)
374  );
375 
376  label patchi = patch().index();
377  const scalarField& pp = thermoPtr_->p().boundaryField()[patchi];
378  tmp<scalarField> tmyHE = thermoPtr_->he(pp, intNbrT, patchi);
379 
380  return tmyHE;
381 }
382 
383 
384 Foam::tmp<Foam::scalarField> Foam::energyRegionCoupledFvPatchScalarField::
385 patchNeighbourTemperatureField() const
386 {
387  const fvPatch& nbrPatch = regionCoupledPatch_.neighbFvPatch();
388 
389  const labelUList& nbrFaceCells = nbrPatch.faceCells();
390 
391  const scalarField nbrIntT
392  (
393  nbrThermoPtr_->T().internalField(), nbrFaceCells
394  );
395 
396  tmp<scalarField> tintNbrT =
397  regionCoupledPatch_.regionCoupledPatch().interpolate(nbrIntT);
398 
399  return tintNbrT;
400 }
401 
402 
403 Foam::tmp<Foam::scalarField> Foam::energyRegionCoupledFvPatchScalarField::
404 patchInternalTemperatureField() const
405 {
406  const labelUList& faceCells = regionCoupledPatch_.faceCells();
407 
408  tmp<scalarField> tintT
409  (
410  new scalarField(thermoPtr_->T().internalField(), faceCells)
411  );
412 
413  return tintT;
414 }
415 
416 
418 (
419  Field<scalar>& result,
420  const scalarField& psiInternal,
421  const scalarField& coeffs,
422  const direction cmpt,
423  const Pstream::commsTypes
424 ) const
425 {
426  setMethod();
427 
428  scalarField myHE(this->size());
429 
430  if (&psiInternal == &internalField())
431  {
432  label patchi = this->patch().index();
433  const scalarField& pp = thermoPtr_->p().boundaryField()[patchi];
434  const scalarField& Tp = thermoPtr_->T().boundaryField()[patchi];
435 
436  myHE = thermoPtr_->he(pp, Tp, patchi);
437  }
438  else
439  {
440  //NOTE: This is not correct for preconditioned solvers
441  // psiInternal is not the information needed of the slave
442  forAll(*this, facei)
443  {
444  myHE[facei] = psiInternal[regionCoupledPatch_.faceCells()[facei]];
445  }
446  }
447 
448  // Multiply the field by coefficients and add into the result
449  const labelUList& faceCells = regionCoupledPatch_.faceCells();
450 
451  forAll(faceCells, elemI)
452  {
453  result[faceCells[elemI]] -= coeffs[elemI]*myHE[elemI];
454  }
455 }
456 
457 
459 (
460  Field<scalar>& result,
461  const Field<scalar>& psiInternal,
462  const scalarField& coeffs,
463  const Pstream::commsTypes
464 ) const
465 {
467  (
468  "energyRegionCoupledFvPatchScalarField::updateInterfaceMatrix()"
469  "("
470  "Field<scalar>& "
471  "const Field<scalar>&"
472  "const scalarField& "
473  "const Pstream::commsTypes"
474  );
475 }
476 
477 
479 {
481  this->writeEntry("value", os);
482 }
483 
484 
485 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
486 
487 namespace Foam
488 {
490  (
493  );
494 };
495 
496 
497 // ************************************************************************* //
unsigned char direction
Definition: direction.H:43
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual tmp< volScalarField > kappaEff() const
Return the effective turbulent thermal diffusivity for temperature.
virtual tmp< vectorField > delta() const
Return cell-centre to face-centre vector.
Definition: fvPatch.C:142
virtual tmp< volScalarField > kappa() const =0
Thermal diffusivity for temperature of mixture [J/m/s/K].
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:625
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:52
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::fvPatchFieldMapper.
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:93
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:354
energyRegionCoupledFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Namespace for OpenFOAM.
#define Debug(var)
Report a variable name and value.
const GeometricField::PatchFieldType & lookupPatchField(const word &name, const GeometricField *=NULL, const Type *=NULL) const
Lookup and return the patchField of the named field from the.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:143
dictionary dict
virtual tmp< scalarField > patchNeighbourField() const
Return neighbour coupled internal cell data.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
volScalarField & p
Definition: createFields.H:51
Energy region coupled implicit boundary condition. The fvPatch is treated as uncoupled from the delta...
commsTypes
Types of communications.
Definition: UPstream.H:64
#define forAll(list, i)
Definition: UList.H:421
label patchi
Macros for easy insertion into run-time selection tables.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:323
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
rDeltaT dimensionedInternalField()
tmp< vectorField > nf() const
Return face normals.
Definition: fvPatch.C:124
error FatalError
virtual tmp< scalarField > snGrad() const
Return patch-normal gradient.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const word propertiesName
Default name of the turbulence properties dictionary.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
makePatchTypeField(fvPatchVectorField, SRFFreestreamVelocityFvPatchVectorField)
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:106
virtual void updateInterfaceMatrix(Field< scalar > &result, const scalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
#define notImplemented(functionName)
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:356
friend Ostream & operator(Ostream &, const Field< scalar > &)
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
const dimensionedScalar kappa
Coulomb constant: default SI units: [N.m2/C2].
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
A class for managing temporary objects.
Definition: PtrList.H:118
conserve internalField()+