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