regionModel.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "regionModel.H"
30 #include "fvMesh.H"
31 #include "Time.H"
32 #include "mappedWallPolyPatch.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace regionModels
40 {
41  defineTypeNameAndDebug(regionModel, 0);
42 }
43 }
44 
45 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
46 
47 void Foam::regionModels::regionModel::constructMeshObjects()
48 {
49  // construct region mesh
50  if (!time_.foundObject<fvMesh>(regionName_))
51  {
52  regionMeshPtr_.reset
53  (
54  new fvMesh
55  (
56  IOobject
57  (
59  time_.timeName(),
60  time_,
62  )
63  )
64  );
65  }
66 }
67 
68 
69 void Foam::regionModels::regionModel::initialise()
70 {
71  if (debug)
72  {
73  Pout<< "regionModel::initialise()" << endl;
74  }
75 
76  label nBoundaryFaces = 0;
77  DynamicList<label> primaryPatchIDs;
78  DynamicList<label> intCoupledPatchIDs;
79  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
80 
81  forAll(rbm, patchi)
82  {
83  const polyPatch& regionPatch = rbm[patchi];
84  if (isA<mappedPatchBase>(regionPatch))
85  {
86  if (debug)
87  {
88  Pout<< "found " << mappedWallPolyPatch::typeName
89  << " " << regionPatch.name() << endl;
90  }
91 
92  intCoupledPatchIDs.append(patchi);
93 
94  nBoundaryFaces += regionPatch.faceCells().size();
95 
96  const mappedPatchBase& mapPatch =
97  refCast<const mappedPatchBase>(regionPatch);
98 
99  if
100  (
101  primaryMesh_.time().foundObject<polyMesh>
102  (
103  mapPatch.sampleRegion()
104  )
105  )
106  {
107 
108  const label primaryPatchi = mapPatch.samplePolyPatch().index();
109  primaryPatchIDs.append(primaryPatchi);
110  }
111  }
112  }
113 
114  primaryPatchIDs_.transfer(primaryPatchIDs);
115  intCoupledPatchIDs_.transfer(intCoupledPatchIDs);
116 
117  if (returnReduce(nBoundaryFaces, sumOp<label>()) == 0)
118  {
120  << "Region model has no mapped boundary conditions - transfer "
121  << "between regions will not be possible" << endl;
122  }
123 
124  if (!outputPropertiesPtr_.valid())
125  {
126  const fileName uniformPath(word("uniform")/"regionModels");
127 
128  outputPropertiesPtr_.reset
129  (
130  new IOdictionary
131  (
132  IOobject
133  (
134  regionName_ + "OutputProperties",
135  time_.timeName(),
136  uniformPath/regionName_,
137  primaryMesh_,
140  )
141  )
142  );
143  }
144 }
145 
146 
147 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
148 
150 {
151  if (regIOobject::read())
152  {
153  if (active_)
154  {
155  if (const dictionary* dictptr = findDict(modelName_ + "Coeffs"))
156  {
157  coeffs_ <<= *dictptr;
158  }
159 
160  infoOutput_.readIfPresent("infoOutput", *this);
161  }
162 
163  return true;
164  }
165 
166  return false;
167 }
168 
169 
171 {
172  if (active_)
173  {
174  if (const dictionary* dictptr = dict.findDict(modelName_ + "Coeffs"))
175  {
176  coeffs_ <<= *dictptr;
177  }
178 
179  infoOutput_.readIfPresent("infoOutput", dict);
180  return true;
181  }
182 
183  return false;
184 }
185 
186 
189 (
190  const regionModel& nbrRegion,
191  const label regionPatchi,
192  const label nbrPatchi,
193  const bool flip
194 ) const
195 {
196  label nbrRegionID = interRegionAMINames_.find(nbrRegion.name());
197 
198  const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
199 
200  if (nbrRegionID != -1)
201  {
202  if (!interRegionAMI_[nbrRegionID].set(regionPatchi))
203  {
204  const polyPatch& p = regionMesh().boundaryMesh()[regionPatchi];
205  const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchi];
206 
207  int oldTag = UPstream::msgType();
208  UPstream::msgType() = oldTag + 1;
209 
210  interRegionAMI_[nbrRegionID].set
211  (
212  regionPatchi,
214  (
215  p,
216  nbrP,
218  true,
220  -1,
221  flip
222  )
223  );
224 
225  UPstream::msgType() = oldTag;
226  }
227 
228  return interRegionAMI_[nbrRegionID][regionPatchi];
229  }
230  else
231  {
232  label nbrRegionID = interRegionAMINames_.size();
233 
234  interRegionAMINames_.append(nbrRegion.name());
235 
236  const polyPatch& p = regionMesh().boundaryMesh()[regionPatchi];
237  const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchi];
238 
239  label nPatch = regionMesh().boundaryMesh().size();
240 
241 
242  interRegionAMI_.resize(nbrRegionID + 1);
243 
244  interRegionAMI_.set
245  (
246  nbrRegionID,
248  );
249 
250  int oldTag = UPstream::msgType();
251  UPstream::msgType() = oldTag + 1;
252 
253  interRegionAMI_[nbrRegionID].set
254  (
255  regionPatchi,
257  (
258  p,
259  nbrP,
261  true,
263  -1,
264  flip
265  )
266  );
267 
268  UPstream::msgType() = oldTag;
269 
270  return interRegionAMI_[nbrRegionID][regionPatchi];
271  }
272 }
273 
274 
276 (
277  const regionModel& nbrRegion,
278  const label regionPatchi
279 ) const
280 {
281  label nbrPatchi = -1;
282 
283  // region
284  const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
285 
286  // boundary mesh
287  const polyBoundaryMesh& nbrPbm = nbrRegionMesh.boundaryMesh();
288 
289  const polyBoundaryMesh& pbm = regionMesh().boundaryMesh();
290 
291  if (regionPatchi > pbm.size() - 1)
292  {
294  << "region patch index out of bounds: "
295  << "region patch index = " << regionPatchi
296  << ", maximum index = " << pbm.size() - 1
297  << abort(FatalError);
298  }
299 
300  const polyPatch& pp = regionMesh().boundaryMesh()[regionPatchi];
301 
302  if (!isA<mappedPatchBase>(pp))
303  {
305  << "Expected a " << mappedPatchBase::typeName
306  << " patch, but found a " << pp.type() << abort(FatalError);
307  }
308 
309  const mappedPatchBase& mpb = refCast<const mappedPatchBase>(pp);
310 
311  // sample patch name on the primary region
312  const word& primaryPatchName = mpb.samplePatch();
313 
314  // find patch on nbr region that has the same sample patch name
315  forAll(nbrRegion.intCoupledPatchIDs(), j)
316  {
317  const label nbrRegionPatchi = nbrRegion.intCoupledPatchIDs()[j];
318 
319  const mappedPatchBase& mpb =
320  refCast<const mappedPatchBase>(nbrPbm[nbrRegionPatchi]);
321 
322  if (mpb.samplePatch() == primaryPatchName)
323  {
324  nbrPatchi = nbrRegionPatchi;
325  break;
326  }
327  }
328 
329  if (nbrPatchi == -1)
330  {
331  const polyPatch& p = regionMesh().boundaryMesh()[regionPatchi];
332 
334  << "Unable to find patch pair for local patch "
335  << p.name() << " and region " << nbrRegion.name()
336  << abort(FatalError);
337  }
338 
339  return nbrPatchi;
340 }
341 
342 
343 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
344 
345 Foam::regionModels::regionModel::regionModel
346 (
347  const fvMesh& mesh,
348  const word& regionType
349 )
350 :
352  (
353  IOobject
354  (
355  regionType + "Properties",
356  mesh.time().constant(),
357  mesh.time(),
360  )
361  ),
362  primaryMesh_(mesh),
363  time_(mesh.time()),
364  active_(false),
365  infoOutput_(false),
366  modelName_("none"),
367  regionMeshPtr_(nullptr),
368  coeffs_(dictionary::null),
369  outputPropertiesPtr_(nullptr),
370  primaryPatchIDs_(),
371  intCoupledPatchIDs_(),
372  regionName_("none"),
373  functions_(*this),
374  interRegionAMINames_(),
375  interRegionAMI_()
376 {}
377 
378 
379 Foam::regionModels::regionModel::regionModel
380 (
381  const fvMesh& mesh,
382  const word& regionType,
383  const word& modelName,
384  bool readFields
385 )
386 :
388  (
389  IOobject
390  (
391  regionType + "Properties",
392  mesh.time().constant(),
393  mesh.time(),
396  )
397  ),
398  primaryMesh_(mesh),
399  time_(mesh.time()),
400  active_(get<Switch>("active")),
401  infoOutput_(true),
402  modelName_(modelName),
403  regionMeshPtr_(nullptr),
404  coeffs_(subOrEmptyDict(modelName + "Coeffs")),
405  outputPropertiesPtr_(nullptr),
406  primaryPatchIDs_(),
407  intCoupledPatchIDs_(),
408  regionName_(lookup("region")),
409  functions_(*this, subOrEmptyDict("functions"))
410 {
411  if (active_)
412  {
413  constructMeshObjects();
414  initialise();
415 
416  if (readFields)
417  {
418  read();
419  }
420  }
421 }
422 
423 
424 Foam::regionModels::regionModel::regionModel
425 (
426  const fvMesh& mesh,
427  const word& regionType,
428  const word& modelName,
429  const dictionary& dict,
430  bool readFields
431 )
432 :
434  (
435  IOobject
436  (
437  regionType + "Properties",
438  mesh.time().constant(),
439  mesh.time(),
442  true
443  ),
444  dict
445  ),
446  primaryMesh_(mesh),
447  time_(mesh.time()),
448  active_(dict.get<Switch>("active")),
449  infoOutput_(false),
450  modelName_(modelName),
451  regionMeshPtr_(nullptr),
452  coeffs_(dict.subOrEmptyDict(modelName + "Coeffs")),
453  outputPropertiesPtr_(nullptr),
454  primaryPatchIDs_(),
455  intCoupledPatchIDs_(),
456  regionName_(dict.lookup("region")),
457  functions_(*this, subOrEmptyDict("functions"))
458 {
459  if (active_)
460  {
461  constructMeshObjects();
462  initialise();
463 
464  if (readFields)
465  {
466  read(dict);
467  }
468  }
469 }
470 
471 
472 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
473 
475 {}
476 
477 
478 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
479 
481 {
482  if (active_)
483  {
484  Info<< "\nEvolving " << modelName_ << " for region "
485  << regionMesh().name() << endl;
486 
487  preEvolveRegion();
488 
489  evolveRegion();
490 
491  postEvolveRegion();
492 
493  // Provide some feedback
494  if (infoOutput_)
495  {
496  Info<< incrIndent;
497  info();
498  Info<< endl << decrIndent;
499  }
500 
501  if (time_.writeTime())
502  {
503  outputProperties().writeObject
504  (
507  time_.writeCompression(),
508  true
509  );
510  }
511  }
512 }
513 
514 
516 {
517  functions_.preEvolveRegion();
518 }
519 
520 
522 {}
523 
524 
526 {
527  functions_.postEvolveRegion();
528 }
529 
530 
532 {}
533 
534 
535 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:70
mappedWallPolyPatch.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::regionModels::regionModel::evolveRegion
virtual void evolveRegion()
Evolve the region.
Definition: regionModel.C:521
Foam::regionModels::regionModel::info
virtual void info()
Provide some feedback.
Definition: regionModel.C:531
Foam::AMIInterpolation::imFaceAreaWeight
Definition: AMIInterpolation.H:94
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:764
Foam::regionModels::regionModel::regionMeshPtr_
autoPtr< fvMesh > regionMeshPtr_
Pointer to the region mesh database.
Definition: regionModel.H:101
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:202
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
regionModel.H
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
Foam::mappedPatchBase
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
Definition: mappedPatchBase.H:105
Foam::baseIOdictionary::name
const word & name() const
Name function is needed to disambiguate those inherited.
Definition: baseIOdictionary.C:88
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:314
Foam::objectRegistry::foundObject
bool foundObject(const word &name, const bool recursive=false) const
Is the named Type found?
Definition: objectRegistryTemplates.C:379
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::regionModels::regionModel
Base class for region models.
Definition: regionModel.H:59
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:385
Foam::label
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:62
Foam::polyPatch::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:305
Foam::regionModels::regionModel::postEvolveRegion
virtual void postEvolveRegion()
Post-evolve region.
Definition: regionModel.C:525
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::OSstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:91
Foam::cellModeller::lookup
const cellModel * lookup(const word &modelName)
Deprecated(2017-11) equivalent to cellModel::ptr static method.
Definition: cellModeller.H:46
Foam::regionModels::regionModel::regionMesh
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:63
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:122
Foam::regionModels::regionModel::preEvolveRegion
virtual void preEvolveRegion()
Pre-evolve region.
Definition: regionModel.C:515
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
Foam::regionModels::regionModel::read
virtual bool read()
Read control parameters from dictionary.
Definition: regionModel.C:149
Foam::regionModels::regionModel::nbrCoupledPatchID
label nbrCoupledPatchID(const regionModel &nbrRegion, const label regionPatchi) const
Return the coupled patch ID paired with coupled patch.
Definition: regionModel.C:276
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::regionModels::defineTypeNameAndDebug
defineTypeNameAndDebug(regionModel, 0)
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:321
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::regionModels::regionModel::interRegionAMI
virtual const AMIPatchToPatchInterpolation & interRegionAMI(const regionModel &nbrRegion, const label regionPatchi, const label nbrPatchi, const bool flip) const
Create or return a new inter-region AMI object.
Definition: regionModel.C:189
Foam::PtrList::resize
void resize(const label newLen)
Adjust size of PtrList.
Definition: PtrList.C:103
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Time.H
Foam::regionModels::regionModel::~regionModel
virtual ~regionModel()
Destructor.
Definition: regionModel.C:474
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
Foam::UPstream::msgType
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:491
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::regionModels::regionModel::time_
const Time & time_
Reference to the time database.
Definition: regionModel.H:89
Foam::regionModels::regionModel::evolve
virtual void evolve()
Main driver routing to evolve the region - calls other evolves.
Definition: regionModel.C:480
Foam::IOobject::IOobject
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:276
Foam::AMIInterpolation
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Definition: AMIInterpolation.H:81
Foam::IOobject::NO_READ
Definition: IOobject.H:123
zeroGradientFvPatchFields.H
Foam::regionModels::regionModel::intCoupledPatchIDs
const labelList & intCoupledPatchIDs() const
Return the list of patch IDs internally coupled with the.
Definition: regionModelI.H:182
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::regionModels::regionModel::regionName_
word regionName_
Region name.
Definition: regionModel.H:120
Foam::faceAreaIntersect::tmMesh
Definition: faceAreaIntersect.H:65
Foam::IOobject::MUST_READ
Definition: IOobject.H:120
Foam::mappedPatchBase::samplePatch
const word & samplePatch() const
Patch (only if NEARESTPATCHFACE)
Definition: mappedPatchBaseI.H:61