Loading...
Searching...
No Matches
codedMixedFvPatchField.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
31#include "fvPatchFieldMapper.H"
32#include "volFields.H"
33#include "dynamicCode.H"
34#include "dictionaryContent.H"
35
36// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37
38template<class Type>
40{
41 return this->db().time().libs();
42}
43
44
45template<class Type>
47{
48 return
49 "patch "
50 + this->patch().name()
51 + " on field "
52 + this->internalField().name();
53}
54
55
56template<class Type>
59 redirectPatchFieldPtr_.reset(nullptr);
60}
61
62
63template<class Type>
66{
67 const dictionary* ptr = dict_.findDict("codeContext", keyType::LITERAL);
68 return (ptr ? *ptr : dictionary::null);
69}
70
71
72template<class Type>
75{
76 // Inline "code" or from system/codeDict
77 return
78 (
79 dict_.found("code")
80 ? dict_
81 : codedBase::codeDict(this->db()).subDict(name_)
82 );
83}
84
85
86template<class Type>
88(
89 dynamicCode& dynCode,
90 const dynamicCodeContext& context
91) const
92{
93 // Take no chances - typeName must be identical to name_
94 dynCode.setFilterVariable("typeName", name_);
95
96 // Set TemplateType and FieldType filter variables
97 dynCode.setFieldTemplates<Type>();
98
99 // Compile filtered C template
100 dynCode.addCompileFile(codeTemplateC);
101
102 // Copy filtered H template
103 dynCode.addCopyFile(codeTemplateH);
104
105 #ifdef FULLDEBUG
106 dynCode.setFilterVariable("verbose", "true");
108 <<"compile " << name_ << " sha1: " << context.sha1() << endl;
109 #endif
110
111 // Define Make/options
112 dynCode.setMakeOptions
113 (
114 "EXE_INC = -g \\\n"
115 "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
116 "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
117 + context.options()
118 + "\n\nLIB_LIBS = \\\n"
119 " -lOpenFOAM \\\n"
120 " -lfiniteVolume \\\n"
121 " -lmeshTools \\\n"
122 + context.libs()
123 );
124}
125
126
127// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128
129template<class Type>
131(
132 const fvPatch& p,
134)
135:
136 parent_bctype(p, iF),
137 codedBase(),
138 redirectPatchFieldPtr_(nullptr)
139{}
140
141
142template<class Type>
144(
146 const fvPatch& p,
148 const fvPatchFieldMapper& mapper
149)
150:
151 parent_bctype(rhs, p, iF, mapper),
152 codedBase(),
153 dict_(rhs.dict_), // Deep copy
154 name_(rhs.name_),
155 redirectPatchFieldPtr_(nullptr)
156{}
157
158
159template<class Type>
161(
162 const fvPatch& p,
164 const dictionary& dict
165)
166:
167 parent_bctype(p, iF, dict),
168 codedBase(),
169 dict_
170 (
171 // Copy dictionary, but without "heavy" data chunks
172 dictionaryContent::copyDict
173 (
174 dict,
175 wordList(), // allow
176 wordList // deny
177 ({
178 "type", // redundant
179 "value", "refValue", "refGradient", "valueFraction"
180 })
181 )
182 ),
183 name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
184 redirectPatchFieldPtr_(nullptr)
185{
186 updateLibrary(name_);
187}
188
189
190template<class Type>
192(
194)
195:
196 parent_bctype(rhs),
197 codedBase(),
198 dict_(rhs.dict_), // Deep copy
199 name_(rhs.name_),
200 redirectPatchFieldPtr_(nullptr)
201{}
202
203
204template<class Type>
206(
209)
210:
211 parent_bctype(rhs, iF),
212 codedBase(),
213 dict_(rhs.dict_), // Deep copy
214 name_(rhs.name_),
215 redirectPatchFieldPtr_(nullptr)
217
218
219// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
220
221template<class Type>
224{
225 if (!redirectPatchFieldPtr_)
226 {
227 // Construct a patch
228 // Make sure to construct the patchfield with up-to-date value
229
230 // Write the data from the mixed b.c.
232 this->parent_bctype::write(os);
233 ISpanStream is(os.view());
234 dictionary constructDict(is);
235
236 // Override type
237 constructDict.set("type", name_);
238
239 redirectPatchFieldPtr_.reset
240 (
241 dynamic_cast<parent_bctype*>
242 (
244 (
245 this->patch(),
246 this->internalField(),
247 constructDict
248 ).ptr()
249 )
250 );
251
252 // Forward copy of dictionary content to the code template
253 auto* contentPtr =
254 dynamic_cast<dictionaryContent*>(redirectPatchFieldPtr_.get());
255
256 if (contentPtr)
257 {
258 contentPtr->dict(this->codeContext());
259 }
260 else
261 {
263 << name_ << " Did not derive from dictionaryContent"
264 << nl << nl;
266 }
267 return *redirectPatchFieldPtr_;
268}
269
270
271template<class Type>
273{
274 if (this->updated())
275 {
276 return;
277 }
278
279 // Make sure library containing user-defined fvPatchField is up-to-date
280 updateLibrary(name_);
281
282 const parent_bctype& fvp = redirectPatchField();
283 const_cast<parent_bctype&>(fvp).updateCoeffs();
284
285 // Copy through coefficients
286 this->refValue() = fvp.refValue();
287 this->refGrad() = fvp.refGrad();
288 this->valueFraction() = fvp.valueFraction();
289
291}
292
293
294template<class Type>
296(
297 const Pstream::commsTypes commsType
298)
299{
300 // Make sure library containing user-defined fvPatchField is up-to-date
301 updateLibrary(name_);
302
303 const parent_bctype& fvp = redirectPatchField();
304
305 // - updates the value of fvp (though not used)
306 // - resets the updated() flag
307 const_cast<parent_bctype&>(fvp).evaluate(commsType);
309 // Update the value (using the coefficients) locally
310 parent_bctype::evaluate(commsType);
311}
312
313
314template<class Type>
316{
317 this->parent_bctype::write(os);
318 os.writeEntry("name", name_);
319
321}
322
323
324// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
An OSstream with internal List storage.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
commsTypes
Communications types.
Definition UPstream.H:81
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition codedBase.H:63
void updateLibrary(const word &name, const dynamicCodeContext &context) const
Update library as required, using the given context.
Definition codedBase.C:283
codedBase(const codedBase &)=delete
No copy construct.
static void writeCodeDict(Ostream &os, const dictionary &dict)
Write code-dictionary contents.
Definition codedBase.C:81
static const dictionary & codeDict(const objectRegistry &obr, const word &dictName="codeDict")
Return "codeDict" from objectRegistry or read from disk.
Definition codedBase.C:94
Constructs on-the-fly a new boundary condition (derived from mixedFvPatchField) which is then used to...
virtual const dictionary & codeContext() const
Additional 'codeContext' dictionary to pass through.
virtual void write(Ostream &) const
Write.
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
virtual const dictionary & codeDict() const
The code dictionary. Inline "code" or from system/codeDict.
const mixedFvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patchField.
virtual void clearRedirect() const
Clear redirected object(s).
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
codedMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field.
virtual string description() const
Description (type + name) for the output.
A wrapper for dictionary content, without operators that could affect inheritance patterns.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition dictionary.C:765
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition dictionary.H:487
A table of dynamically loaded libraries.
Encapsulation of dynamic code dictionaries.
const string & libs() const noexcept
The code libs (LIB_LIBS).
const SHA1 & sha1() const noexcept
The SHA1 calculated from options, libs, include, code, etc.
const string & options() const noexcept
The code options (Make/options).
Tools for handling dynamic code compilation.
Definition dynamicCode.H:57
void addCopyFile(const fileName &name)
Add a file template name, which will be found and filtered.
void setFieldTemplates()
Define a filter variables TemplateType and FieldType.
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
void addCompileFile(const fileName &name)
Add a file template name, which will be found and filtered.
void setMakeOptions(const std::string &content)
Define contents for Make/options.
const objectRegistry & db() const
The associated objectRegistry.
const fvPatch & patch() const noexcept
Return the patch.
bool updated() const noexcept
True if the boundary condition has already been updated.
A FieldMapper for finite-volume patch fields.
static tmp< fvPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, volMesh > &)
Return a pointer to a new patchField created on freestore given.
const DimensionedField< Type, volMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
@ LITERAL
String literal.
Definition keyType.H:82
This boundary condition provides a base class for 'mixed' type boundary conditions,...
virtual void write(Ostream &) const
Write.
virtual Field< Type > & refGrad()
virtual Field< Type > & refValue()
virtual scalarField & valueFraction()
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field.
A class for handling character strings derived from std::string.
Definition string.H:76
A class for handling words, derived from Foam::string.
Definition word.H:66
volScalarField & p
#define DetailInfo
Definition evalEntry.C:30
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
List< word > wordList
List of word.
Definition fileName.H:60
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict