cellModeller.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 Description
25  Constructor of cellModeller: just sets the cellModeller's params.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cellModeller.H"
30 #include "IFstream.H"
31 #include "etcFiles.H"
32 
33 // * * * * * * * * * * * * * * * Static data * * * * * * * * * * * * * * * * //
34 
35 Foam::PtrList<Foam::cellModel> Foam::cellModeller::models_;
36 
37 Foam::List<Foam::cellModel*> Foam::cellModeller::modelPtrs_;
38 
39 Foam::HashTable<const Foam::cellModel*> Foam::cellModeller::modelDictionary_;
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 {
46  if (modelPtrs_.size())
47  {
49  << "attempt to re-construct cellModeller when it already exists :"
50  << modelPtrs_.size()
51  << exit(FatalError);
52  }
53 
54  label maxIndex = 0;
55  forAll(models_, i)
56  {
57  if (models_[i].index() > maxIndex) maxIndex = models_[i].index();
58  }
59 
60  modelPtrs_.setSize(maxIndex + 1);
61  modelPtrs_ = nullptr;
62 
63  // For all the words in the wordlist, set the details of the model
64  // to those specified by the word name and the other parameters
65  // given. This should result in an automatic 'read' of the model
66  // from its File (see cellModel class).
67  forAll(models_, i)
68  {
69  if (modelPtrs_[models_[i].index()])
70  {
72  << "more than one model share the index "
73  << models_[i].index()
74  << exit(FatalError);
75  }
76 
77  modelPtrs_[models_[i].index()] = &models_[i];
78 
79  if (modelDictionary_.found(models_[i].name()))
80  {
82  << "more than one model share the name "
83  << models_[i].name()
84  << exit(FatalError);
85  }
86 
87  modelDictionary_.insert(models_[i].name(), &models_[i]);
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
93 
95 {}
96 
97 
98 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
99 
101 {
102  if (models_.empty())
103  {
104  IFstream is(findEtcFile("cellModels", true));
105  is >> models_;
106  cellModeller m;
107  }
108 
109  HashTable<const cellModel*>::iterator iter = modelDictionary_.find(name);
110 
111  if (iter != modelDictionary_.end())
112  {
113  return iter();
114  }
115  else
116  {
117  return nullptr;
118  }
119 }
120 
121 
123 {
124  if (models_.empty())
125  {
126  IFstream is(findEtcFile("cellModels", true));
127  is >> models_;
128  cellModeller m;
129  }
130 
131  return modelPtrs_[i];
132 }
133 
134 
135 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
Definition: cellModeller.C:100
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A static collection of cell models, and a means of looking them up.
Definition: cellModeller.H:52
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
~cellModeller()
Destructor.
Definition: cellModeller.C:94
An STL-conforming iterator.
Definition: HashTable.H:426
A class for handling words, derived from string.
Definition: word.H:59
Functions to search &#39;etc&#39; directories for configuration files etc.
An STL-conforming hash table.
Definition: HashTable.H:61
fileName findEtcFile(const fileName &, bool mandatory=false)
Search for a file using findEtcFiles.
Definition: etcFiles.C:252
cellModeller()
Construct from central "cellModels" file.
Definition: cellModeller.C:44
Input from file stream.
Definition: IFstream.H:81
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64