solverTemplate.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) 2015 OpenFOAM Foundation
9  Copyright (C) 2015-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 "solverTemplate.H"
30 #include "Time.H"
31 #include "IOPtrList.H"
32 #include "polyMesh.H"
33 #include "regionProperties.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 const Foam::Enum
38 <
40 >
42 ({
43  { solverType::stCompressible, "compressible" },
44  { solverType::stIncompressible, "incompressible" },
45  { solverType::stBuoyant, "buoyant" },
46  { solverType::stUnknown, "unknown" },
47 });
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 Foam::word Foam::solverTemplate::readFromDict
53 (
54  IOobject& dictHeader,
55  const word& entryName
56 ) const
57 {
58  if (!dictHeader.typeHeaderOk<IOdictionary>(true))
59  {
61  << "Unable to open file "
62  << dictHeader.objectPath()
63  << exit(FatalError);
64  }
65 
66  IOdictionary dict(dictHeader);
67  return dict.get<word>(entryName);
68 }
69 
70 
71 Foam::dictionary Foam::solverTemplate::readFluidFieldTemplates
72 (
73  const word& regionName,
74  const fileName& baseDir,
75  const dictionary& solverDict,
76  const Time& runTime
77 ) const
78 {
79  Info<< " Reading fluid field templates";
80 
81  if (regionName == word::null)
82  {
83  Info<< endl;
84  }
85  else
86  {
87  Info<< " for region " << regionName << endl;
88  }
89 
90  dictionary fieldTemplates = solverDict.subDict("fluidFields");
91 
92  const fileName turbModelDir(baseDir/"models"/"turbulence");
93 
94  const dictionary fieldModels(solverDict.subDict("fluidModels"));
95 
96  word turbulenceModel("laminar"); // default to laminar
97  word turbulenceType("none");
98 
99  if (fieldModels.readIfPresent("turbulenceModel", turbulenceType))
100  {
101  if (turbulenceType == "turbulenceModel")
102  {
103  IOdictionary turbPropDict
104  (
105  IOobject
106  (
107  "turbulenceProperties",
108  runTime.constant(),
109  regionName,
110  runTime,
113  false
114  )
115  );
116 
117  const word modelType(turbPropDict.get<word>("simulationType"));
118 
119  if (modelType == "laminar")
120  {
121  // Leave turbulenceModel as laminar
122  }
123  else if (modelType == "RAS")
124  {
125  turbPropDict.subDict(modelType)
126  .readEntry("RASModel", turbulenceModel);
127  }
128  else if (modelType == "LES")
129  {
130  turbPropDict.subDict(modelType)
131  .readEntry("LESModel", turbulenceModel);
132  }
133  else
134  {
136  << "Unhandled turbulence model option " << modelType
137  << ". Valid options are laminar, RAS, LES"
138  << exit(FatalError);
139  }
140  }
141  else
142  {
144  << "Unhandled turbulence model option " << turbulenceType
145  << ". Valid options are turbulenceModel"
146  << exit(FatalError);
147  }
148  }
149 
150  Info<< " Selecting " << turbulenceType << ": " << turbulenceModel
151  << endl;
152 
153  IOdictionary turbModelDict
154  (
155  IOobject
156  (
157  fileName(turbModelDir/turbulenceModel),
158  runTime,
160  )
161  );
162 
163  // Merge common fluid fields
164  fieldTemplates.merge(turbModelDict.subDict("fluidFields"));
165 
166  // Merge specific compressible or incompressible fluid fields
167  switch (solverType_)
168  {
169  case stIncompressible:
170  {
171  fieldTemplates.merge(turbModelDict.subDict("incompressibleFields"));
172  break;
173  }
174  case stCompressible:
175  case stBuoyant:
176  {
177  fieldTemplates.merge(turbModelDict.subDict("compressibleFields"));
178  break;
179  }
180  default:
181  {
182  // do nothing
183  }
184  }
185 
186  return fieldTemplates;
187 }
188 
189 
190 Foam::dictionary Foam::solverTemplate::readSolidFieldTemplates
191 (
192  const word& regionName,
193  const dictionary& solverDict
194 ) const
195 {
196  Info<< " Reading solid field templates for region " << regionName
197  << endl;
198 
199  // nothing more to do for solids
200  return solverDict.subDict("solidFields");
201 }
202 
203 
204 void Foam::solverTemplate::setRegionProperties
205 (
206  const dictionary& fieldDict,
207  const word& regionType,
208  const word& regionName,
209  const label regionI
210 )
211 {
212  regionTypes_[regionI] = regionType,
213  regionNames_[regionI] = regionName,
214  fieldNames_[regionI] = fieldDict.toc();
215  fieldTypes_[regionI].setSize(fieldNames_[regionI].size());
216  fieldDimensions_[regionI].setSize(fieldNames_[regionI].size());
217 
218  forAll(fieldNames_[regionI], i)
219  {
220  const word& fieldName = fieldNames_[regionI][i];
221  const dictionary& dict = fieldDict.subDict(fieldName);
222 
223  dict.readEntry("type", fieldTypes_[regionI][i]);
224  fieldDimensions_[regionI].set
225  (
226  i,
227  new dimensionSet(dict, "dimensions")
228  );
229  }
230 }
231 
232 
233 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
234 
236 (
237  const fileName& baseDir,
238  const Time& runTime,
239  const word& solverName
240 )
241 :
242  solverType_(stUnknown),
243  multiRegion_(false),
244  regionTypes_(),
245  fieldNames_(),
246  fieldTypes_(),
247  fieldDimensions_()
248 {
249  IOdictionary solverDict
250  (
251  IOobject
252  (
253  fileName(baseDir/"solvers"/solverName),
254  runTime,
256  )
257  );
258 
259  Info<< "Selecting " << solverName << ": ";
260 
261  solverType_ = solverTypeNames_.get("solverType", solverDict);
262  multiRegion_ = solverDict.get<bool>("multiRegion");
263 
264  Info<< solverTypeNames_[solverType_];
265  if (multiRegion_)
266  {
267  Info<< ", multi-region";
268  }
269  else
270  {
271  Info<< ", single-region";
272  }
273 
274  Info<< " case" << endl;
275 
276  if (multiRegion_)
277  {
278  // read regionProperties
279  regionProperties rp(runTime);
280 
281  const wordList fluidNames(rp["fluid"]);
282  const wordList solidNames(rp["solid"]);
283 
284  const label nRegion = fluidNames.size() + solidNames.size();
285 
286  regionTypes_.setSize(nRegion);
287  regionNames_.setSize(nRegion);
288  fieldNames_.setSize(nRegion);
289  fieldTypes_.setSize(nRegion);
290  fieldDimensions_.setSize(nRegion);
291 
292  // read templates for solver lists of available
293  // - fields and dimensions required for the solver
294  // - models
295  label regionI = 0;
296  forAll(fluidNames, i)
297  {
298  const dictionary fieldDict
299  (
300  readFluidFieldTemplates
301  (
302  fluidNames[i],
303  baseDir,
304  solverDict,
305  runTime
306  )
307  );
308 
309  setRegionProperties(fieldDict, "fluid", fluidNames[i], regionI++);
310  }
311 
312  forAll(solidNames, i)
313  {
314  const dictionary fieldDict
315  (
316  readSolidFieldTemplates
317  (
318  solidNames[i],
319  solverDict
320  )
321  );
322  setRegionProperties(fieldDict, "solid", solidNames[i], regionI++);
323  }
324  }
325  else
326  {
327  regionTypes_.setSize(1);
328  regionNames_.setSize(1);
329  fieldNames_.setSize(1);
330  fieldTypes_.setSize(1);
331  fieldDimensions_.setSize(1);
332 
333  // read templates for solver lists of available
334  // - fields and dimensions required for the solver
335  // - models
336  const dictionary fieldDict
337  (
338  readFluidFieldTemplates
339  (
340  word::null, // use region = null for single-region cases
341  baseDir,
342  solverDict,
343  runTime
344  )
345  );
346 
347  setRegionProperties(fieldDict, "fluid", word::null, 0);
348  }
349 }
350 
351 
352 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
353 
355 {
356  return solverTypeNames_[solverType_];
357 }
358 
359 
361 {
362  return multiRegion_;
363 }
364 
365 
366 Foam::label Foam::solverTemplate::nRegion() const
367 {
368  return regionTypes_.size();
369 }
370 
371 
372 const Foam::word& Foam::solverTemplate::regionType(const label regionI) const
373 {
374  return regionTypes_[regionI];
375 }
376 
377 
378 const Foam::word& Foam::solverTemplate::regionName(const label regionI) const
379 {
380  return regionNames_[regionI];
381 }
382 
383 
385 (
386  const label regionI
387 ) const
388 {
389  return fieldNames_[regionI];
390 }
391 
392 
394 (
395  const label regionI
396 ) const
397 {
398  return fieldTypes_[regionI];
399 }
400 
401 
403 (
404  const label regionI
405 ) const
406 {
407  return fieldDimensions_[regionI];
408 }
409 
410 
411 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
regionProperties.H
solverTemplate.H
Foam::solverTemplate::fieldNames
const wordList & fieldNames(const label regionI) const
Return the field names.
Foam::solverTemplate::solverType
solverType
Solver type.
Definition: solverTemplate.H:60
Foam::solverTemplate::solverTypeNames_
static const Enum< solverType > solverTypeNames_
Solver type names.
Definition: solverTemplate.H:69
Foam::solverTemplate::fieldDimensions
const PtrList< dimensionSet > & fieldDimensions(const label regionI) const
Return the field dimensions.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
polyMesh.H
Foam::solverTemplate::regionName
const word & regionName(const label regionI) const
Return the region name.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::compressible::turbulenceModel
ThermalDiffusivity< CompressibleTurbulenceModel< fluidThermo > > turbulenceModel
Definition: turbulentFluidThermoModel.H:63
IOPtrList.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:528
Foam::solverTemplate::solverTemplate
solverTemplate(const fileName &baseDir, const Time &runTime, const word &regionName)
Constructor.
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
dict
dictionary dict
Definition: searchingEngine.H:14
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
Foam::solverTemplate::fieldTypes
const wordList & fieldTypes(const label regionI) const
Return the field types.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::solverTemplate::nRegion
label nRegion() const
Return the number of regions.
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::solverTemplate::type
word type() const
Solver type name.
rp
regionProperties rp(runTime)
Foam::solverTemplate::multiRegion
bool multiRegion() const
Return the multi-region flag.
Foam::solverTemplate::regionType
const word & regionType(const label regionI) const
Return the region type.
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
solidNames
const wordList solidNames(rp["solid"])
fluidNames
const wordList fluidNames(rp["fluid"])
Foam::IOobject::MUST_READ
Definition: IOobject.H:120