codedFixedValuePointPatchField.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) 2012-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 "pointPatchFieldMapper.H"
29 #include "pointFields.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  // Take no chances - typeName must be identical to codeName()
55  dynCode.setFilterVariable("typeName", codeName());
56 
57  // Set TemplateType and FieldType filter variables
58  // (for pointPatchField)
59  word fieldType(pTraits<Type>::typeName);
60 
61  // Template type for pointPatchField
62  dynCode.setFilterVariable("TemplateType", fieldType);
63 
64  // Name for pointPatchField - eg, ScalarField, VectorField, ...
65  fieldType[0] = toupper(fieldType[0]);
66  dynCode.setFilterVariable("FieldType", fieldType + "Field");
67 
68  // Compile filtered C template
69  dynCode.addCompileFile(codeTemplateC("codedFixedValuePointPatchField"));
70 
71  // Copy filtered H template
72  dynCode.addCopyFile(codeTemplateH("codedFixedValuePointPatchField"));
73 
74  // Make verbose if debugging
75  dynCode.setFilterVariable("verbose", Foam::name(bool(debug)));
76 
77  if (debug)
78  {
79  Info<<"compile " << codeName() << " sha1: " << context.sha1() << endl;
80  }
81 
82  // Define Make/options
83  dynCode.setMakeOptions
84  (
85  "EXE_INC = -g \\\n"
86  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
87  + context.options()
88  + "\n\nLIB_LIBS = \\\n"
89  + " -lOpenFOAM \\\n"
90  + " -lfiniteVolume \\\n"
91  + context.libs()
92  );
93 }
94 
95 
96 template<class Type>
98 {
99  // Remove instantiation of pointPatchField provided by library
100  redirectPatchFieldPtr_.clear();
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
106 template<class Type>
108 (
110  const pointPatch& p,
112  const pointPatchFieldMapper& mapper
113 )
114 :
115  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
116  codedBase(ptf),
117  redirectPatchFieldPtr_()
118 {}
119 
120 
121 template<class Type>
123 (
124  const pointPatch& p,
126  const dictionary& dict
127 )
128 :
129  fixedValuePointPatchField<Type>(p, iF, dict),
130  codedBase(dict),
131  redirectPatchFieldPtr_()
132 {
133  updateLibrary();
134 }
135 
136 
137 template<class Type>
139 (
142 )
143 :
144  fixedValuePointPatchField<Type>(ptf, iF),
145  codedBase(ptf),
146  redirectPatchFieldPtr_()
147 {}
148 
149 
150 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 
152 template<class Type>
155 {
156  if (!redirectPatchFieldPtr_.valid())
157  {
158  OStringStream os;
159  writeEntry(os, "type", codeName());
160  writeEntry(os, "value", static_cast<const Field<Type>&>(*this));
161  IStringStream is(os.str());
162  dictionary dict(is);
163 
164  redirectPatchFieldPtr_.set
165  (
167  (
168  this->patch(),
169  this->internalField(),
170  dict
171  ).ptr()
172  );
173  }
174 
175  return redirectPatchFieldPtr_();
176 }
177 
178 
179 template<class Type>
181 {
182  if (this->updated())
183  {
184  return;
185  }
186 
187  // Make sure library containing user-defined pointPatchField is up-to-date
188  updateLibrary();
189 
190  const pointPatchField<Type>& fvp = redirectPatchField();
191 
192  const_cast<pointPatchField<Type>&>(fvp).updateCoeffs();
193 
194  // Copy through value
195  this->operator==(fvp);
196 
198 }
199 
200 
201 template<class Type>
203 (
204  const Pstream::commsTypes commsType
205 )
206 {
207  // Make sure library containing user-defined pointPatchField is up-to-date
208  updateLibrary();
209 
210  const pointPatchField<Type>& fvp = redirectPatchField();
211 
212  const_cast<pointPatchField<Type>&>(fvp).evaluate(commsType);
213 
215 }
216 
217 
218 template<class Type>
220 {
222  writeCode(os);
223 }
224 
225 
226 // ************************************************************************* //
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...
Pre-declare SubField and related Field type.
Definition: Field.H:82
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 fixedValuePointPatchField) which is then...
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
codedFixedValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
virtual void write(Ostream &) const
Write.
const pointPatchField< Type > & redirectPatchField() const
Get reference to the underlying patch.
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:160
A FixedValue boundary condition for pointField.
Foam::pointPatchFieldMapper.
Abstract base class for point-mesh patch fields.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:57
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual void write(Ostream &) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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)
dictionary dict
volScalarField & p