codedFixedValueFvPatchField.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-2024 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 \*---------------------------------------------------------------------------*/
25 
28 #include "fieldMapper.H"
29 #include "volFields.H"
30 #include "dynamicCode.H"
31 #include "dynamicCodeContext.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class Type>
37 {
38  return {"code", "codeInclude", "localCode"};
39 }
40 
41 
42 template<class Type>
44 {
45  return {word::null, word::null, word::null};
46 }
47 
48 
49 template<class Type>
51 (
52  dynamicCode& dynCode,
53  const dynamicCodeContext& context
54 ) const
55 {
56  dynCode.setFilterVariable("typeName", codeName());
57 
58  // Set TemplateType and FieldType filter variables
59  // (for fvPatchField)
60  word fieldType(pTraits<Type>::typeName);
61 
62  // Template type for fvPatchField
63  dynCode.setFilterVariable("TemplateType", fieldType);
64 
65  // Name for fvPatchField - eg, ScalarField, VectorField, ...
66  fieldType[0] = toupper(fieldType[0]);
67  dynCode.setFilterVariable("FieldType", fieldType + "Field");
68 
69  // Compile filtered C template
70  dynCode.addCompileFile(codeTemplateC("codedFixedValueFvPatchField"));
71 
72  // Copy filtered H template
73  dynCode.addCopyFile(codeTemplateH("codedFixedValueFvPatchField"));
74 
75  // Make verbose if debugging
76  dynCode.setFilterVariable("verbose", Foam::name(bool(debug)));
77 
78  if (debug)
79  {
80  Info<<"compile " << codeName() << " sha1: " << context.sha1() << endl;
81  }
82 
83  // Define Make/options
84  dynCode.setMakeOptions
85  (
86  "EXE_INC = -g \\\n"
87  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
88  + context.options()
89  + "\n\nLIB_LIBS = \\\n"
90  + " -lOpenFOAM \\\n"
91  + " -lfiniteVolume \\\n"
92  + context.libs()
93  );
94 }
95 
96 
97 template<class Type>
99 {
100  // Remove instantiation of fvPatchField provided by library
101  redirectPatchFieldPtr_.clear();
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
107 template<class Type>
109 (
110  const fvPatch& p,
112  const dictionary& dict
113 )
114 :
115  fixedValueFvPatchField<Type>(p, iF, dict),
116  codedBase(dict),
117  redirectPatchFieldPtr_()
118 {
119  updateLibrary();
120 }
121 
122 
123 template<class Type>
125 (
127  const fvPatch& p,
129  const fieldMapper& mapper
130 )
131 :
132  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
133  codedBase(ptf),
134  redirectPatchFieldPtr_()
135 {}
136 
137 
138 template<class Type>
140 (
143 )
144 :
145  fixedValueFvPatchField<Type>(ptf, iF),
146  codedBase(ptf),
147  redirectPatchFieldPtr_()
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
153 template<class Type>
156 {
157  if (!redirectPatchFieldPtr_.valid())
158  {
159  OStringStream os;
160  writeEntry(os, "type", codeName());
161 
162  if (this->overridesConstraint())
163  {
164  writeEntry(os, "patchType", this->patch().type());
165  }
166 
167  writeEntry(os, "value", *this);
168 
169  IStringStream is(os.str());
170  dictionary dict(is);
171 
172  redirectPatchFieldPtr_.set
173  (
175  (
176  this->patch(),
177  this->internalField(),
178  dict
179  ).ptr()
180  );
181  }
182 
183  return redirectPatchFieldPtr_();
184 }
185 
186 
187 template<class Type>
189 {
190  if (this->updated())
191  {
192  return;
193  }
194 
195  // Make sure library containing user-defined fvPatchField is up-to-date
196  updateLibrary();
197 
198  const fvPatchField<Type>& fvp = redirectPatchField();
199 
200  const_cast<fvPatchField<Type>&>(fvp).updateCoeffs();
201 
202  // Copy through value
203  this->operator==(fvp);
204 
206 }
207 
208 
209 template<class Type>
211 (
212  const Pstream::commsTypes commsType
213 )
214 {
215  // Make sure library containing user-defined fvPatchField is up-to-date
216  updateLibrary();
217 
218  const fvPatchField<Type>& fvp = redirectPatchField();
219 
220  const_cast<fvPatchField<Type>&>(fvp).evaluate(commsType);
221 
223 }
224 
225 
226 template<class Type>
228 {
230  writeCode(os);
231 }
232 
233 
234 // ************************************************************************* //
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...
Input from memory buffer stream.
Definition: IStringStream.H:52
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
commsTypes
Types of communications.
Definition: UPstream.H:65
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:54
void updateLibrary() const
Update library as required.
Definition: codedBase.C:314
Constructs on-the-fly a new boundary condition (derived from fixedValueFvPatchField) which is then us...
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
virtual void write(Ostream &) const
Write.
codedFixedValueFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
const fvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patch.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
virtual void write(Ostream &) const
Write.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:209
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:202
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
volScalarField & p