PatchFunction1New.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) 2018-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "ConstantField.H"
29 
30 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
31 
32 template<class Type>
35 (
36  const polyPatch& pp,
37  const word& entryName,
38  const entry* eptr,
39  const dictionary& dict,
40  const bool faceValues,
41  const bool mandatory
42 )
43 {
44  word modelType;
45 
46  const dictionary* coeffs = (eptr ? eptr->dictPtr() : nullptr);
47 
48  if (coeffs)
49  {
50  // Dictionary entry
51 
52  coeffs->readEntry
53  (
54  "type",
55  modelType,
56  keyType::LITERAL
57  // "type" entry is mandatory, there is no 'redirect'
58  );
59  }
60  else if (eptr)
61  {
62  // Primitive entry
63  // - non-word : value for constant (uniform) function
64  // - word : the modelType, or uniform/nonuniform
65 
66  ITstream& is = eptr->stream();
67 
68  token firstToken(is);
69 
70  // Compatibility for reading straight fields
71  if (!firstToken.isWord())
72  {
73  // A value
74  is.putBack(firstToken);
75 
76  const Type constValue = pTraits<Type>(is);
77 
78  return autoPtr<PatchFunction1<Type>>
79  (
80  new PatchFunction1Types::ConstantField<Type>
81  (
82  pp,
83  entryName,
84  constValue,
85  dict,
86  faceValues
87  )
88  );
89  }
90 
91  modelType = firstToken.wordToken();
92 
93  // Looks like a normal field entry?
94  if (modelType == "uniform" || modelType == "nonuniform")
95  {
96  return autoPtr<PatchFunction1<Type>>
97  (
98  new PatchFunction1Types::ConstantField<Type>
99  (
100  pp,
101  eptr,
102  entryName,
103  dict,
104  faceValues
105  )
106  );
107  }
108 
109  // Fallthrough
110  }
111 
112 
113  if (modelType.empty())
114  {
115  // Entry missing
116 
117  if (mandatory)
118  {
120  << "Missing or invalid PatchFunction1 entry: "
121  << entryName << nl
122  << exit(FatalIOError);
123  }
124 
125  return nullptr;
126  }
127  else if (!coeffs)
128  {
129  // Primitive entry. Coeffs dictionary is optional.
130  // Use keyword() - not entryName - for compatibility lookup!
131 
132  const word& kw =
133  (
134  eptr
135  ? eptr->keyword() // Could be a compatibility lookup
136  : entryName
137  );
138 
139  coeffs = &dict.optionalSubDict(kw + "Coeffs", keyType::LITERAL);
140  }
141 
142 
143  auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
144 
145  if (!cstrIter.found())
146  {
148  << "Unknown PatchFunction1 type "
149  << modelType << " for " << entryName
150  << "\n\nValid PatchFunction1 types :\n"
151  << dictionaryConstructorTablePtr_->sortedToc() << nl
152  << exit(FatalIOError);
153  }
154 
155  return cstrIter()(pp, modelType, entryName, *coeffs, faceValues);
156 }
157 
158 
159 template<class Type>
162 (
163  const polyPatch& pp,
164  const word& entryName,
165  const dictionary& dict,
166  const bool faceValues,
167  const bool mandatory
168 )
169 {
171  (
172  pp,
173  entryName,
174  dict.findEntry(entryName, keyType::LITERAL),
175  dict,
176  faceValues,
177  mandatory
178  );
179 }
180 
181 
182 template<class Type>
185 (
186  const polyPatch& pp,
187  const word& entryName,
188  std::initializer_list<std::pair<const char*,int>> compat,
189  const dictionary& dict,
190  const bool faceValues,
191  const bool mandatory
192 )
193 {
195  (
196  pp,
197  entryName,
198  dict.findCompat(entryName, compat, keyType::LITERAL),
199  dict,
200  faceValues,
201  mandatory
202  );
203 }
204 
205 
206 template<class Type>
209 (
210  const polyPatch& pp,
211  const word& entryName,
212  const dictionary& dict,
213  const bool faceValues
214 )
215 {
216  // mandatory = false
217  return PatchFunction1<Type>::New(pp, entryName, dict, faceValues, false);
218 }
219 
220 
221 // ************************************************************************* //
ConstantField.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::FatalIOError
IOerror FatalIOError
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:59
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::PatchFunction1::NewCompat
static autoPtr< PatchFunction1< Type > > NewCompat(const polyPatch &pp, const word &entryName, std::initializer_list< std::pair< const char *, int >> compat, const dictionary &dict, const bool faceValues=true, const bool mandatory=true)
Compatibility selector.
Definition: PatchFunction1New.C:185
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::PatchFunction1::NewIfPresent
static autoPtr< PatchFunction1< Type > > NewIfPresent(const polyPatch &pp, const word &entryName, const dictionary &dict, const bool faceValues=true)
An optional selector.
Definition: PatchFunction1New.C:209