Loading...
Searching...
No Matches
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-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
32template<class Type>
34Foam::PatchFunction1<Type>::New
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
53 << "For " << entryName << " with dictionary entries: "
54 << flatOutput(coeffs->toc()) << nl;
55
56 // The "type" entry - mandatory, no fallback type provided
57 coeffs->readEntry
58 (
59 "type",
60 modelType,
61 keyType::LITERAL,
62 IOobjectOption::MUST_READ
63 );
64 }
65 else if (eptr)
66 {
67 // Primitive entry
68 // - word : the modelType, or uniform/nonuniform
69 // - non-word : value for constant (uniform) function
70
72 << "For " << entryName << " with primitive entry" << nl;
73
74 ITstream& is = eptr->stream();
75
76 if (is.peek().isWord())
77 {
78 modelType = is.peek().wordToken();
79 }
80 else
81 {
82 // A value - compatibility for reading uniform (constant) field
83
84 const Type constValue = pTraits<Type>(is);
85
86 return autoPtr<PatchFunction1<Type>>
87 (
88 new PatchFunction1Types::ConstantField<Type>
89 (
90 pp,
91 entryName,
92 constValue,
93 dict,
94 faceValues
95 )
96 );
97 }
98
99 // Looks like a normal field entry?
100 if (modelType == "uniform" || modelType == "nonuniform")
101 {
102 return autoPtr<PatchFunction1<Type>>
103 (
104 new PatchFunction1Types::ConstantField<Type>
105 (
106 pp,
107 eptr,
108 entryName,
109 dict,
110 faceValues
111 )
112 );
113 }
114
115 // Fallthrough
116 }
117
118
119 if (modelType.empty())
120 {
121 // Entry missing
122
123 if (mandatory)
124 {
126 << "Missing or invalid PatchFunction1 entry: "
127 << entryName << nl
128 << exit(FatalIOError);
129 }
130
131 return nullptr;
132 }
133 else if (!coeffs)
134 {
135 // Primitive entry. Coeffs dictionary is optional.
136 // Use keyword() - not entryName - for compatibility lookup!
137
138 const word& kw =
139 (
140 eptr
141 ? eptr->keyword() // Could be a compatibility lookup
142 : entryName
143 );
144
145 coeffs = &dict.optionalSubDict(kw + "Coeffs", keyType::LITERAL);
146 }
147
148
149 auto* ctorPtr = dictionaryConstructorTable(modelType);
150
151 if (!ctorPtr)
152 {
154 << "Unknown PatchFunction1 type "
155 << modelType << " for " << entryName
156 << "\n\nValid PatchFunction1 types :\n"
157 << dictionaryConstructorTablePtr_->sortedToc() << nl
158 << exit(FatalIOError);
159 }
161 return ctorPtr(pp, modelType, entryName, *coeffs, faceValues);
162}
163
164
165template<class Type>
167Foam::PatchFunction1<Type>::New
168(
169 const polyPatch& pp,
170 const word& entryName,
171 const dictionary& dict,
172 const bool faceValues,
173 const bool mandatory
174)
175{
176 return PatchFunction1<Type>::New
177 (
178 pp,
179 entryName,
180 dict.findEntry(entryName, keyType::LITERAL),
181 dict,
182 faceValues,
183 mandatory
184 );
185}
186
187
188template<class Type>
191(
192 const polyPatch& pp,
193 const word& entryName,
194 std::initializer_list<std::pair<const char*,int>> compat,
195 const dictionary& dict,
196 const bool faceValues,
197 const bool mandatory
198)
199{
200 return PatchFunction1<Type>::New
201 (
202 pp,
203 entryName,
204 dict.findCompat(entryName, compat, keyType::LITERAL),
205 dict,
206 faceValues,
207 mandatory
208 );
209}
210
211
212template<class Type>
215(
216 const polyPatch& pp,
217 const word& entryName,
218 const dictionary& dict,
219 const bool faceValues
220)
221{
222 // mandatory = false
223 return PatchFunction1<Type>::New(pp, entryName, dict, faceValues, false);
225
226
227template<class Type>
229Foam::PatchFunction1<Type>::New
230(
232
233 const polyPatch& pp,
234 const word& entryName,
235 const dictionary& dict,
236 enum keyType::option matchOpt,
237 const bool faceValues,
238 const bool mandatory
239)
240{
241 // See corresponding comments in Function1::New (caching version)
242
243 refPtr<PatchFunction1<Type>> fref; // return value
244
245 // Try for direct cache hit
246 fref.cref(cache.get(entryName));
247
248 if (fref)
249 {
250 return fref;
251 }
252
253
254 // Lookup from dictionary
255 const entry* eptr = dict.findEntry(entryName, matchOpt);
256
257 if (eptr)
258 {
259 // Use keyword (potentially a wildcard) instead of entry name
260 const auto& kw = eptr->keyword();
261
262 // Try for a cache hit
263 fref.cref(cache.get(kw));
264
265 if (!fref)
266 {
267 // Create new entry
268 auto fauto
269 (
270 PatchFunction1<Type>::New
271 (
272 pp,
273 kw,
274 eptr, // Already resolved
275 dict,
277 mandatory
278 )
279 );
280
281 if (fauto)
282 {
283 // Cache the newly created function
284 fref.cref(fauto.get());
285 cache.set(kw, fauto);
286 }
287 }
288 }
289
290 if (mandatory && !fref)
291 {
293 << "No match for " << entryName << nl
294 << exit(FatalIOError);
295 }
296
297 return fref;
298}
299
300
301// ************************************************************************* //
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const polyPatch const word const word & entryName
const polyPatch const word const word const dictionary & dict
const polyPatch & pp
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.
static autoPtr< PatchFunction1< Type > > NewIfPresent(const polyPatch &pp, const word &entryName, const dictionary &dict, const bool faceValues=true)
An optional selector.
const polyPatch const word const word const dictionary const bool faceValues
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
const keyType & keyword() const noexcept
Return keyword.
Definition entry.H:231
option
Enumeration for the data type and search/match modes (bitmask).
Definition keyType.H:80
@ LITERAL
String literal.
Definition keyType.H:82
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
Definition refPtrI.H:216
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define DebugInFunction
Report an information message using Foam::Info.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict