codedFixedValuePointPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "pointPatchFieldMapper.H"
32 #include "pointFields.H"
33 #include "dynamicCode.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 template<class Type>
39 const
40 {
41  const objectRegistry& obr = this->db();
42 
43  const IOdictionary* dictptr = obr.cfindObject<IOdictionary>("codeDict");
44  if (dictptr)
45  {
46  return *dictptr;
47  }
48 
49  return obr.store
50  (
51  new IOdictionary
52  (
53  IOobject
54  (
55  "codeDict",
56  this->db().time().system(),
57  this->db(),
58  IOobject::MUST_READ_IF_MODIFIED,
59  IOobject::NO_WRITE
60  )
61  )
62  );
63 }
64 
65 
66 template<class Type>
68 {
69  return this->db().time().libs();
70 }
71 
72 
73 template<class Type>
75 (
76  dynamicCode& dynCode,
77  const dynamicCodeContext& context
78 ) const
79 {
80  // Take no chances - typeName must be identical to name_
81  dynCode.setFilterVariable("typeName", name_);
82 
83  // Set TemplateType and FieldType filter variables
84  dynCode.setFieldTemplates<Type>();
85 
86  // Compile filtered C template
87  dynCode.addCompileFile(codeTemplateC);
88 
89  // Copy filtered H template
90  dynCode.addCopyFile(codeTemplateH);
91 
92  // Debugging: make verbose
93  // dynCode.setFilterVariable("verbose", "true");
94  // DetailInfo
95  // <<"compile " << name_ << " sha1: "
96  // << context.sha1() << endl;
97 
98  // Define Make/options
99  dynCode.setMakeOptions
100  (
101  "EXE_INC = -g \\\n"
102  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
103  + context.options()
104  + "\n\nLIB_LIBS = \\\n"
105  " -lOpenFOAM \\\n"
106  " -lfiniteVolume \\\n"
107  + context.libs()
108  );
109 }
110 
111 
112 template<class Type>
114 const
115 {
116  // Use system/codeDict or in-line
117  return
118  (
119  dict_.found("code")
120  ? dict_
121  : this->dict().subDict(name_)
122  );
123 }
124 
125 
126 template<class Type>
128 {
129  return
130  "patch "
131  + this->patch().name()
132  + " on field "
133  + this->internalField().name();
134 }
135 
136 
137 template<class Type>
139 {
140  // Remove instantiation of pointPatchField provided by library
141  redirectPatchFieldPtr_.clear();
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
146 
147 template<class Type>
149 (
150  const pointPatch& p,
152 )
153 :
155  codedBase(),
156  redirectPatchFieldPtr_()
157 {}
158 
159 
160 template<class Type>
162 (
164  const pointPatch& p,
166  const pointPatchFieldMapper& mapper
167 )
168 :
169  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
170  codedBase(),
171  dict_(ptf.dict_),
172  name_(ptf.name_),
173  redirectPatchFieldPtr_()
174 {}
175 
176 
177 template<class Type>
179 (
180  const pointPatch& p,
182  const dictionary& dict,
183  const bool valueRequired
184 )
185 :
186  fixedValuePointPatchField<Type>(p, iF, dict, valueRequired),
187  codedBase(),
188  dict_(dict),
189  name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
190  redirectPatchFieldPtr_()
191 {
192  updateLibrary(name_);
193 }
194 
195 
196 template<class Type>
198 (
200 )
201 :
203  codedBase(),
204  dict_(ptf.dict_),
205  name_(ptf.name_),
206  redirectPatchFieldPtr_()
207 {}
208 
209 
210 template<class Type>
212 (
215 )
216 :
218  codedBase(),
219  dict_(ptf.dict_),
220  name_(ptf.name_),
221  redirectPatchFieldPtr_()
222 {}
223 
224 
225 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
226 
227 template<class Type>
230 {
231  if (!redirectPatchFieldPtr_)
232  {
233  // Construct a patch
234  // Make sure to construct the patchfield with up-to-date value
235 
236  OStringStream os;
237  os.writeEntry("type", name_);
238  static_cast<const Field<Type>&>(*this).writeEntry("value", os);
239  IStringStream is(os.str());
240  dictionary dict(is);
241 
242  redirectPatchFieldPtr_.reset
243  (
245  (
246  this->patch(),
247  this->internalField(),
248  dict
249  ).ptr()
250  );
251  }
252  return *redirectPatchFieldPtr_;
253 }
254 
255 
256 template<class Type>
258 {
259  if (this->updated())
260  {
261  return;
262  }
263 
264  // Make sure library containing user-defined pointPatchField is up-to-date
265  updateLibrary(name_);
266 
267  const pointPatchField<Type>& fvp = redirectPatchField();
268 
269  const_cast<pointPatchField<Type>&>(fvp).updateCoeffs();
270 
271  // Copy through value
272  this->operator==(fvp);
273 
275 }
276 
277 
278 template<class Type>
280 (
281  const Pstream::commsTypes commsType
282 )
283 {
284  // Make sure library containing user-defined pointPatchField is up-to-date
285  updateLibrary(name_);
286 
287  const pointPatchField<Type>& fvp = redirectPatchField();
288 
289  const_cast<pointPatchField<Type>&>(fvp).evaluate(commsType);
290 
292 }
293 
294 
295 template<class Type>
297 {
299  os.writeEntry("name", name_);
300 
301  codedBase::writeCodeDict(os, dict_);
302 }
303 
304 
305 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:63
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::system
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: MSwindows.C:1140
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition: codedBase.H:67
pointPatchFieldMapper.H
Foam::codedFixedValuePointPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: codedFixedValuePointPatchField.C:280
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::codedFixedValuePointPatchField
Constructs on-the-fly a new boundary condition (derived from fixedValuePointPatchField) which is then...
Definition: codedFixedValuePointPatchField.H:103
Foam::pointPatchField
Abstract base class for point-mesh patch fields.
Definition: pointMVCWeight.H:60
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
Foam::fixedValuePointPatchField
A FixedValue boundary condition for pointField.
Definition: fixedValuePointPatchField.H:51
Foam::codedFixedValuePointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: codedFixedValuePointPatchField.C:296
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::codedFixedValuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: codedFixedValuePointPatchField.C:257
dynamicCode.H
Foam::codedFixedValuePointPatchField::codedFixedValuePointPatchField
codedFixedValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Definition: codedFixedValuePointPatchField.C:149
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::codedFixedValuePointPatchField::redirectPatchField
const pointPatchField< Type > & redirectPatchField() const
Get reference to the underlying patch.
Definition: codedFixedValuePointPatchField.C:229
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam::Field::writeEntry
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:620
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:91
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:196
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
pointFields.H
Foam::stringOps::evaluate
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:37
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
codedFixedValuePointPatchField.H