codedMixedFvPatchField.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 
26 #include "codedMixedFvPatchField.H"
27 #include "fieldMapper.H"
28 #include "volFields.H"
29 #include "dynamicCode.H"
30 #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("codedMixedFvPatchField"));
71 
72  // Copy filtered H template
73  dynCode.addCopyFile(codeTemplateH("codedMixedFvPatchField"));
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  mixedFvPatchField<Type>(p, iF, dict),
116  codedBase(dict),
117  redirectPatchFieldPtr_()
118 {
119  updateLibrary();
120 }
121 
122 
123 template<class Type>
125 (
126  const codedMixedFvPatchField<Type>& ptf,
127  const fvPatch& p,
129  const fieldMapper& mapper
130 )
131 :
132  mixedFvPatchField<Type>(ptf, p, iF, mapper),
133  codedBase(ptf),
134  redirectPatchFieldPtr_()
135 {}
136 
137 
138 template<class Type>
140 (
141  const codedMixedFvPatchField<Type>& ptf,
143 )
144 :
145  mixedFvPatchField<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;
161  IStringStream is(os.str());
162  dictionary dict(is);
163 
164  // Override the type to enforce the fvPatchField::New constructor
165  // to choose our type
166  dict.set("type", codeName());
167 
168  redirectPatchFieldPtr_.set
169  (
170  dynamic_cast<mixedFvPatchField<Type>*>
171  (
173  (
174  this->patch(),
175  this->internalField(),
176  dict
177  ).ptr()
178  )
179  );
180  }
181 
182  return redirectPatchFieldPtr_();
183 }
184 
185 
186 template<class Type>
188 {
189  if (this->updated())
190  {
191  return;
192  }
193 
194  // Make sure library containing user-defined fvPatchField is up-to-date
195  updateLibrary();
196 
197  const mixedFvPatchField<Type>& fvp = redirectPatchField();
198 
199  const_cast<mixedFvPatchField<Type>&>(fvp).updateCoeffs();
200 
201  // Copy through coefficients
202  this->refValue() = fvp.refValue();
203  this->refGrad() = fvp.refGrad();
204  this->valueFraction() = fvp.valueFraction();
205 
207 }
208 
209 
210 template<class Type>
212 (
213  const Pstream::commsTypes commsType
214 )
215 {
216  // Make sure library containing user-defined fvPatchField is up-to-date
217  updateLibrary();
218 
219  const mixedFvPatchField<Type>& fvp = redirectPatchField();
220 
221  // - updates the value of fvp (though not used)
222  // - resets the updated() flag
223  const_cast<mixedFvPatchField<Type>&>(fvp).evaluate(commsType);
224 
225  // Update the value (using the coefficients) locally
227 }
228 
229 
230 template<class Type>
232 {
234  writeCode(os);
235 }
236 
237 
238 // ************************************************************************* //
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 mixedFvPatchField) which is then used to...
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual void write(Ostream &) const
Write.
codedMixedFvPatchField(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 mixedFvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patchField.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:1152
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
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
This boundary condition provides a base class for 'mixed' type boundary conditions,...
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual void write(Ostream &) const
Write.
virtual Field< Type > & refValue()
virtual scalarField & valueFraction()
virtual Field< Type > & refGrad()
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 evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
dictionary dict
volScalarField & p