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-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 
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 (
110  const pointPatch& p,
112 )
113 :
115  codedBase(),
116  redirectPatchFieldPtr_()
117 {}
118 
119 
120 template<class Type>
122 (
124  const pointPatch& p,
126  const pointPatchFieldMapper& mapper
127 )
128 :
129  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
130  codedBase(ptf),
131  redirectPatchFieldPtr_()
132 {}
133 
134 
135 template<class Type>
137 (
138  const pointPatch& p,
140  const dictionary& dict
141 )
142 :
144  codedBase(dict),
145  redirectPatchFieldPtr_()
146 {
147  updateLibrary();
148 }
149 
150 
151 template<class Type>
153 (
156 )
157 :
159  codedBase(ptf),
160  redirectPatchFieldPtr_()
161 {}
162 
163 
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 
166 template<class Type>
169 {
170  if (!redirectPatchFieldPtr_.valid())
171  {
172  OStringStream os;
173  writeEntry(os, "type", codeName());
174  writeEntry(os, "value", static_cast<const Field<Type>&>(*this));
175  IStringStream is(os.str());
176  dictionary dict(is);
177 
178  redirectPatchFieldPtr_.set
179  (
181  (
182  this->patch(),
183  this->internalField(),
184  dict
185  ).ptr()
186  );
187  }
188 
189  return redirectPatchFieldPtr_();
190 }
191 
192 
193 template<class Type>
195 {
196  if (this->updated())
197  {
198  return;
199  }
200 
201  // Make sure library containing user-defined pointPatchField is up-to-date
202  updateLibrary();
203 
204  const pointPatchField<Type>& fvp = redirectPatchField();
205 
206  const_cast<pointPatchField<Type>&>(fvp).updateCoeffs();
207 
208  // Copy through value
209  this->operator==(fvp);
210 
212 }
213 
214 
215 template<class Type>
217 (
218  const Pstream::commsTypes commsType
219 )
220 {
221  // Make sure library containing user-defined pointPatchField is up-to-date
222  updateLibrary();
223 
224  const pointPatchField<Type>& fvp = redirectPatchField();
225 
226  const_cast<pointPatchField<Type>&>(fvp).evaluate(commsType);
227 
229 }
230 
231 
232 template<class Type>
234 {
236  writeCode(os);
237 }
238 
239 
240 // ************************************************************************* //
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
codedFixedValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
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
A FixedValue boundary condition for pointField.
const pointPatchField< Type > & redirectPatchField() const
Get reference to the underlying patch.
Foam::pointPatchFieldMapper.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Macros for easy insertion into run-time selection tables.
Abstract base class for point-mesh patch fields.
Constructs on-the-fly a new boundary condition (derived from fixedValuePointPatchField) which is then...
Pre-declare SubField and related Field type.
Definition: Field.H:56
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 > &)
virtual void write(Ostream &) const
Write.
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
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
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Input from memory buffer stream.
Definition: IStringStream.H:49
virtual void updateCoeffs()
Update the coefficients associated with the patch 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
volScalarField & p
Output to memory buffer stream.
Definition: OStringStream.H:49