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 | Copyright (C) 2011-2014 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 
26 #include "regionModel.H"
27 #include "fvMesh.H"
28 #include "Time.H"
29 #include "mappedWallPolyPatch.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace regionModels
37 {
38  defineTypeNameAndDebug(regionModel, 0);
39 }
40 }
41 
42 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
43 
44 void Foam::regionModels::regionModel::constructMeshObjects()
45 {
46  // construct region mesh
47  if (!time_.foundObject<fvMesh>(regionName_))
48  {
49  regionMeshPtr_.reset
50  (
51  new fvMesh
52  (
53  IOobject
54  (
55  regionName_,
56  time_.timeName(),
57  time_,
59  )
60  )
61  );
62  }
63 }
64 
65 
66 void Foam::regionModels::regionModel::constructMeshObjects
67 (
68  const dictionary& dict
69 )
70 {
71  // construct region mesh
72  if (!time_.foundObject<fvMesh>(regionName_))
73  {
74  regionMeshPtr_.reset
75  (
76  new fvMesh
77  (
78  IOobject
79  (
80  regionName_,
81  time_.timeName(),
82  time_,
84  )
85  )
86  );
87  }
88 }
89 
90 
91 void Foam::regionModels::regionModel::initialise()
92 {
93  if (debug)
94  {
95  Pout<< "regionModel::initialise()" << endl;
96  }
97 
98  label nBoundaryFaces = 0;
99  DynamicList<label> primaryPatchIDs;
100  DynamicList<label> intCoupledPatchIDs;
101  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
102 
103  forAll(rbm, patchI)
104  {
105  const polyPatch& regionPatch = rbm[patchI];
106  if (isA<mappedPatchBase>(regionPatch))
107  {
108  if (debug)
109  {
110  Pout<< "found " << mappedWallPolyPatch::typeName
111  << " " << regionPatch.name() << endl;
112  }
113 
114  intCoupledPatchIDs.append(patchI);
115 
116  nBoundaryFaces += regionPatch.faceCells().size();
117 
118  const mappedPatchBase& mapPatch =
119  refCast<const mappedPatchBase>(regionPatch);
120 
121  if
122  (
123  primaryMesh_.time().foundObject<polyMesh>
124  (
125  mapPatch.sampleRegion()
126  )
127  )
128  {
129 
130  const label primaryPatchI = mapPatch.samplePolyPatch().index();
131  primaryPatchIDs.append(primaryPatchI);
132  }
133  }
134  }
135 
136  primaryPatchIDs_.transfer(primaryPatchIDs);
137  intCoupledPatchIDs_.transfer(intCoupledPatchIDs);
138 
139  if (returnReduce(nBoundaryFaces, sumOp<label>()) == 0)
140  {
141  WarningIn("regionModel::initialise()")
142  << "Region model has no mapped boundary conditions - transfer "
143  << "between regions will not be possible" << endl;
144  }
145 
146  if (!outputPropertiesPtr_.valid())
147  {
148  const fileName uniformPath(word("uniform")/"regionModels");
149 
150  outputPropertiesPtr_.reset
151  (
152  new IOdictionary
153  (
154  IOobject
155  (
156  regionName_ + "OutputProperties",
157  time_.timeName(),
158  uniformPath/regionName_,
159  primaryMesh_,
162  )
163  )
164  );
165  }
166 }
167 
168 
169 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
170 
172 {
173  if (regIOobject::read())
174  {
175  if (active_)
176  {
177  if (const dictionary* dictPtr = subDictPtr(modelName_ + "Coeffs"))
178  {
179  coeffs_ <<= *dictPtr;
180  }
181 
182  infoOutput_.readIfPresent("infoOutput", *this);
183  }
184 
185  return true;
186  }
187  else
188  {
189  return false;
190  }
191 }
192 
193 
195 {
196  if (active_)
197  {
198  if (const dictionary* dictPtr = dict.subDictPtr(modelName_ + "Coeffs"))
199  {
200  coeffs_ <<= *dictPtr;
201  }
202 
203  infoOutput_.readIfPresent("infoOutput", dict);
204 
205  return true;
206  }
207  else
208  {
209  return false;
210  }
211 }
212 
213 
216 (
217  const regionModel& nbrRegion,
218  const label regionPatchI,
219  const label nbrPatchI,
220  const bool flip
221 ) const
222 {
223  label nbrRegionID = findIndex(interRegionAMINames_, nbrRegion.name());
224 
225  const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
226 
227  if (nbrRegionID != -1)
228  {
229  if (!interRegionAMI_[nbrRegionID].set(regionPatchI))
230  {
231  const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];
232  const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI];
233 
234  int oldTag = UPstream::msgType();
235  UPstream::msgType() = oldTag + 1;
236 
237  interRegionAMI_[nbrRegionID].set
238  (
239  regionPatchI,
241  (
242  p,
243  nbrP,
245  true,
247  -1,
248  flip
249  )
250  );
251 
252  UPstream::msgType() = oldTag;
253  }
254 
255  return interRegionAMI_[nbrRegionID][regionPatchI];
256  }
257  else
258  {
259  label nbrRegionID = interRegionAMINames_.size();
260 
261  interRegionAMINames_.append(nbrRegion.name());
262 
263  const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];
264  const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI];
265 
266  label nPatch = regionMesh().boundaryMesh().size();
267 
268 
269  interRegionAMI_.resize(nbrRegionID + 1);
270 
271  interRegionAMI_.set
272  (
273  nbrRegionID,
275  );
276 
277  int oldTag = UPstream::msgType();
278  UPstream::msgType() = oldTag + 1;
279 
280  interRegionAMI_[nbrRegionID].set
281  (
282  regionPatchI,
284  (
285  p,
286  nbrP,
288  true,
290  -1,
291  flip
292  )
293  );
294 
295  UPstream::msgType() = oldTag;
296 
297  return interRegionAMI_[nbrRegionID][regionPatchI];
298  }
299 }
300 
301 
303 (
304  const regionModel& nbrRegion,
305  const label regionPatchI
306 ) const
307 {
308  label nbrPatchI = -1;
309 
310  // region
311  const fvMesh& nbrRegionMesh = nbrRegion.regionMesh();
312 
313  // boundary mesh
314  const polyBoundaryMesh& nbrPbm = nbrRegionMesh.boundaryMesh();
315 
316  const polyBoundaryMesh& pbm = regionMesh().boundaryMesh();
317 
318  if (regionPatchI > pbm.size() - 1)
319  {
321  (
322  "Foam::label Foam::regionModels::regionModel::nbrCoupledPatchID"
323  "("
324  "const regionModel&, "
325  "const label"
326  ") const"
327  )
328  << "region patch index out of bounds: "
329  << "region patch index = " << regionPatchI
330  << ", maximum index = " << pbm.size() - 1
331  << abort(FatalError);
332  }
333 
334  const polyPatch& pp = regionMesh().boundaryMesh()[regionPatchI];
335 
336  if (!isA<mappedPatchBase>(pp))
337  {
339  (
340  "Foam::label Foam::regionModels::regionModel::nbrCoupledPatchID"
341  "("
342  "const regionModel&, "
343  "const label"
344  ") const"
345  )
346  << "Expected a " << mappedPatchBase::typeName
347  << " patch, but found a " << pp.type() << abort(FatalError);
348  }
349 
350  const mappedPatchBase& mpb = refCast<const mappedPatchBase>(pp);
351 
352  // sample patch name on the primary region
353  const word& primaryPatchName = mpb.samplePatch();
354 
355  // find patch on nbr region that has the same sample patch name
356  forAll(nbrRegion.intCoupledPatchIDs(), j)
357  {
358  const label nbrRegionPatchI = nbrRegion.intCoupledPatchIDs()[j];
359 
360  const mappedPatchBase& mpb =
361  refCast<const mappedPatchBase>(nbrPbm[nbrRegionPatchI]);
362 
363  if (mpb.samplePatch() == primaryPatchName)
364  {
365  nbrPatchI = nbrRegionPatchI;
366  break;
367  }
368  }
369 
370  if (nbrPatchI == -1)
371  {
372  const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI];
373 
375  (
376  "Foam::label Foam::regionModels::regionModel::nbrCoupledPatchID"
377  "("
378  "const regionModel&, "
379  "const label"
380  ") const"
381  )
382  << "Unable to find patch pair for local patch "
383  << p.name() << " and region " << nbrRegion.name()
384  << abort(FatalError);
385  }
386 
387  return nbrPatchI;
388 }
389 
390 
391 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
392 
393 Foam::regionModels::regionModel::regionModel
394 (
395  const fvMesh& mesh,
396  const word& regionType
397 )
398 :
400  (
401  IOobject
402  (
403  regionType + "Properties",
404  mesh.time().constant(),
405  mesh.time(),
408  )
409  ),
410  primaryMesh_(mesh),
411  time_(mesh.time()),
412  active_(false),
413  infoOutput_(false),
414  modelName_("none"),
415  regionMeshPtr_(NULL),
416  coeffs_(dictionary::null),
417  outputPropertiesPtr_(NULL),
418  primaryPatchIDs_(),
419  intCoupledPatchIDs_(),
420  regionName_("none"),
421  functions_(*this),
422  interRegionAMINames_(),
423  interRegionAMI_()
424 {}
425 
426 
427 Foam::regionModels::regionModel::regionModel
428 (
429  const fvMesh& mesh,
430  const word& regionType,
431  const word& modelName,
432  bool readFields
433 )
434 :
436  (
437  IOobject
438  (
439  regionType + "Properties",
440  mesh.time().constant(),
441  mesh.time(),
444  )
445  ),
446  primaryMesh_(mesh),
447  time_(mesh.time()),
448  active_(lookup("active")),
449  infoOutput_(true),
450  modelName_(modelName),
451  regionMeshPtr_(NULL),
452  coeffs_(subOrEmptyDict(modelName + "Coeffs")),
453  outputPropertiesPtr_(NULL),
454  primaryPatchIDs_(),
455  intCoupledPatchIDs_(),
456  regionName_(lookup("regionName")),
457  functions_(*this, subOrEmptyDict("functions"))
458 {
459  if (active_)
460  {
461  constructMeshObjects();
462  initialise();
463 
464  if (readFields)
465  {
466  read();
467  }
468  }
469 }
470 
471 
472 Foam::regionModels::regionModel::regionModel
473 (
474  const fvMesh& mesh,
475  const word& regionType,
476  const word& modelName,
477  const dictionary& dict,
478  bool readFields
479 )
480 :
482  (
483  IOobject
484  (
485  regionType + "Properties",
486  mesh.time().constant(),
487  mesh.time(),
490  true
491  ),
492  dict
493  ),
494  primaryMesh_(mesh),
495  time_(mesh.time()),
496  active_(dict.lookup("active")),
497  infoOutput_(false),
498  modelName_(modelName),
499  regionMeshPtr_(NULL),
500  coeffs_(dict.subOrEmptyDict(modelName + "Coeffs")),
501  outputPropertiesPtr_(NULL),
502  primaryPatchIDs_(),
503  intCoupledPatchIDs_(),
504  regionName_(dict.lookup("regionName")),
505  functions_(*this, subOrEmptyDict("functions"))
506 {
507  if (active_)
508  {
509  constructMeshObjects(dict);
510  initialise();
511 
512  if (readFields)
513  {
514  read(dict);
515  }
516  }
517 }
518 
519 
520 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
521 
523 {}
524 
525 
526 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
527 
529 {
530  if (active_)
531  {
532  Info<< "\nEvolving " << modelName_ << " for region "
533  << regionMesh().name() << endl;
534 
535  //read();
536 
537  preEvolveRegion();
538 
539  evolveRegion();
540 
541  postEvolveRegion();
542 
543  // Provide some feedback
544  if (infoOutput_)
545  {
546  Info<< incrIndent;
547  info();
548  Info<< endl << decrIndent;
549  }
550 
551  if (time_.outputTime())
552  {
553  outputProperties().writeObject
554  (
557  time_.writeCompression()
558  );
559  }
560  }
561 }
562 
563 
565 {
566  functions_.preEvolveRegion();
567 }
568 
569 
571 {
572  // do nothing
573 }
574 
575 
577 {
578  functions_.postEvolveRegion();
579 }
580 
581 
583 {
584  // do nothing
585 }
586 
587 
588 // ************************************************************************* //
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const labelList & intCoupledPatchIDs() const
Return the list of patch IDs internally coupled with the.
Definition: regionModelI.H:193
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
const word & name() const
Return name.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
virtual void evolve()
Main driver routing to evolve the region - calls other evolves.
Definition: regionModel.C:528
const word & samplePatch() const
Patch (only if NEARESTPATCHFACE)
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:216
A class for handling words, derived from string.
Definition: word.H:59
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
label nbrCoupledPatchID(const regionModel &nbrRegion, const label regionPatchI) const
Return the coupled patch ID paired with coupled patch.
Definition: regionModel.C:303
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:61
defineTypeNameAndDebug(regionModel, 0)
messageStream Info
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:278
virtual void preEvolveRegion()
Pre-evolve region.
Definition: regionModel.C:564
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void postEvolveRegion()
Post-evolve region.
Definition: regionModel.C:576
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:623
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
const word & name() const
Name function is needed to disambiguate those inherited.
Definition: IOdictionary.C:183
Namespace for OpenFOAM.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
virtual void evolveRegion()
Evolve the region.
Definition: regionModel.C:570
static const dictionary null
Null dictionary.
Definition: dictionary.H:193
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
stressControl lookup("compactNormalStress") >> compactNormalStress
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Foam::polyBoundaryMesh.
volScalarField & p
Definition: createFields.H:51
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
#define forAll(list, i)
Definition: UList.H:421
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
virtual bool read()
Read object.
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:451
errorManip< error > abort(error &err)
Definition: errorManip.H:131
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:88
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
virtual void info()
Provide some feedback.
Definition: regionModel.C:582
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Determines a mapping between patch face centres and mesh cell or face centres and processors they&#39;re ...
virtual bool read()
Read control parameters from dictionary.
Definition: regionModel.C:171
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:675
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
virtual ~regionModel()
Destructor.
Definition: regionModel.C:522