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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-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 
29 #include "codedMixedFvPatchField.H"
31 #include "fvPatchFieldMapper.H"
32 #include "volFields.H"
33 #include "dynamicCode.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 template<class Type>
39 {
40  const objectRegistry& obr = this->db();
41 
42  const IOdictionary* dictptr = obr.cfindObject<IOdictionary>("codeDict");
43  if (dictptr)
44  {
45  return *dictptr;
46  }
47 
48  return obr.store
49  (
50  new IOdictionary
51  (
52  IOobject
53  (
54  "codeDict",
55  this->db().time().system(),
56  this->db(),
57  IOobject::MUST_READ_IF_MODIFIED,
58  IOobject::NO_WRITE
59  )
60  )
61  );
62 }
63 
64 
65 template<class Type>
67 {
68  return this->db().time().libs();
69 }
70 
71 
72 template<class Type>
74 (
75  dynamicCode& dynCode,
76  const dynamicCodeContext& context
77 ) const
78 {
79  // Take no chances - typeName must be identical to name_
80  dynCode.setFilterVariable("typeName", name_);
81 
82  // Set TemplateType and FieldType filter variables
83  dynCode.setFieldTemplates<Type>();
84 
85  // Compile filtered C template
86  dynCode.addCompileFile(codeTemplateC);
87 
88  // Copy filtered H template
89  dynCode.addCopyFile(codeTemplateH);
90 
91  // Debugging: make verbose
92  // dynCode.setFilterVariable("verbose", "true");
93  // DetailInfo
94  // <<"compile " << name_ << " sha1: "
95  // << context.sha1() << endl;
96 
97  // Define Make/options
98  dynCode.setMakeOptions
99  (
100  "EXE_INC = -g \\\n"
101  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
102  + context.options()
103  + "\n\nLIB_LIBS = \\\n"
104  " -lOpenFOAM \\\n"
105  " -lfiniteVolume \\\n"
106  + context.libs()
107  );
108 }
109 
110 
111 template<class Type>
113 const
114 {
115  // use system/codeDict or in-line
116  return
117  (
118  dict_.found("code")
119  ? dict_
120  : this->dict().subDict(name_)
121  );
122 }
123 
124 
125 template<class Type>
127 {
128  return
129  "patch "
130  + this->patch().name()
131  + " on field "
132  + this->internalField().name();
133 }
134 
135 
136 template<class Type>
138 {
139  // remove instantiation of fvPatchField provided by library
140  redirectPatchFieldPtr_.clear();
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
145 
146 template<class Type>
148 (
149  const fvPatch& p,
151 )
152 :
154  codedBase(),
155  redirectPatchFieldPtr_()
156 {}
157 
158 
159 template<class Type>
161 (
162  const codedMixedFvPatchField<Type>& ptf,
163  const fvPatch& p,
165  const fvPatchFieldMapper& mapper
166 )
167 :
168  mixedFvPatchField<Type>(ptf, p, iF, mapper),
169  codedBase(),
170  dict_(ptf.dict_),
171  name_(ptf.name_),
172  redirectPatchFieldPtr_()
173 {}
174 
175 
176 template<class Type>
178 (
179  const fvPatch& p,
181  const dictionary& dict
182 )
183 :
185  codedBase(),
186  dict_(dict),
187  name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
188  redirectPatchFieldPtr_()
189 {
190  updateLibrary(name_);
191 }
192 
193 
194 template<class Type>
196 (
198 )
199 :
201  codedBase(),
202  dict_(ptf.dict_),
203  name_(ptf.name_),
204  redirectPatchFieldPtr_()
205 {}
206 
207 
208 template<class Type>
210 (
211  const codedMixedFvPatchField<Type>& ptf,
213 )
214 :
215  mixedFvPatchField<Type>(ptf, iF),
216  codedBase(),
217  dict_(ptf.dict_),
218  name_(ptf.name_),
219  redirectPatchFieldPtr_()
220 {}
221 
222 
223 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
224 
225 template<class Type>
228 {
229  if (!redirectPatchFieldPtr_)
230  {
231  // Construct a patch
232  // Make sure to construct the patchfield with up-to-date value
233 
234  // Write the data from the mixed b.c.
235  OStringStream os;
237  IStringStream is(os.str());
238  // Construct dictionary from it.
239  dictionary dict(is);
240 
241  // Override the type to enforce the fvPatchField::New constructor
242  // to choose our type
243  dict.set("type", name_);
244 
245  redirectPatchFieldPtr_.reset
246  (
247  dynamic_cast<mixedFvPatchField<Type>*>
248  (
250  (
251  this->patch(),
252  this->internalField(),
253  dict
254  ).ptr()
255  )
256  );
257  }
258  return *redirectPatchFieldPtr_;
259 }
260 
261 
262 template<class Type>
264 {
265  if (this->updated())
266  {
267  return;
268  }
269 
270  // Make sure library containing user-defined fvPatchField is up-to-date
271  updateLibrary(name_);
272 
273  const mixedFvPatchField<Type>& fvp = redirectPatchField();
274 
275  const_cast<mixedFvPatchField<Type>&>(fvp).updateCoeffs();
276 
277  // Copy through coefficients
278  this->refValue() = fvp.refValue();
279  this->refGrad() = fvp.refGrad();
280  this->valueFraction() = fvp.valueFraction();
281 
283 }
284 
285 
286 template<class Type>
288 (
289  const Pstream::commsTypes commsType
290 )
291 {
292  // Make sure library containing user-defined fvPatchField is up-to-date
293  updateLibrary(name_);
294 
295  const mixedFvPatchField<Type>& fvp = redirectPatchField();
296 
297  // - updates the value of fvp (though not used)
298  // - resets the updated() flag
299  const_cast<mixedFvPatchField<Type>&>(fvp).evaluate(commsType);
300 
301  // Update the value (using the coefficients) locally
303 }
304 
305 
306 template<class Type>
308 {
310  os.writeEntry("name", name_);
311 
312  codedBase::writeCodeDict(os, dict_);
313 }
314 
315 
316 // ************************************************************************* //
Foam::dynamicCodeContext::libs
const string & libs() const
Return the code-libs.
Definition: dynamicCodeContext.H:146
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
Foam::codedMixedFvPatchField::codeDict
virtual const dictionary & codeDict() const
Definition: codedMixedFvPatchField.C:112
volFields.H
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::mixedFvPatchField::valueFraction
virtual scalarField & valueFraction()
Definition: mixedFvPatchField.H:247
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::mixedFvPatchField::refValue
virtual Field< Type > & refValue()
Definition: mixedFvPatchField.H:227
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:59
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:53
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
Foam::codedMixedFvPatchField::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: codedMixedFvPatchField.C:74
Foam::mixedFvPatchField::refGrad
virtual Field< Type > & refGrad()
Definition: mixedFvPatchField.H:237
Foam::codedMixedFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: codedMixedFvPatchField.C:263
fvPatchFieldMapper.H
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
Foam::dynamicCode::addCopyFile
void addCopyFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:357
Foam::dynamicCode::addCompileFile
void addCompileFile(const fileName &name)
Add a file template name, which will be found and filtered.
Definition: dynamicCode.C:351
Foam::codedMixedFvPatchField::libs
virtual dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: codedMixedFvPatchField.C:66
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::codedMixedFvPatchField::description
virtual string description() const
Definition: codedMixedFvPatchField.C:126
dynamicCode.H
Foam::codedMixedFvPatchField::redirectPatchField
const mixedFvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patchField.
Definition: codedMixedFvPatchField.C:227
Foam::codedMixedFvPatchField::codedMixedFvPatchField
codedMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: codedMixedFvPatchField.C:148
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::codedMixedFvPatchField::clearRedirect
virtual void clearRedirect() const
Definition: codedMixedFvPatchField.C:137
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::dynamicCodeContext::options
const string & options() const
Return the code-options.
Definition: dynamicCodeContext.H:140
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam::mixedFvPatchField
This boundary condition provides a base class for 'mixed' type boundary conditions,...
Definition: mixedFvPatchField.H:123
Foam::dynamicCode::setFilterVariable
void setFilterVariable(const word &key, const std::string &value)
Define a filter variable.
Definition: dynamicCode.C:386
Foam::dlLibraryTable::libs
static dlLibraryTable & libs()
Table of global libraries.
Definition: dlLibraryTable.C:80
Foam::dynamicCode::setFieldTemplates
void setFieldTemplates()
Define a filter variables TemplateType and FieldType.
Definition: dynamicCode.H:286
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::dynamicCode::setMakeOptions
void setMakeOptions(const std::string &content)
Define contents for Make/options.
Definition: dynamicCode.C:395
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::codedMixedFvPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
Definition: codedMixedFvPatchField.C:288
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::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
codedMixedFvPatchField.H
Foam::codedMixedFvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: codedMixedFvPatchField.C:307
Foam::codedMixedFvPatchField
Constructs on-the-fly a new boundary condition (derived from mixedFvPatchField) which is then used to...
Definition: codedMixedFvPatchField.H:116
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