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-2021 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"
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("codedMixedFvPatchField"));
69 
70  // Copy filtered H template
71  dynCode.addCopyFile(codeTemplateH("codedMixedFvPatchField"));
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 )
111 :
113  codedBase(),
114  redirectPatchFieldPtr_()
115 {}
116 
117 
118 template<class Type>
120 (
121  const fvPatch& p,
123  const dictionary& dict
124 )
125 :
127  codedBase(dict),
128  redirectPatchFieldPtr_()
129 {
130  updateLibrary();
131 }
132 
133 
134 template<class Type>
136 (
137  const codedMixedFvPatchField<Type>& ptf,
138  const fvPatch& p,
140  const fvPatchFieldMapper& mapper
141 )
142 :
143  mixedFvPatchField<Type>(ptf, p, iF, mapper),
144  codedBase(ptf),
145  redirectPatchFieldPtr_()
146 {}
147 
148 
149 template<class Type>
151 (
152  const codedMixedFvPatchField<Type>& ptf,
154 )
155 :
156  mixedFvPatchField<Type>(ptf, iF),
157  codedBase(ptf),
158  redirectPatchFieldPtr_()
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 
164 template<class Type>
167 {
168  if (!redirectPatchFieldPtr_.valid())
169  {
170  OStringStream os;
172  IStringStream is(os.str());
173  dictionary dict(is);
174 
175  // Override the type to enforce the fvPatchField::New constructor
176  // to choose our type
177  dict.set("type", codeName());
178 
179  redirectPatchFieldPtr_.set
180  (
181  dynamic_cast<mixedFvPatchField<Type>*>
182  (
184  (
185  this->patch(),
186  this->internalField(),
187  dict
188  ).ptr()
189  )
190  );
191  }
192 
193  return redirectPatchFieldPtr_();
194 }
195 
196 
197 template<class Type>
199 {
200  if (this->updated())
201  {
202  return;
203  }
204 
205  // Make sure library containing user-defined fvPatchField is up-to-date
206  updateLibrary();
207 
208  const mixedFvPatchField<Type>& fvp = redirectPatchField();
209 
210  const_cast<mixedFvPatchField<Type>&>(fvp).updateCoeffs();
211 
212  // Copy through coefficients
213  this->refValue() = fvp.refValue();
214  this->refGrad() = fvp.refGrad();
215  this->valueFraction() = fvp.valueFraction();
216 
218 }
219 
220 
221 template<class Type>
223 (
224  const Pstream::commsTypes commsType
225 )
226 {
227  // Make sure library containing user-defined fvPatchField is up-to-date
228  updateLibrary();
229 
230  const mixedFvPatchField<Type>& fvp = redirectPatchField();
231 
232  // - updates the value of fvp (though not used)
233  // - resets the updated() flag
234  const_cast<mixedFvPatchField<Type>&>(fvp).evaluate(commsType);
235 
236  // Update the value (using the coefficients) locally
238 }
239 
240 
241 template<class Type>
243 {
245  writeCode(os);
246 }
247 
248 
249 // ************************************************************************* //
dictionary dict
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
commsTypes
Types of communications.
Definition: UPstream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
This boundary condition provides a base class for &#39;mixed&#39; type boundary conditions, i.e. conditions that mix fixed value and patch-normal gradient conditions.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
Macros for easy insertion into run-time selection tables.
const mixedFvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patchField.
virtual Field< Type > & refValue()
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
virtual scalarField & valueFraction()
Foam::fvPatchFieldMapper.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
codedMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void write(Ostream &) const
Write.
Constructs on-the-fly a new boundary condition (derived from mixedFvPatchField) which is then used to...
Input from memory buffer stream.
Definition: IStringStream.H:49
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
string str() const
Return the string.
messageStream Info
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
volScalarField & p
Output to memory buffer stream.
Definition: OStringStream.H:49
virtual Field< Type > & refGrad()