codedMixedFvPatchField.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) 2011-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 
26 #include "codedMixedFvPatchField.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "dynamicCode.H"
31 #include "dynamicCodeContext.H"
32 #include "stringOps.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 template<class Type>
38  = "mixedFvPatchFieldTemplate.C";
39 
40 template<class Type>
42  = "mixedFvPatchFieldTemplate.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 fvPatchField
56  dynCode.setFilterVariable("TemplateType", fieldType);
57 
58  // Name for fvPatchField - 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 {
69  const objectRegistry& obr = this->db();
70 
71  if (obr.foundObject<IOdictionary>("codeDict"))
72  {
73  return obr.lookupObject<IOdictionary>("codeDict");
74  }
75  else
76  {
77  return obr.store
78  (
79  new IOdictionary
80  (
81  IOobject
82  (
83  "codeDict",
84  this->db().time().system(),
85  this->db(),
86  IOobject::MUST_READ_IF_MODIFIED,
87  IOobject::NO_WRITE
88  )
89  )
90  );
91  }
92 }
93 
94 
95 template<class Type>
97 {
98  return const_cast<dlLibraryTable&>(this->db().time().libs());
99 }
100 
101 
102 template<class Type>
104 (
105  dynamicCode& dynCode,
106  const dynamicCodeContext& context
107 ) const
108 {
109  // take no chances - typeName must be identical to redirectType_
110  dynCode.setFilterVariable("typeName", redirectType_);
111 
112  // set TemplateType and FieldType filter variables
113  // (for fvPatchField)
114  setFieldTemplates(dynCode);
115 
116  // compile filtered C template
117  dynCode.addCompileFile(codeTemplateC);
118 
119  // copy filtered H template
120  dynCode.addCopyFile(codeTemplateH);
121 
122 
123  // debugging: make BC verbose
124  // dynCode.setFilterVariable("verbose", "true");
125  // Info<<"compile " << redirectType_ << " sha1: "
126  // << context.sha1() << endl;
127 
128  // define Make/options
129  dynCode.setMakeOptions
130  (
131  "EXE_INC = -g \\\n"
132  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
133  + context.options()
134  + "\n\nLIB_LIBS = \\\n"
135  + " -lOpenFOAM \\\n"
136  + " -lfiniteVolume \\\n"
137  + context.libs()
138  );
139 }
140 
141 
142 template<class Type>
144 const
145 {
146  // use system/codeDict or in-line
147  return
148  (
149  dict_.found("code")
150  ? dict_
151  : this->dict().subDict(redirectType_)
152  );
153 }
154 
155 
156 template<class Type>
158 {
159  return
160  "patch "
161  + this->patch().name()
162  + " on field "
163  + this->dimensionedInternalField().name();
164 }
165 
166 
167 template<class Type>
169 {
170  // remove instantiation of fvPatchField provided by library
171  redirectPatchFieldPtr_.clear();
172 }
173 
174 
175 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
176 
177 template<class Type>
179 (
180  const fvPatch& p,
182 )
183 :
185  codedBase(),
186  redirectPatchFieldPtr_()
187 {}
188 
189 
190 template<class Type>
192 (
193  const codedMixedFvPatchField<Type>& ptf,
194  const fvPatch& p,
196  const fvPatchFieldMapper& mapper
197 )
198 :
199  mixedFvPatchField<Type>(ptf, p, iF, mapper),
200  codedBase(),
201  dict_(ptf.dict_),
202  redirectType_(ptf.redirectType_),
203  redirectPatchFieldPtr_()
204 {}
205 
206 
207 template<class Type>
209 (
210  const fvPatch& p,
212  const dictionary& dict
213 )
214 :
216  codedBase(),
217  dict_(dict),
218  redirectType_(dict.lookup("redirectType")),
219  redirectPatchFieldPtr_()
220 {
221  updateLibrary(redirectType_);
222 }
223 
224 
225 template<class Type>
227 (
229 )
230 :
232  codedBase(),
233  dict_(ptf.dict_),
234  redirectType_(ptf.redirectType_),
235  redirectPatchFieldPtr_()
236 {}
237 
238 
239 template<class Type>
241 (
242  const codedMixedFvPatchField<Type>& ptf,
244 )
245 :
246  mixedFvPatchField<Type>(ptf, iF),
247  codedBase(),
248  dict_(ptf.dict_),
249  redirectType_(ptf.redirectType_),
250  redirectPatchFieldPtr_()
251 {}
252 
253 
254 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
255 
256 template<class Type>
259 {
260  if (!redirectPatchFieldPtr_.valid())
261  {
262  // Construct a patch
263  // Make sure to construct the patchfield with up-to-date value
264 
265  // Write the data from the mixed b.c.
266  OStringStream os;
268  IStringStream is(os.str());
269  // Construct dictionary from it.
270  dictionary dict(is);
271 
272  // Override the type to enforce the fvPatchField::New constructor
273  // to choose our type
274  dict.set("type", redirectType_);
275 
276  redirectPatchFieldPtr_.set
277  (
278  dynamic_cast<mixedFvPatchField<Type>*>
279  (
281  (
282  this->patch(),
283  this->dimensionedInternalField(),
284  dict
285  ).ptr()
286  )
287  );
288  }
289  return redirectPatchFieldPtr_();
290 }
291 
292 
293 template<class Type>
295 {
296  if (this->updated())
297  {
298  return;
299  }
300 
301  // Make sure library containing user-defined fvPatchField is up-to-date
302  updateLibrary(redirectType_);
303 
304  const mixedFvPatchField<Type>& fvp = redirectPatchField();
305 
306  const_cast<mixedFvPatchField<Type>&>(fvp).updateCoeffs();
307 
308  // Copy through coefficients
309  this->refValue() = fvp.refValue();
310  this->refGrad() = fvp.refGrad();
311  this->valueFraction() = fvp.valueFraction();
312 
314 }
315 
316 
317 template<class Type>
319 (
320  const Pstream::commsTypes commsType
321 )
322 {
323  // Make sure library containing user-defined fvPatchField is up-to-date
324  updateLibrary(redirectType_);
325 
326  const mixedFvPatchField<Type>& fvp = redirectPatchField();
327 
328  // - updates the value of fvp (though not used)
329  // - resets the updated() flag
330  const_cast<mixedFvPatchField<Type>&>(fvp).evaluate(commsType);
331 
332  // Update the value (using the coefficients) locally
334 }
335 
336 
337 template<class Type>
339 {
341  os.writeKeyword("redirectType") << redirectType_
342  << token::END_STATEMENT << nl;
343 
344  if (dict_.found("codeInclude"))
345  {
346  os.writeKeyword("codeInclude")
347  << token::HASH << token::BEGIN_BLOCK;
348 
349  os.writeQuoted(string(dict_["codeInclude"]), false)
350  << token::HASH << token::END_BLOCK
351  << token::END_STATEMENT << nl;
352  }
353 
354  if (dict_.found("localCode"))
355  {
356  os.writeKeyword("localCode")
357  << token::HASH << token::BEGIN_BLOCK;
358 
359  os.writeQuoted(string(dict_["localCode"]), false)
360  << token::HASH << token::END_BLOCK
361  << token::END_STATEMENT << nl;
362  }
363 
364  if (dict_.found("code"))
365  {
366  os.writeKeyword("code")
367  << token::HASH << token::BEGIN_BLOCK;
368 
369  os.writeQuoted(string(dict_["code"]), false)
370  << token::HASH << token::END_BLOCK
371  << token::END_STATEMENT << nl;
372  }
373 
374  if (dict_.found("codeOptions"))
375  {
376  os.writeKeyword("codeOptions")
377  << token::HASH << token::BEGIN_BLOCK;
378 
379  os.writeQuoted(string(dict_["codeOptions"]), false)
380  << token::HASH << token::END_BLOCK
381  << token::END_STATEMENT << nl;
382  }
383 
384  if (dict_.found("codeLibs"))
385  {
386  os.writeKeyword("codeLibs")
387  << token::HASH << token::BEGIN_BLOCK;
388 
389  os.writeQuoted(string(dict_["codeLibs"]), false)
390  << token::HASH << token::END_BLOCK
391  << token::END_STATEMENT << nl;
392  }
393 }
394 
395 
396 // ************************************************************************* //
Foam::dynamicCodeContext::libs
const string & libs() const
Return the code-libs.
Definition: dynamicCodeContext.H:102
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
Foam::codedMixedFvPatchField::codeDict
virtual const dictionary & codeDict() const
Definition: codedMixedFvPatchField.C:143
volFields.H
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::mixedFvPatchField::valueFraction
virtual scalarField & valueFraction()
Definition: mixedFvPatchField.H:244
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::mixedFvPatchField::refValue
virtual Field< Type > & refValue()
Definition: mixedFvPatchField.H:224
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
Foam::codedMixedFvPatchField::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: codedMixedFvPatchField.C:104
Foam::mixedFvPatchField::refGrad
virtual Field< Type > & refGrad()
Definition: mixedFvPatchField.H:234
Foam::codedMixedFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: codedMixedFvPatchField.C:294
fvPatchFieldMapper.H
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
dynamicCodeContext.H
Foam::dynamicCode::addCopyFile
void addCopyFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:355
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::codedMixedFvPatchField::redirectType_
const word redirectType_
Definition: codedMixedFvPatchField.H:124
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::codedMixedFvPatchField::libs
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: codedMixedFvPatchField.C:96
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Foam::codedMixedFvPatchField::description
virtual string description() const
Definition: codedMixedFvPatchField.C:157
dynamicCode.H
Foam::codedMixedFvPatchField::redirectPatchField
const mixedFvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patchField.
Definition: codedMixedFvPatchField.C:258
Foam::codedMixedFvPatchField::codedMixedFvPatchField
codedMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: codedMixedFvPatchField.C:179
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::codedMixedFvPatchField::clearRedirect
virtual void clearRedirect() const
Definition: codedMixedFvPatchField.C:168
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::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam::codedMixedFvPatchField::dict_
dictionary dict_
Dictionary contents for the boundary condition.
Definition: codedMixedFvPatchField.H:122
Foam::mixedFvPatchField
This boundary condition provides a base class for 'mixed' type boundary conditions,...
Definition: mixedFvPatchField.H:126
Foam::dynamicCode::setFilterVariable
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
Definition: dynamicCode.C:384
Foam::codedMixedFvPatchField::setFieldTemplates
static void setFieldTemplates(dynamicCode &dynCode)
Set the rewrite vars controlling the Type.
Definition: codedMixedFvPatchField.C:49
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::codedMixedFvPatchField::dict
const IOdictionary & dict() const
Definition: codedMixedFvPatchField.C:67
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::codedMixedFvPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::blocking)
Evaluate the patch field.
Definition: codedMixedFvPatchField.C:319
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:45
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
codedMixedFvPatchField.H
Foam::codedMixedFvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: codedMixedFvPatchField.C:338
stringOps.H
Foam::system
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1155
Foam::codedMixedFvPatchField
Constructs on-the-fly a new boundary condition (derived from mixedFvPatchField) which is then used to...
Definition: codedMixedFvPatchField.H:114
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