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 | Copyright (C) 2012 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 #include "stringOps.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 template<class Type>
38  = "fixedValuePointPatchFieldTemplate.C";
39 
40 template<class Type>
42  = "fixedValuePointPatchFieldTemplate.H";
43 
44 
45 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
46 
47 template<class Type>
49 (
50  dynamicCode& dynCode
51 )
52 {
53  word fieldType(pTraits<Type>::typeName);
54 
55  // template type for pointPatchField
56  dynCode.setFilterVariable("TemplateType", fieldType);
57 
58  // Name for pointPatchField - eg, ScalarField, VectorField, ...
59  fieldType[0] = toupper(fieldType[0]);
60  dynCode.setFilterVariable("FieldType", fieldType + "Field");
61 }
62 
63 
64 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
65 
66 template<class Type>
68 const
69 {
70  const objectRegistry& obr = this->db();
71 
72  if (obr.foundObject<IOdictionary>("codeDict"))
73  {
74  return obr.lookupObject<IOdictionary>("codeDict");
75  }
76  else
77  {
78  return obr.store
79  (
80  new IOdictionary
81  (
82  IOobject
83  (
84  "codeDict",
85  this->db().time().system(),
86  this->db(),
87  IOobject::MUST_READ_IF_MODIFIED,
88  IOobject::NO_WRITE
89  )
90  )
91  );
92  }
93 }
94 
95 
96 template<class Type>
98 {
99  return const_cast<dlLibraryTable&>(this->db().time().libs());
100 }
101 
102 
103 template<class Type>
105 (
106  dynamicCode& dynCode,
107  const dynamicCodeContext& context
108 ) const
109 {
110  // take no chances - typeName must be identical to redirectType_
111  dynCode.setFilterVariable("typeName", redirectType_);
112 
113  // set TemplateType and FieldType filter variables
114  // (for pointPatchField)
115  setFieldTemplates(dynCode);
116 
117  // compile filtered C template
118  dynCode.addCompileFile(codeTemplateC);
119 
120  // copy filtered H template
121  dynCode.addCopyFile(codeTemplateH);
122 
123 
124  // debugging: make BC verbose
125  // dynCode.setFilterVariable("verbose", "true");
126  // Info<<"compile " << redirectType_ << " sha1: "
127  // << context.sha1() << endl;
128 
129  // define Make/options
130  dynCode.setMakeOptions
131  (
132  "EXE_INC = -g \\\n"
133  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
134  + context.options()
135  + "\n\nLIB_LIBS = \\\n"
136  + " -lOpenFOAM \\\n"
137  + " -lfiniteVolume \\\n"
138  + context.libs()
139  );
140 }
141 
142 
143 template<class Type>
145 const
146 {
147  // use system/codeDict or in-line
148  return
149  (
150  dict_.found("code")
151  ? dict_
152  : this->dict().subDict(redirectType_)
153  );
154 }
155 
156 
157 template<class Type>
159 {
160  return
161  "patch "
162  + this->patch().name()
163  + " on field "
164  + this->dimensionedInternalField().name();
165 }
166 
167 
168 template<class Type>
170 {
171  // remove instantiation of pointPatchField provided by library
172  redirectPatchFieldPtr_.clear();
173 }
174 
175 
176 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
177 
178 template<class Type>
180 (
181  const pointPatch& p,
183 )
184 :
186  codedBase(),
187  redirectPatchFieldPtr_()
188 {}
189 
190 
191 template<class Type>
193 (
195  const pointPatch& p,
197  const pointPatchFieldMapper& mapper
198 )
199 :
200  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
201  codedBase(),
202  dict_(ptf.dict_),
203  redirectType_(ptf.redirectType_),
204  redirectPatchFieldPtr_()
205 {}
206 
207 
208 template<class Type>
210 (
211  const pointPatch& p,
213  const dictionary& dict,
214  const bool valueRequired
215 )
216 :
217  fixedValuePointPatchField<Type>(p, iF, dict, valueRequired),
218  codedBase(),
219  dict_(dict),
220  redirectType_(dict.lookup("redirectType")),
221  redirectPatchFieldPtr_()
222 {
223  updateLibrary(redirectType_);
224 }
225 
226 
227 template<class Type>
229 (
231 )
232 :
234  codedBase(),
235  dict_(ptf.dict_),
236  redirectType_(ptf.redirectType_),
237  redirectPatchFieldPtr_()
238 {}
239 
240 
241 template<class Type>
243 (
246 )
247 :
249  codedBase(),
250  dict_(ptf.dict_),
251  redirectType_(ptf.redirectType_),
252  redirectPatchFieldPtr_()
253 {}
254 
255 
256 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
257 
258 template<class Type>
261 {
262  if (!redirectPatchFieldPtr_.valid())
263  {
264  // Construct a patch
265  // Make sure to construct the patchfield with up-to-date value
266 
267  OStringStream os;
268  os.writeKeyword("type") << redirectType_ << token::END_STATEMENT
269  << nl;
270  static_cast<const Field<Type>&>(*this).writeEntry("value", os);
271  IStringStream is(os.str());
272  dictionary dict(is);
273 
274  redirectPatchFieldPtr_.set
275  (
277  (
278  this->patch(),
279  this->dimensionedInternalField(),
280  dict
281  ).ptr()
282  );
283  }
284  return redirectPatchFieldPtr_();
285 }
286 
287 
288 template<class Type>
290 {
291  if (this->updated())
292  {
293  return;
294  }
295 
296  // Make sure library containing user-defined pointPatchField is up-to-date
297  updateLibrary(redirectType_);
298 
299  const pointPatchField<Type>& fvp = redirectPatchField();
300 
301  const_cast<pointPatchField<Type>&>(fvp).updateCoeffs();
302 
303  // Copy through value
304  this->operator==(fvp);
305 
307 }
308 
309 
310 template<class Type>
312 (
313  const Pstream::commsTypes commsType
314 )
315 {
316  // Make sure library containing user-defined pointPatchField is up-to-date
317  updateLibrary(redirectType_);
318 
319  const pointPatchField<Type>& fvp = redirectPatchField();
320 
321  const_cast<pointPatchField<Type>&>(fvp).evaluate(commsType);
322 
324 }
325 
326 
327 template<class Type>
329 {
331  os.writeKeyword("redirectType") << redirectType_
332  << token::END_STATEMENT << nl;
333 
334  if (dict_.found("codeInclude"))
335  {
336  os.writeKeyword("codeInclude")
337  << token::HASH << token::BEGIN_BLOCK;
338 
339  os.writeQuoted(string(dict_["codeInclude"]), false)
340  << token::HASH << token::END_BLOCK
341  << token::END_STATEMENT << nl;
342  }
343 
344  if (dict_.found("localCode"))
345  {
346  os.writeKeyword("localCode")
347  << token::HASH << token::BEGIN_BLOCK;
348 
349  os.writeQuoted(string(dict_["localCode"]), false)
350  << token::HASH << token::END_BLOCK
351  << token::END_STATEMENT << nl;
352  }
353 
354  if (dict_.found("code"))
355  {
356  os.writeKeyword("code")
357  << token::HASH << token::BEGIN_BLOCK;
358 
359  os.writeQuoted(string(dict_["code"]), false)
360  << token::HASH << token::END_BLOCK
361  << token::END_STATEMENT << nl;
362  }
363 
364  if (dict_.found("codeOptions"))
365  {
366  os.writeKeyword("codeOptions")
367  << token::HASH << token::BEGIN_BLOCK;
368 
369  os.writeQuoted(string(dict_["codeOptions"]), false)
370  << token::HASH << token::END_BLOCK
371  << token::END_STATEMENT << nl;
372  }
373 
374  if (dict_.found("codeLibs"))
375  {
376  os.writeKeyword("codeLibs")
377  << token::HASH << token::BEGIN_BLOCK;
378 
379  os.writeQuoted(string(dict_["codeLibs"]), false)
380  << token::HASH << token::END_BLOCK
381  << token::END_STATEMENT << nl;
382  }
383 }
384 
385 
386 // ************************************************************************* //
Foam::dynamicCodeContext::libs
const string & libs() const
Return the code-libs.
Definition: dynamicCodeContext.H:102
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::codedFixedValuePointPatchField::dict
const IOdictionary & dict() const
Definition: codedFixedValuePointPatchField.C:67
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::codedFixedValuePointPatchField::setFieldTemplates
static void setFieldTemplates(dynamicCode &dynCode)
Set the rewrite vars controlling the Type.
Definition: codedFixedValuePointPatchField.C:49
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:49
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:49
dimensionedInternalField
rDeltaT dimensionedInternalField()
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
pointPatchFieldMapper.H
Foam::operator==
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
dynamicCodeContext.H
Foam::codedFixedValuePointPatchField
Constructs on-the-fly a new boundary condition (derived from fixedValuePointPatchField) which is then...
Definition: codedFixedValuePointPatchField.H:102
Foam::pointPatchField< Type >
Foam::codedFixedValuePointPatchField::codeDict
virtual const dictionary & codeDict() const
Definition: codedFixedValuePointPatchField.C:144
Foam::codedFixedValuePointPatchField::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: codedFixedValuePointPatchField.C:105
Foam::dynamicCode::addCopyFile
void addCopyFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:355
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:46
Foam::OStringStream::str
string str() const
Return the string.
Definition: OStringStream.H:107
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::dynamicCode::addCompileFile
void addCompileFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:349
Foam::fixedValuePointPatchField
A FixedValue boundary condition for pointField.
Definition: fixedValuePointPatchField.H:49
Foam::codedFixedValuePointPatchField::dict_
dictionary dict_
Dictionary contents for the boundary condition.
Definition: codedFixedValuePointPatchField.H:110
Foam::codedFixedValuePointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: codedFixedValuePointPatchField.C:328
Foam::Field< Type >
Foam::codedFixedValuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: codedFixedValuePointPatchField.C:289
Foam::nl
static const char nl
Definition: Ostream.H:260
dynamicCode.H
Foam::codedFixedValuePointPatchField::codedFixedValuePointPatchField
codedFixedValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Definition: codedFixedValuePointPatchField.C:180
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dynamicCodeContext::options
const string & options() const
Return the code-options.
Definition: dynamicCodeContext.H:96
Foam::codedFixedValuePointPatchField::redirectPatchField
const pointPatchField< Type > & redirectPatchField() const
Get reference to the underlying patch.
Definition: codedFixedValuePointPatchField.C:260
Foam::codedFixedValuePointPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::blocking)
Evaluate the patch field, sets Updated to false.
Definition: codedFixedValuePointPatchField.C:312
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam::dynamicCode::setFilterVariable
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
Definition: dynamicCode.C:384
Foam::codedFixedValuePointPatchField::clearRedirect
virtual void clearRedirect() const
Definition: codedFixedValuePointPatchField.C:169
Foam::Field::writeEntry
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:700
Foam::objectRegistry::foundObject
bool foundObject(const word &name) const
Is the named Type found?
Definition: objectRegistryTemplates.C:142
Foam::regIOobject::store
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:64
Foam::dynamicCode::setMakeOptions
void setMakeOptions(const std::string &content)
Define contents for Make/options.
Definition: dynamicCode.C:393
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::OStringStream
Output to memory buffer stream.
Definition: OStringStream.H:49
Foam::Ostream::writeQuoted
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)=0
Write std::string surrounded by quotes.
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::codedFixedValuePointPatchField::redirectType_
const word redirectType_
Definition: codedFixedValuePointPatchField.H:112
Foam::codedFixedValuePointPatchField::description
virtual string description() const
Definition: codedFixedValuePointPatchField.C:158
Foam::codedFixedValuePointPatchField::libs
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: codedFixedValuePointPatchField.C:97
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
stringOps.H
Foam::system
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1155
pointFields.H
write
Tcoeff write()
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:51
codedFixedValuePointPatchField.H