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-2021 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 #include "dictionaryContent.H"
35 
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 
38 template<class Type>
40 {
41  return this->db().time().libs();
42 }
43 
44 
45 template<class Type>
47 {
48  return
49  "patch "
50  + this->patch().name()
51  + " on field "
52  + this->internalField().name();
53 }
54 
55 
56 template<class Type>
58 {
59  redirectPatchFieldPtr_.reset(nullptr);
60 }
61 
62 
63 template<class Type>
64 const Foam::dictionary&
66 {
67  const dictionary* ptr = dict_.findDict("codeContext", keyType::LITERAL);
68  return (ptr ? *ptr : dictionary::null);
69 }
70 
71 
72 template<class Type>
73 const Foam::dictionary&
75 {
76  // Inline "code" or from system/codeDict
77  return
78  (
79  dict_.found("code")
80  ? dict_
81  : codedBase::codeDict(this->db()).subDict(name_)
82  );
83 }
84 
85 
86 template<class Type>
88 (
89  dynamicCode& dynCode,
90  const dynamicCodeContext& context
91 ) const
92 {
93  // Take no chances - typeName must be identical to name_
94  dynCode.setFilterVariable("typeName", name_);
95 
96  // Set TemplateType and FieldType filter variables
97  dynCode.setFieldTemplates<Type>();
98 
99  // Compile filtered C template
100  dynCode.addCompileFile(codeTemplateC);
101 
102  // Copy filtered H template
103  dynCode.addCopyFile(codeTemplateH);
104 
105  #ifdef FULLDEBUG
106  dynCode.setFilterVariable("verbose", "true");
107  DetailInfo
108  <<"compile " << name_ << " sha1: " << context.sha1() << endl;
109  #endif
110 
111  // Define Make/options
112  dynCode.setMakeOptions
113  (
114  "EXE_INC = -g \\\n"
115  "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
116  "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
117  + context.options()
118  + "\n\nLIB_LIBS = \\\n"
119  " -lOpenFOAM \\\n"
120  " -lfiniteVolume \\\n"
121  " -lmeshTools \\\n"
122  + context.libs()
123  );
124 }
125 
126 
127 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 
129 template<class Type>
131 (
132  const pointPatch& p,
134 )
135 :
136  parent_bctype(p, iF),
138  redirectPatchFieldPtr_(nullptr)
139 {}
140 
141 
142 template<class Type>
144 (
146  const pointPatch& p,
148  const pointPatchFieldMapper& mapper
149 )
150 :
151  parent_bctype(rhs, p, iF, mapper),
152  codedBase(),
153  dict_(rhs.dict_), // Deep copy
154  name_(rhs.name_),
155  redirectPatchFieldPtr_(nullptr)
156 {}
157 
158 
159 template<class Type>
161 (
162  const pointPatch& p,
164  const dictionary& dict,
165  const bool valueRequired
166 )
167 :
168  parent_bctype(p, iF, dict, false),
169  codedBase(),
170  dict_
171  (
172  // Copy dictionary without "heavy" data chunks
173  dictionaryContent::copyDict
174  (
175  dict,
176  wordList(), // allow
177  wordList // deny
178  ({
179  "type", // redundant
180  "value"
181  })
182  )
183  ),
184  name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
185  redirectPatchFieldPtr_(nullptr)
186 {
187  updateLibrary(name_);
188 
189  // Note: 'value' is used even with valueRequired = false ! This is
190  // inconsistent with fixedValueFvPatchField behaviour.
191 
192  if (!dict.found("value")) // Q: check for valueRequired?
193  {
194  // Evaluate to assign a value
196  }
197 }
198 
199 
200 template<class Type>
202 (
203  const codedFixedValuePointPatchField<Type>& rhs
204 )
205 :
206  parent_bctype(rhs),
207  codedBase(),
208  dict_(rhs.dict_), // Deep copy
209  name_(rhs.name_),
210  redirectPatchFieldPtr_(nullptr)
211 {}
212 
213 
214 template<class Type>
216 (
219 )
220 :
221  parent_bctype(rhs, iF),
222  codedBase(),
223  dict_(rhs.dict_), // Deep copy
224  name_(rhs.name_),
225  redirectPatchFieldPtr_(nullptr)
226 {}
227 
228 
229 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
230 
231 template<class Type>
234 {
235  if (!redirectPatchFieldPtr_)
236  {
237  // Construct a patch
238  // Make sure to construct the patchfield with up-to-date value
239 
241  static_cast<const Field<Type>&>(*this).writeEntry("value", os);
242  IStringStream is(os.str());
243  dictionary constructDict(is);
244 
245  constructDict.set("type", name_);
246 
247  redirectPatchFieldPtr_.reset
248  (
250  (
251  this->patch(),
252  this->internalField(),
253  constructDict
254  ).ptr()
255  );
256 
257 
258  // Forward copy of codeContext to the code template
259  auto* contentPtr =
260  dynamic_cast<dictionaryContent*>(redirectPatchFieldPtr_.get());
261 
262  if (contentPtr)
263  {
264  contentPtr->dict(this->codeContext());
265  }
266  else
267  {
269  << name_ << " Did not derive from dictionaryContent"
270  << nl << nl;
271  }
272  }
273  return *redirectPatchFieldPtr_;
274 }
275 
276 
277 template<class Type>
279 {
280  if (this->updated())
281  {
282  return;
283  }
284 
285  // Make sure library containing user-defined pointPatchField is up-to-date
286  updateLibrary(name_);
287 
288  const pointPatchField<Type>& fvp = redirectPatchField();
289 
290  const_cast<pointPatchField<Type>&>(fvp).updateCoeffs();
291 
292  // Copy through value
293  this->operator==(fvp);
295  parent_bctype::updateCoeffs();
296 }
297 
298 
299 template<class Type>
301 (
302  const Pstream::commsTypes commsType
303 )
304 {
305  // Make sure library containing user-defined pointPatchField is up-to-date
306  updateLibrary(name_);
307 
308  const pointPatchField<Type>& fvp = redirectPatchField();
309 
310  const_cast<pointPatchField<Type>&>(fvp).evaluate(commsType);
311 
312  parent_bctype::evaluate(commsType);
313 }
314 
315 
316 template<class Type>
318 {
319  this->parent_bctype::write(os);
320  os.writeEntry("name", name_);
321 
323 }
324 
325 
326 // ************************************************************************* //
dictionary dict
"blocking" : (MPI_Bsend, MPI_Recv)
commsTypes
Types of communications.
Definition: UPstream.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
codedFixedValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
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:487
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:644
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:312
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.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:100
Abstract base class for point-mesh patch fields.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Constructs on-the-fly a new boundary condition (derived from fixedValuePointPatchField) which is then...
Generic templated field type.
Definition: Field.H:61
const dictionary & dict() const noexcept
Read-access to the content.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
virtual void write(Ostream &) const
Write.
Base class for function objects and boundary conditions using dynamic code that provides methods for ...
Definition: codedBase.H:62
#define DetailInfo
Definition: evalEntry.C:30
A table of dynamically loaded libraries.
A wrapper for dictionary content, without operators that could affect inheritance patterns...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
OBJstream os(runTime.globalPath()/outputName)
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T using any compatibility names if needed. FatalIOError if not found, or if there are excess tokens.
#define WarningInFunction
Report a warning using Foam::Warning.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:120
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...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
volScalarField & p
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
A class for handling character strings derived from std::string.
Definition: string.H:72
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:256
static void writeCodeDict(Ostream &os, const dictionary &dict)
Write code-dictionary contents.
Definition: codedBase.C:81