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  // Debugging: make BC verbose
75  if (debug)
76  {
77  // Debugging: make BC verbose
78  dynCode.setFilterVariable("verbose", "true");
79  Info<<"compile " << codeName() << " sha1: "
80  << 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 pointPatchField provided by library
101  redirectPatchFieldPtr_.clear();
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
107 template<class Type>
109 (
111  const pointPatch& p,
113  const pointPatchFieldMapper& mapper
114 )
115 :
116  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
117  codedBase(ptf),
118  redirectPatchFieldPtr_()
119 {}
120 
121 
122 template<class Type>
124 (
125  const pointPatch& p,
127  const dictionary& dict
128 )
129 :
130  fixedValuePointPatchField<Type>(p, iF, dict),
131  codedBase(dict),
132  redirectPatchFieldPtr_()
133 {
134  updateLibrary();
135 }
136 
137 
138 template<class Type>
140 (
143 )
144 :
145  fixedValuePointPatchField<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;
160  writeEntry(os, "type", codeName());
161  writeEntry(os, "value", static_cast<const Field<Type>&>(*this));
162  IStringStream is(os.str());
163  dictionary dict(is);
164 
165  redirectPatchFieldPtr_.set
166  (
168  (
169  this->patch(),
170  this->internalField(),
171  dict
172  ).ptr()
173  );
174  }
175 
176  return redirectPatchFieldPtr_();
177 }
178 
179 
180 template<class Type>
182 {
183  if (this->updated())
184  {
185  return;
186  }
187 
188  // Make sure library containing user-defined pointPatchField is up-to-date
189  updateLibrary();
190 
191  const pointPatchField<Type>& fvp = redirectPatchField();
192 
193  const_cast<pointPatchField<Type>&>(fvp).updateCoeffs();
194 
195  // Copy through value
196  this->operator==(fvp);
197 
199 }
200 
201 
202 template<class Type>
204 (
205  const Pstream::commsTypes commsType
206 )
207 {
208  // Make sure library containing user-defined pointPatchField is up-to-date
209  updateLibrary();
210 
211  const pointPatchField<Type>& fvp = redirectPatchField();
212 
213  const_cast<pointPatchField<Type>&>(fvp).evaluate(commsType);
214 
216 }
217 
218 
219 template<class Type>
221 {
223  writeCode(os);
224 }
225 
226 
227 // ************************************************************************* //
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
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