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-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 "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  dynamicCode& dynCode,
39  const dynamicCodeContext& context
40 ) const
41 {
42  // Take no chances - typeName must be identical to codeName()
43  dynCode.setFilterVariable("typeName", codeName());
44 
45  // Set TemplateType and FieldType filter variables
46  // (for pointPatchField)
47  word fieldType(pTraits<Type>::typeName);
48 
49  // Template type for pointPatchField
50  dynCode.setFilterVariable("TemplateType", fieldType);
51 
52  // Name for pointPatchField - eg, ScalarField, VectorField, ...
53  fieldType[0] = toupper(fieldType[0]);
54  dynCode.setFilterVariable("FieldType", fieldType + "Field");
55 
56  // Compile filtered C template
57  dynCode.addCompileFile(codeTemplateC);
58 
59  // Copy filtered H template
60  dynCode.addCopyFile(codeTemplateH);
61 
62  // Debugging: make BC verbose
63  if (debug)
64  {
65  // Debugging: make BC verbose
66  dynCode.setFilterVariable("verbose", "true");
67  Info<<"compile " << codeName() << " sha1: "
68  << context.sha1() << endl;
69  }
70 
71  // Define Make/options
72  dynCode.setMakeOptions
73  (
74  "EXE_INC = -g \\\n"
75  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
76  + context.options()
77  + "\n\nLIB_LIBS = \\\n"
78  + " -lOpenFOAM \\\n"
79  + " -lfiniteVolume \\\n"
80  + context.libs()
81  );
82 }
83 
84 
85 template<class Type>
87 {
88  // Remove instantiation of pointPatchField provided by library
89  redirectPatchFieldPtr_.clear();
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 
95 template<class Type>
97 (
98  const pointPatch& p,
100 )
101 :
104  redirectPatchFieldPtr_()
105 {}
106 
107 
108 template<class Type>
110 (
112  const pointPatch& p,
114  const pointPatchFieldMapper& mapper
115 )
116 :
117  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
119  redirectPatchFieldPtr_()
120 {}
121 
122 
123 template<class Type>
125 (
126  const pointPatch& p,
128  const dictionary& dict
129 )
130 :
133  redirectPatchFieldPtr_()
134 {
135  updateLibrary();
136 }
137 
138 
139 template<class Type>
141 (
143 )
144 :
147  redirectPatchFieldPtr_()
148 {}
149 
150 
151 template<class Type>
153 (
156 )
157 :
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
codedFixedValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
commsTypes
Types of communications.
Definition: UPstream.H:64
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.
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