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-2020 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  dynamicCode& dynCode,
39  const dynamicCodeContext& context
40 ) const
41 {
42  dynCode.setFilterVariable("typeName", codeName());
43 
44  // Set TemplateType and FieldType filter variables
45  // (for fvPatchField)
46  word fieldType(pTraits<Type>::typeName);
47 
48  // Template type for fvPatchField
49  dynCode.setFilterVariable("TemplateType", fieldType);
50 
51  // Name for fvPatchField - eg, ScalarField, VectorField, ...
52  fieldType[0] = toupper(fieldType[0]);
53  dynCode.setFilterVariable("FieldType", fieldType + "Field");
54 
55  // Compile filtered C template
56  dynCode.addCompileFile(codeTemplateC);
57 
58  // Copy filtered H template
59  dynCode.addCopyFile(codeTemplateH);
60 
61  // Debugging: make BC verbose
62  if (debug)
63  {
64  dynCode.setFilterVariable("verbose", "true");
65  Info<<"compile " << codeName() << " sha1: "
66  << context.sha1() << endl;
67  }
68 
69  // Define Make/options
70  dynCode.setMakeOptions
71  (
72  "EXE_INC = -g \\\n"
73  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
74  + context.options()
75  + "\n\nLIB_LIBS = \\\n"
76  + " -lOpenFOAM \\\n"
77  + " -lfiniteVolume \\\n"
78  + context.libs()
79  );
80 }
81 
82 
83 template<class Type>
85 {
86  // Remove instantiation of fvPatchField provided by library
87  redirectPatchFieldPtr_.clear();
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 template<class Type>
95 (
96  const fvPatch& p,
98 )
99 :
102  redirectPatchFieldPtr_()
103 {}
104 
105 
106 template<class Type>
108 (
110  const fvPatch& p,
112  const fvPatchFieldMapper& mapper
113 )
114 :
115  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
117  redirectPatchFieldPtr_()
118 {}
119 
120 
121 template<class Type>
123 (
124  const fvPatch& p,
126  const dictionary& dict
127 )
128 :
131  redirectPatchFieldPtr_()
132 {
133  updateLibrary();
134 }
135 
136 
137 template<class Type>
139 (
141 )
142 :
145  redirectPatchFieldPtr_()
146 {}
147 
148 
149 template<class Type>
151 (
154 )
155 :
158  redirectPatchFieldPtr_()
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 
164 template<class Type>
167 {
168  if (!redirectPatchFieldPtr_.valid())
169  {
170  OStringStream os;
171  writeEntry(os, "type", codeName());
172  writeEntry(os, "value", *this);
173  IStringStream is(os.str());
174  dictionary dict(is);
175 
176  redirectPatchFieldPtr_.set
177  (
179  (
180  this->patch(),
181  this->internalField(),
182  dict
183  ).ptr()
184  );
185  }
186 
187  return redirectPatchFieldPtr_();
188 }
189 
190 
191 template<class Type>
193 {
194  if (this->updated())
195  {
196  return;
197  }
198 
199  // Make sure library containing user-defined fvPatchField is up-to-date
200  updateLibrary();
201 
202  const fvPatchField<Type>& fvp = redirectPatchField();
203 
204  const_cast<fvPatchField<Type>&>(fvp).updateCoeffs();
205 
206  // Copy through value
207  this->operator==(fvp);
208 
210 }
211 
212 
213 template<class Type>
215 (
216  const Pstream::commsTypes commsType
217 )
218 {
219  // Make sure library containing user-defined fvPatchField is up-to-date
220  updateLibrary();
221 
222  const fvPatchField<Type>& fvp = redirectPatchField();
223 
224  const_cast<fvPatchField<Type>&>(fvp).evaluate(commsType);
225 
227 }
228 
229 
230 template<class Type>
232 {
234  writeCode(os);
235 }
236 
237 
238 // ************************************************************************* //
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
dictionary dict
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
commsTypes
Types of communications.
Definition: UPstream.H:64
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:61
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.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Foam::fvPatchFieldMapper.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Constructs on-the-fly a new boundary condition (derived from fixedValueFvPatchField) which is then us...
Input from memory buffer stream.
Definition: IStringStream.H:49
codedFixedValueFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
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 write(Ostream &) const
Write.
volScalarField & p
Output to memory buffer stream.
Definition: OStringStream.H:49
const fvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patch.