regionModel.H
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) 2020 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 Class
28  Foam::regionModels::regionModel
29 
30 Description
31  Base class for region models
32 
33 SourceFiles
34  regionModelI.H
35  regionModel.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef regionModel_H
40 #define regionModel_H
41 
42 #include "IOdictionary.H"
43 #include "Switch.H"
44 #include "labelList.H"
45 #include "volFields.H"
46 #include "mappedPatchBase.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 namespace regionModels
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class regionModel Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class regionModel
62 :
63  public IOdictionary
64 {
65 private:
66 
67  // Private Member Functions
68 
69  //- No copy construct
70  regionModel(const regionModel&) = delete;
71 
72  //- No copy assignment
73  void operator=(const regionModel&) = delete;
74 
75  //- Construct region mesh and fields
76  void constructMeshObjects();
77 
78  //- Initialise the region
79  void initialise();
80 
81 
82 protected:
83 
84  // Protected data
85 
86  //- Reference to the primary mesh database
87  const fvMesh& primaryMesh_;
88 
89  //- Reference to the time database
90  const Time& time_;
91 
92  //- Active flag
94 
95  //- Active information output
97 
98  //- Model name
99  const word modelName_;
100 
101  //- Model coefficients dictionary
103 
104  //- Dictionary of output properties
106 
108  // Addressing
109 
110  //- List of patch IDs on the primary region coupled to this region
113  //- List of patch IDs internally coupled with the primary region
115 
116 
117  //- Region name
119 
120  //- Region model function objects
123 
124  // Inter-region AMI interpolation caching
125 
126  //- List of region names this region is coupled to
128 
129  //- List of AMI objects per coupled region
132 
133 
134  // Protected Member Functions
136  //- Read control parameters from dictionary
137  virtual bool read();
138 
139  //- Read control parameters from dictionary
140  virtual bool read(const dictionary& dict);
142  //- Create or return a new inter-region AMI object
144  (
145  const regionModel& nbrRegion,
146  const label regionPatchi,
147  const label nbrPatchi,
148  const bool flip
149  ) const;
150 
151 
152 public:
153 
154  //- Runtime type information
155  TypeName("regionModel");
156 
157 
158  // Constructors
159 
160  //- Construct null
161  regionModel(const fvMesh& mesh, const word& regionType);
162 
163  //- Construct from mesh, region type and name
165  (
166  const fvMesh& mesh,
167  const word& regionType,
168  const word& modelName,
169  bool readFields = true
170  );
171 
172  //- Construct from mesh and name and dict
174  (
175  const fvMesh& mesh,
176  const word& regionType,
177  const word& modelName,
178  const dictionary& dict,
179  bool readFields = true
180  );
181 
182 
183  //- Destructor
184  virtual ~regionModel() = default;
185 
186 
187  // Member Functions
188 
189  // Access
190 
191  //- Return the reference to the primary mesh database
192  const fvMesh& primaryMesh() const noexcept { return primaryMesh_; }
193 
194  //- Return the reference to the time database
195  const Time& time() const noexcept { return time_; }
196 
197  //- Return the active flag
198  Switch active() const noexcept { return active_; }
199 
200  //- Return the information flag
201  Switch infoOutput() const noexcept { return infoOutput_; }
202 
203  //- Return the model name
204  const word& modelName() const noexcept { return modelName_; }
205 
206  //- Return the region mesh database
207  inline const fvMesh& regionMesh() const;
208 
209  //- Return the region mesh database for manipulation
210  inline fvMesh& regionMesh();
211 
212  //- Return the model coefficients dictionary
213  const dictionary& coeffs() const noexcept { return coeffs_; }
214 
215  //- Return the solution dictionary
216  inline const dictionary& solution() const;
217 
218  //- Return const access to the output properties dictionary
219  inline const IOdictionary& outputProperties() const;
220 
221  //- Return output properties dictionary
222  inline IOdictionary& outputProperties();
223 
224 
225 
226  // Addressing
227 
228  //- List of patch IDs on the primary region coupled to this region
229  inline const labelList& primaryPatchIDs() const noexcept;
230 
231  //- List of patch IDs internally coupled with the primary region
232  inline const labelList& intCoupledPatchIDs() const noexcept;
233 
234  //- True if patchi on the local region is a coupled
235  //- patch to the primary region
236  inline bool isCoupledPatch(const label regionPatchi) const;
237 
238  //- True if patchi on the primary region is a coupled
239  //- patch to the local region
240  inline bool isRegionPatch(const label primaryPatchi) const;
241 
242  //- Return region ID corresponding to primaryPatch ID
243  inline label regionPatchID(const label primaryPatchi) const;
245 
246  // Helper Functions
247 
248  //- Return the coupled patch ID paired with coupled patch
249  // regionPatchi
250  label nbrCoupledPatchID
251  (
252  const regionModel& nbrRegion,
253  const label regionPatchi
254  ) const;
255 
256  //- Map patch field from another region model to local patch
257  template<class Type>
259  (
260  const regionModel& nbrRegion,
261  const label regionPatchi,
262  const label nbrPatchi,
263  const Field<Type>& nbrField,
264  const bool flip = false
265  ) const;
266 
267  //- Map patch field from another region model to local patch
268  template<class Type>
270  (
271  const regionModel& nbrRegion,
272  const word& fieldName,
273  const label regionPatchi,
274  const bool flip = false
275  ) const;
276 
277  //- Map patch internal field from another region model to local
278  // patch
279  template<class Type>
281  (
282  const regionModel& nbrRegion,
283  const word& fieldName,
284  const label regionPatchi,
285  const bool flip = false
286  ) const;
287 
288  //- Convert a local region field to the primary region
289  template<class Type>
290  void toPrimary
291  (
292  const label regionPatchi,
293  List<Type>& regionField
294  ) const;
295 
296  //- Convert a primary region field to the local region
297  template<class Type>
298  void toRegion
299  (
300  const label regionPatchi,
301  List<Type>& primaryFieldField
302  ) const;
303 
304  //- Convert a local region field to the primary region with op
305  template<class Type, class CombineOp>
306  void toPrimary
307  (
308  const label regionPatchi,
309  List<Type>& regionField,
310  const CombineOp& cop
311  ) const;
312 
313  //- Convert a primary region field to the local region with op
314  template<class Type, class CombineOp>
315  void toRegion
316  (
317  const label regionPatchi,
318  List<Type>& primaryFieldField,
319  const CombineOp& cop
320  ) const;
321 
322 
323  // Evolution
324 
325  //- Main driver routing to evolve the region - calls other evolves
326  virtual void evolve();
327 
328  //- Pre-evolve region
329  virtual void preEvolveRegion();
330 
331  //- Evolve the region
332  virtual void evolveRegion();
333 
334  //- Post-evolve region
335  virtual void postEvolveRegion();
336 
337 
338  // I-O
339 
340  //- Provide some feedback
341  virtual void info();
342 };
343 
344 
345 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346 
347 } // End namespace regionModels
348 } // End namespace Foam
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 #include "regionModelI.H"
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 #ifdef NoRepository
357  #include "regionModelTemplates.C"
358 #endif
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
362 #endif
363 
364 // ************************************************************************* //
dictionary dict
const fvMesh & primaryMesh_
Reference to the primary mesh database.
Definition: regionModel.H:92
const word modelName_
Model name.
Definition: regionModel.H:112
Switch infoOutput() const noexcept
Return the information flag.
Definition: regionModel.H:254
wordList interRegionAMINames_
List of region names this region is coupled to.
Definition: regionModel.H:154
virtual void evolveRegion()
Evolve the region.
Definition: regionModel.C:500
virtual void info()
Provide some feedback.
Definition: regionModel.C:510
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Definition: IOdictionary.C:30
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool isRegionPatch(const label primaryPatchi) const
True if patchi on the primary region is a coupled patch to the local region.
Definition: regionModelI.H:113
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
Definition: Switch.H:77
const labelList & primaryPatchIDs() const noexcept
List of patch IDs on the primary region coupled to this region.
Definition: regionModelI.H:90
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
label regionPatchID(const label primaryPatchi) const
Return region ID corresponding to primaryPatch ID.
Definition: regionModelI.H:122
TypeName("regionModel")
Runtime type information.
autoPtr< IOdictionary > outputPropertiesPtr_
Dictionary of output properties.
Definition: regionModel.H:122
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
const labelList & intCoupledPatchIDs() const noexcept
List of patch IDs internally coupled with the primary region.
Definition: regionModelI.H:97
const word & modelName() const noexcept
Return the model name.
Definition: regionModel.H:259
dictionary()
Default construct, a top-level empty dictionary.
Definition: dictionary.C:68
void toPrimary(const label regionPatchi, List< Type > &regionField) const
Convert a local region field to the primary region.
Switch active() const noexcept
Return the active flag.
Definition: regionModel.H:249
dynamicFvMesh & mesh
virtual void preEvolveRegion()
Pre-evolve region.
Definition: regionModel.C:494
Generic templated field type.
Definition: Field.H:62
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool read()
Read control parameters from dictionary.
Definition: regionModel.C:145
bool isCoupledPatch(const label regionPatchi) const
True if patchi on the local region is a coupled patch to the primary region.
Definition: regionModelI.H:104
label nbrCoupledPatchID(const regionModel &nbrRegion, const label regionPatchi) const
Return the coupled patch ID paired with coupled patch.
Definition: regionModel.C:266
virtual void postEvolveRegion()
Post-evolve region.
Definition: regionModel.C:504
const IOdictionary & outputProperties() const
Return const access to the output properties dictionary.
Definition: regionModelI.H:62
const dictionary & solution() const
Return the solution dictionary.
Definition: regionModelI.H:55
const dictionary & coeffs() const noexcept
Return the model coefficients dictionary.
Definition: regionModel.H:274
tmp< Field< Type > > mapRegionPatchInternalField(const regionModel &nbrRegion, const word &fieldName, const label regionPatchi, const bool flip=false) const
Map patch internal field from another region model to local.
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:26
Switch infoOutput_
Active information output.
Definition: regionModel.H:107
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:185
const direction noexcept
Definition: Scalar.H:258
Switch active_
Active flag.
Definition: regionModel.H:102
PtrList< PtrList< AMIPatchToPatchInterpolation > > interRegionAMI_
List of AMI objects per coupled region.
Definition: regionModel.H:160
dictionary coeffs_
Model coefficients dictionary.
Definition: regionModel.H:117
virtual ~regionModel()=default
Destructor.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
const Time & time_
Reference to the time database.
Definition: regionModel.H:97
regionModelFunctionObjectList functions_
Region model function objects.
Definition: regionModel.H:146
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual void evolve()
Main driver routing to evolve the region - calls other evolves.
Definition: regionModel.C:461
tmp< Foam::Field< Type > > mapRegionPatchField(const regionModel &nbrRegion, const label regionPatchi, const label nbrPatchi, const Field< Type > &nbrField, const bool flip=false) const
Map patch field from another region model to local patch.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
void toRegion(const label regionPatchi, List< Type > &primaryFieldField) const
Convert a primary region field to the local region.
Base class for region models.
Definition: regionModel.H:56
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const fvMesh & primaryMesh() const noexcept
Return the reference to the primary mesh database.
Definition: regionModel.H:239
List< label > labelList
A List of labels.
Definition: List.H:62
labelList intCoupledPatchIDs_
List of patch IDs internally coupled with the primary region.
Definition: regionModel.H:135
A class for managing temporary objects.
Definition: HashPtrTable.H:50
word regionName_
Region name.
Definition: regionModel.H:141
labelList primaryPatchIDs_
List of patch IDs on the primary region coupled to this region.
Definition: regionModel.H:130
const Time & time() const noexcept
Return the reference to the time database.
Definition: regionModel.H:244
Namespace for OpenFOAM.