codedMixedFvPatchField.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 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::codedMixedFvPatchField
29 
30 Group
31  grpGenericBoundaryConditions
32 
33 Description
34  Constructs on-the-fly a new boundary condition (derived from
35  mixedFvPatchField) which is then used to evaluate.
36 
37 Usage
38  Example:
39  \verbatim
40  <patchName>
41  {
42  type codedMixed;
43 
44  refValue uniform (0 0 0);
45  refGradient uniform (0 0 0);
46  valueFraction uniform 1;
47 
48  name rampedMixed; // name of generated BC
49 
50  code
51  #{
52  this->refValue() =
53  vector(1, 0, 0)
54  *min(10, 0.1*this->db().time().value());
55  this->refGrad() = Zero;
56  this->valueFraction() = 1.0;
57  #};
58 
59  //codeInclude
60  //#{
61  // #include "fvCFD.H"
62  //#};
63 
64  //codeOptions
65  //#{
66  // -I$(LIB_SRC)/finiteVolume/lnInclude
67  //#};
68  }
69  \endverbatim
70 
71  A special form is if the 'code' section is not supplied. In this case
72  the code gets read from a (runTimeModifiable!) dictionary system/codeDict
73  which would have a corresponding entry
74 
75  \verbatim
76  <patchName>
77  {
78  code
79  #{
80  this->refValue() = min(10, 0.1*this->db().time().value());
81  this->refGrad() = Zero;
82  this->valueFraction() = 1.0;
83  #};
84  }
85  \endverbatim
86 
87 See also
88  Foam::dynamicCode
89  Foam::functionEntries::codeStream
90 
91 SourceFiles
92  codedMixedFvPatchField.C
93 
94 \*---------------------------------------------------------------------------*/
95 
96 #ifndef codedMixedFvPatchField_H
97 #define codedMixedFvPatchField_H
98 
99 #include "mixedFvPatchFields.H"
100 #include "codedBase.H"
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 namespace Foam
105 {
106 
107 // Forward Declarations
108 class dynamicCode;
109 class dynamicCodeContext;
110 class IOdictionary;
111 
112 /*---------------------------------------------------------------------------*\
113  Class codedMixedFvPatchField Declaration
114 \*---------------------------------------------------------------------------*/
115 
116 template<class Type>
118 :
119  public mixedFvPatchField<Type>,
120  public codedBase
121 {
122  // Private Data
123 
124  //- Dictionary contents for the boundary condition
125  mutable dictionary dict_;
126 
127  const word name_;
128 
129  mutable autoPtr<mixedFvPatchField<Type>> redirectPatchFieldPtr_;
130 
131 
132  // Private Member Functions
133 
134  const IOdictionary& dict() const;
135 
136 
137 protected:
138 
139  // Protected Member Functions
140 
141  //- Mutable access to the loaded dynamic libraries
142  virtual dlLibraryTable& libs() const;
143 
144  //- Adapt the context for the current object
145  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
146 
147  // Return a description (type + name) for the output
148  virtual string description() const;
149 
150  // Clear the ptr to the redirected object
151  virtual void clearRedirect() const;
152 
153  // Get the dictionary to initialize the codeContext
154  virtual const dictionary& codeDict() const;
155 
156 
157 public:
158 
159  // Static Data Members
160 
161  //- Name of the C code template to be used
162  static constexpr const char* const codeTemplateC
163  = "mixedFvPatchFieldTemplate.C";
164 
165  //- Name of the H code template to be used
166  static constexpr const char* const codeTemplateH
167  = "mixedFvPatchFieldTemplate.H";
168 
169 
170  //- Runtime type information
171  TypeName("codedMixed");
172 
173 
174  // Constructors
175 
176  //- Construct from patch and internal field
178  (
179  const fvPatch&,
181  );
182 
183  //- Construct from patch, internal field and dictionary
185  (
186  const fvPatch&,
188  const dictionary&
189  );
190 
191  //- Construct by mapping given codedMixedFvPatchField
192  // onto a new patch
194  (
196  const fvPatch&,
198  const fvPatchFieldMapper&
199  );
200 
201  //- Construct as copy
203  (
205  );
206 
207  //- Construct and return a clone
208  virtual tmp<fvPatchField<Type>> clone() const
209  {
210  return tmp<fvPatchField<Type>>
211  (
213  );
214  }
215 
216  //- Construct as copy setting internal field reference
218  (
221  );
222 
223  //- Construct and return a clone setting internal field reference
225  (
227  ) const
228  {
229  return tmp<fvPatchField<Type>>
230  (
231  new codedMixedFvPatchField<Type>(*this, iF)
232  );
233  }
234 
235 
236  // Member functions
237 
238  //- Get reference to the underlying patchField
240 
241  //- Update the coefficients associated with the patch field
242  virtual void updateCoeffs();
243 
244  //- Evaluate the patch field
245  // This is only needed to set the updated() flag of the name
246  // to false.
247  virtual void evaluate
248  (
250  );
251 
252  //- Write
253  virtual void write(Ostream&) const;
254 };
255 
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 } // End namespace Foam
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #ifdef NoRepository
264  #include "codedMixedFvPatchField.C"
265 #endif
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #endif
270 
271 // ************************************************************************* //
Foam::codedMixedFvPatchField::codeDict
virtual const dictionary & codeDict() const
Definition: codedMixedFvPatchField.C:112
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::UPstream::commsTypes::blocking
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:59
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:53
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::codedMixedFvPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: codedMixedFvPatchField.C:263
Foam::codedMixedFvPatchField::TypeName
TypeName("codedMixed")
Runtime type information.
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
Foam::codedMixedFvPatchField::redirectPatchField
const mixedFvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patchField.
Definition: codedMixedFvPatchField.C:227
codedMixedFvPatchField.C
Foam::codedMixedFvPatchField::codedMixedFvPatchField
codedMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: codedMixedFvPatchField.C:148
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
Foam::codedMixedFvPatchField::clone
virtual tmp< fvPatchField< Type > > clone() const
Construct and return a clone.
Definition: codedMixedFvPatchField.H:207
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::mixedFvPatchField
This boundary condition provides a base class for 'mixed' type boundary conditions,...
Definition: mixedFvPatchField.H:123
mixedFvPatchFields.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::codedMixedFvPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
Definition: codedMixedFvPatchField.C:288
Foam::codedMixedFvPatchField::codeTemplateH
static constexpr const char *const codeTemplateH
Name of the H code template to be used.
Definition: codedMixedFvPatchField.H:166
codedBase.H
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
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::codedMixedFvPatchField::codeTemplateC
static constexpr const char *const codeTemplateC
Name of the C code template to be used.
Definition: codedMixedFvPatchField.H:162
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54