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-2023 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 "fvPatchFieldMapper.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
39  {
40  "code",
41  "codeInclude",
42  "localCode"
43  };
44 }
45 
46 
47 template<class Type>
49 (
50  dynamicCode& dynCode,
51  const dynamicCodeContext& context
52 ) const
53 {
54  dynCode.setFilterVariable("typeName", codeName());
55 
56  // Set TemplateType and FieldType filter variables
57  // (for fvPatchField)
58  word fieldType(pTraits<Type>::typeName);
59 
60  // Template type for fvPatchField
61  dynCode.setFilterVariable("TemplateType", fieldType);
62 
63  // Name for fvPatchField - eg, ScalarField, VectorField, ...
64  fieldType[0] = toupper(fieldType[0]);
65  dynCode.setFilterVariable("FieldType", fieldType + "Field");
66 
67  // Compile filtered C template
68  dynCode.addCompileFile(codeTemplateC("codedFixedValueFvPatchField"));
69 
70  // Copy filtered H template
71  dynCode.addCopyFile(codeTemplateH("codedFixedValueFvPatchField"));
72 
73  // Debugging: make BC verbose
74  if (debug)
75  {
76  dynCode.setFilterVariable("verbose", "true");
77  Info<<"compile " << codeName() << " sha1: "
78  << context.sha1() << endl;
79  }
80 
81  // Define Make/options
82  dynCode.setMakeOptions
83  (
84  "EXE_INC = -g \\\n"
85  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
86  + context.options()
87  + "\n\nLIB_LIBS = \\\n"
88  + " -lOpenFOAM \\\n"
89  + " -lfiniteVolume \\\n"
90  + context.libs()
91  );
92 }
93 
94 
95 template<class Type>
97 {
98  // Remove instantiation of fvPatchField provided by library
99  redirectPatchFieldPtr_.clear();
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
105 template<class Type>
107 (
108  const fvPatch& p,
110  const dictionary& dict
111 )
112 :
113  fixedValueFvPatchField<Type>(p, iF, dict),
114  codedBase(dict),
115  redirectPatchFieldPtr_()
116 {
117  updateLibrary();
118 }
119 
120 
121 template<class Type>
123 (
125  const fvPatch& p,
127  const fvPatchFieldMapper& mapper
128 )
129 :
130  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
131  codedBase(ptf),
132  redirectPatchFieldPtr_()
133 {}
134 
135 
136 template<class Type>
138 (
141 )
142 :
143  fixedValueFvPatchField<Type>(ptf, iF),
144  codedBase(ptf),
145  redirectPatchFieldPtr_()
146 {}
147 
148 
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 
151 template<class Type>
154 {
155  if (!redirectPatchFieldPtr_.valid())
156  {
157  OStringStream os;
158  writeEntry(os, "type", codeName());
159 
160  if (this->overridesConstraint())
161  {
162  writeEntry(os, "patchType", this->patch().type());
163  }
164 
165  writeEntry(os, "value", *this);
166 
167  IStringStream is(os.str());
168  dictionary dict(is);
169 
170  redirectPatchFieldPtr_.set
171  (
173  (
174  this->patch(),
175  this->internalField(),
176  dict
177  ).ptr()
178  );
179  }
180 
181  return redirectPatchFieldPtr_();
182 }
183 
184 
185 template<class Type>
187 {
188  if (this->updated())
189  {
190  return;
191  }
192 
193  // Make sure library containing user-defined fvPatchField is up-to-date
194  updateLibrary();
195 
196  const fvPatchField<Type>& fvp = redirectPatchField();
197 
198  const_cast<fvPatchField<Type>&>(fvp).updateCoeffs();
199 
200  // Copy through value
201  this->operator==(fvp);
202 
204 }
205 
206 
207 template<class Type>
209 (
210  const Pstream::commsTypes commsType
211 )
212 {
213  // Make sure library containing user-defined fvPatchField is up-to-date
214  updateLibrary();
215 
216  const fvPatchField<Type>& fvp = redirectPatchField();
217 
218  const_cast<fvPatchField<Type>&>(fvp).evaluate(commsType);
219 
221 }
222 
223 
224 template<class Type>
226 {
228  writeCode(os);
229 }
230 
231 
232 // ************************************************************************* //
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:288
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:160
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
virtual void write(Ostream &) const
Write.
Foam::fvPatchFieldMapper.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:87
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:211
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:204
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:251
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