codedFixedValueFvPatchField.H
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-2017 OpenFOAM Foundation
9  Copyright (C) 2019-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 Class
28  Foam::codedFixedValueFvPatchField
29 
30 Group
31  grpGenericBoundaryConditions
32 
33 Description
34  Constructs on-the-fly a new boundary condition (derived from
35  fixedValueFvPatchField) which is then used to evaluate.
36 
37  The \c value entry (optional) is used for the initial values.
38  Otherwise the code is executed.
39 
40  The code entries:
41  \plaintable
42  codeInclude | include files
43  codeOptions | compiler line: added to EXE_INC (Make/options)
44  codeLibs | linker line: added to LIB_LIBS (Make/options)
45  localCode | c++; local static functions
46  code | c++; patch value assignment
47  codeContext | additional dictionary context for the code
48  \endplaintable
49 
50 Usage
51  Example:
52  \verbatim
53  <patchName>
54  {
55  type codedFixedValue;
56  value uniform 0;
57  name rampedFixedValue; // name of generated BC
58 
59  codeContext
60  {
61  ...
62  }
63 
64  code
65  #{
66  operator==(min(10, 0.1*this->db().time().value()));
67  #};
68 
69  //codeInclude
70  //#{
71  // #include "fvCFD.H"
72  //#};
73 
74  //codeOptions
75  //#{
76  // -I$(LIB_SRC)/finiteVolume/lnInclude
77  //#};
78  }
79  \endverbatim
80 
81  A special form is if the 'code' section is not supplied. In this case
82  the code is read from a (runTimeModifiable!) dictionary system/codeDict
83  which would have a corresponding entry:
84 
85  \verbatim
86  <patchName>
87  {
88  code
89  #{
90  operator==(min(10, 0.1*this->db().time().value()));
91  #};
92  }
93  \endverbatim
94 
95 Note
96  The code context dictionary can be supplied separately as the
97  \c codeContext entry.
98 
99 See also
100  Foam::dynamicCode
101  Foam::functionEntries::codeStream
102 
103 SourceFiles
104  codedFixedValueFvPatchField.C
105 
106 \*---------------------------------------------------------------------------*/
107 
108 #ifndef Foam_codedFixedValueFvPatchField_H
109 #define Foam_codedFixedValueFvPatchField_H
110 
111 #include "fixedValueFvPatchFields.H"
112 #include "codedBase.H"
113 
114 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115 
116 namespace Foam
117 {
118 
119 /*---------------------------------------------------------------------------*\
120  Class codedFixedValueFvPatchField Declaration
121 \*---------------------------------------------------------------------------*/
122 
123 template<class Type>
124 class codedFixedValueFvPatchField
125 :
126  public fixedValueFvPatchField<Type>,
127  protected codedBase
128 {
129  //- The parent boundary condition type
130  typedef fixedValueFvPatchField<Type> parent_bctype;
131 
132 
133  // Private Data
134 
135  //- Dictionary contents for the boundary condition
136  dictionary dict_;
137 
138  const word name_;
139 
140  mutable autoPtr<fvPatchField<Type>> redirectPatchFieldPtr_;
141 
142 
143  // Private Member Functions
144 
145  //- Mutable access to the loaded dynamic libraries
146  virtual dlLibraryTable& libs() const;
147 
148  //- Description (type + name) for the output
149  virtual string description() const;
150 
151  //- Clear redirected object(s)
152  virtual void clearRedirect() const;
153 
154  //- Additional 'codeContext' dictionary to pass through
155  virtual const dictionary& codeContext() const;
156 
157  //- The code dictionary. Inline "code" or from system/codeDict
158  virtual const dictionary& codeDict() const;
159 
160  //- Adapt the context for the current object
161  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
162 
163 
164 public:
165 
166  // Static data members
167 
168  //- Name of the C code template to be used
169  static constexpr const char* const codeTemplateC
170  = "fixedValueFvPatchFieldTemplate.C";
171 
172  //- Name of the H code template to be used
173  static constexpr const char* const codeTemplateH
174  = "fixedValueFvPatchFieldTemplate.H";
175 
176 
177  //- Runtime type information
178  TypeName("codedFixedValue");
179 
180 
181  // Constructors
182 
183  //- Construct from patch and internal field
185  (
186  const fvPatch&,
188  );
189 
190  //- Construct from patch, internal field and dictionary
192  (
193  const fvPatch&,
195  const dictionary&
196  );
197 
198  //- Construct by mapping given codedFixedValueFvPatchField
199  // onto a new patch
201  (
203  const fvPatch&,
205  const fvPatchFieldMapper&
206  );
208  //- Construct as copy
210  (
212  );
214  //- Construct and return a clone
215  virtual tmp<fvPatchField<Type>> clone() const
216  {
217  return tmp<fvPatchField<Type>>
218  (
220  );
221  }
222 
223  //- Construct as copy setting internal field reference
225  (
228  );
229 
230  //- Construct and return a clone setting internal field reference
232  (
234  ) const
235  {
236  return tmp<fvPatchField<Type>>
237  (
238  new codedFixedValueFvPatchField<Type>(*this, iF)
239  );
240  }
241 
242 
243  // Member functions
244 
245  //- Get reference to the underlying patch
246  const fvPatchField<Type>& redirectPatchField() const;
247 
248  //- Update the coefficients associated with the patch field
249  virtual void updateCoeffs();
250 
251  //- Evaluate the patch field, sets updated() to false
252  virtual void evaluate
253  (
255  );
256 
257  //- Write
258  virtual void write(Ostream&) const;
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 #ifdef NoRepository
270 #endif
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 #endif
275 
276 // ************************************************************************* //
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
"blocking" : (MPI_Bsend, MPI_Recv)
TypeName("codedFixedValue")
Runtime type information.
commsTypes
Communications types.
Definition: UPstream.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
virtual tmp< fvPatchField< Type > > clone() const
Construct and return a clone.
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets updated() to false.
A FieldMapper for finite-volume patch fields.
A table of dynamically loaded libraries.
Constructs on-the-fly a new boundary condition (derived from fixedValueFvPatchField) which is then us...
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Encapsulation of dynamic code dictionaries.
codedFixedValueFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual void write(Ostream &) const
Write.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
Namespace for OpenFOAM.
const fvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patch.