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-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 
28 #include "fieldMapper.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 {"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  // Take no chances - typeName must be identical to codeName()
57  dynCode.setFilterVariable("typeName", codeName());
58 
59  // Set TemplateType and FieldType filter variables
60  // (for pointPatchField)
61  word fieldType(pTraits<Type>::typeName);
62 
63  // Template type for pointPatchField
64  dynCode.setFilterVariable("TemplateType", fieldType);
65 
66  // Name for pointPatchField - eg, ScalarField, VectorField, ...
67  fieldType[0] = toupper(fieldType[0]);
68  dynCode.setFilterVariable("FieldType", fieldType + "Field");
69 
70  // Compile filtered C template
71  dynCode.addCompileFile(codeTemplateC("codedFixedValuePointPatchField"));
72 
73  // Copy filtered H template
74  dynCode.addCopyFile(codeTemplateH("codedFixedValuePointPatchField"));
75 
76  // Make verbose if debugging
77  dynCode.setFilterVariable("verbose", Foam::name(bool(debug)));
78 
79  if (debug)
80  {
81  Info<<"compile " << codeName() << " sha1: " << context.sha1() << endl;
82  }
83 
84  // Define Make/options
85  dynCode.setMakeOptions
86  (
87  "EXE_INC = -g \\\n"
88  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
89  + context.options()
90  + "\n\nLIB_LIBS = \\\n"
91  + " -lOpenFOAM \\\n"
92  + " -lfiniteVolume \\\n"
93  + context.libs()
94  );
95 }
96 
97 
98 template<class Type>
100 {
101  // Remove instantiation of pointPatchField provided by library
102  redirectPatchFieldPtr_.clear();
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 
108 template<class Type>
110 (
112  const pointPatch& p,
114  const fieldMapper& mapper
115 )
116 :
117  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
118  codedBase(ptf),
119  redirectPatchFieldPtr_()
120 {}
121 
122 
123 template<class Type>
125 (
126  const pointPatch& p,
128  const dictionary& dict
129 )
130 :
131  fixedValuePointPatchField<Type>(p, iF, dict),
132  codedBase(dict),
133  redirectPatchFieldPtr_()
134 {
135  updateLibrary();
136 }
137 
138 
139 template<class Type>
141 (
144 )
145 :
146  fixedValuePointPatchField<Type>(ptf, iF),
147  codedBase(ptf),
148  redirectPatchFieldPtr_()
149 {}
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
154 template<class Type>
157 {
158  if (!redirectPatchFieldPtr_.valid())
159  {
160  OStringStream os;
161  writeEntry(os, "type", codeName());
162  writeEntry(os, "value", static_cast<const Field<Type>&>(*this));
163  IStringStream is(os.str());
164  dictionary dict(is);
165 
166  redirectPatchFieldPtr_.set
167  (
169  (
170  this->patch(),
171  this->internalField(),
172  dict
173  ).ptr()
174  );
175  }
176 
177  return redirectPatchFieldPtr_();
178 }
179 
180 
181 template<class Type>
183 {
184  if (this->updated())
185  {
186  return;
187  }
188 
189  // Make sure library containing user-defined pointPatchField is up-to-date
190  updateLibrary();
191 
192  const pointPatchField<Type>& fvp = redirectPatchField();
193 
194  const_cast<pointPatchField<Type>&>(fvp).updateCoeffs();
195 
196  // Copy through value
197  this->operator==(fvp);
198 
200 }
201 
202 
203 template<class Type>
205 (
206  const Pstream::commsTypes commsType
207 )
208 {
209  // Make sure library containing user-defined pointPatchField is up-to-date
210  updateLibrary();
211 
212  const pointPatchField<Type>& fvp = redirectPatchField();
213 
214  const_cast<pointPatchField<Type>&>(fvp).evaluate(commsType);
215 
217 }
218 
219 
220 template<class Type>
222 {
224  writeCode(os);
225 }
226 
227 
228 // ************************************************************************* //
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:83
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 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:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
A FixedValue boundary condition for pointField.
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:257
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