codedMixedFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "codedMixedFvPatchField.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  {"code", "codeInclude", "localCode"}
35 );
36 
37 template<class Type>
39 (
40  {word::null, word::null, word::null}
41 );
42 
43 template<class Type>
45 (
46  "codedMixedFvPatchFieldOptions"
47 );
48 
49 template<class Type>
51 {
52  "codedMixedFvPatchFieldTemplate.C"
53 };
54 
55 template<class Type>
57 {
58  "codedMixedFvPatchFieldTemplate.H"
59 };
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
64 template<class Type>
66 (
67  const fvPatch& p,
69  const dictionary& dict
70 )
71 :
72  mixedFvPatchField<Type>(p, iF, dict),
73  codedBase
74  (
75  dict.lookupOrDefault<word>
76  (
77  "name",
78  (
79  iF.mesh().name() == polyMesh::defaultRegion
80  ? word::null
81  : word(iF.mesh().name() + '_')
82  )
83  + iF.name() + '_' + p.name()
84  ),
85  dict,
86  codeKeys,
87  codeDictVars,
88  codeOptions,
89  compileFiles,
90  copyFiles
91  )
92 {
93  const word fieldType(pTraits<Type>::typeName);
94 
95  // Set variable substitutions
96  varSubstitutions().set
97  (
98  {
99  {"TemplateType", fieldType},
100  {"FieldType", fieldType.capitalise() + "Field"},
101  {"verbose", Foam::name(bool(debug))}
102  }
103  );
104 
105  // Compile the library containing user-defined fvPatchField
107 }
108 
109 
110 template<class Type>
112 (
113  const codedMixedFvPatchField<Type>& ptf,
114  const fvPatch& p,
116  const fieldMapper& mapper
117 )
118 :
119  mixedFvPatchField<Type>(ptf, p, iF, mapper),
120  codedBase(ptf)
121 {}
122 
123 
124 template<class Type>
126 (
127  const codedMixedFvPatchField<Type>& ptf,
129 )
130 :
131  mixedFvPatchField<Type>(ptf, iF),
132  codedBase(ptf)
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
138 template<class Type>
141 {
142  if (!redirectPatchFieldPtr_.valid())
143  {
144  OStringStream os;
146  IStringStream is(os.str());
147  dictionary dict(is);
148 
149  // Override the type to enforce the fvPatchField::New constructor
150  // to choose our type
151  dict.set("type", codeName());
152 
153  redirectPatchFieldPtr_.set
154  (
155  dynamic_cast<mixedFvPatchField<Type>*>
156  (
158  (
159  this->patch(),
160  this->internalField(),
161  dict
162  ).ptr()
163  )
164  );
165  }
166 
167  return redirectPatchFieldPtr_();
168 }
169 
170 
171 template<class Type>
173 {
174  if (this->updated())
175  {
176  return;
177  }
178 
179  const mixedFvPatchField<Type>& fvp = redirectPatchField();
180 
181  const_cast<mixedFvPatchField<Type>&>(fvp).updateCoeffs();
182 
183  // Copy through coefficients
184  this->refValue() = fvp.refValue();
185  this->refGrad() = fvp.refGrad();
186  this->valueFraction() = fvp.valueFraction();
187 
189 }
190 
191 
192 template<class Type>
194 (
195  const Pstream::commsTypes commsType
196 )
197 {
198  const mixedFvPatchField<Type>& fvp = redirectPatchField();
199 
200  // - updates the value of fvp (though not used)
201  // - resets the updated() flag
202  const_cast<mixedFvPatchField<Type>&>(fvp).evaluate(commsType);
203 
204  // Update the value (using the coefficients) locally
206 }
207 
208 
209 template<class Type>
211 {
213  codedBase::write(os);
214 }
215 
216 
217 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Input from memory buffer stream.
Definition: IStringStream.H:52
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
commsTypes
Types of communications.
Definition: UPstream.H:65
Base class for coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:230
Mixed boundary condition evaluated from the code provided.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
codedMixedFvPatchField(const fvPatch &, const DimensionedField< Type, fvMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
virtual void write(Ostream &) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
const mixedFvPatchField< Type > & redirectPatchField() const
Get reference to the underlying patchField.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
HashTable< string > & varSubstitutions()
Definition: dynamicCode.H:252
void write(Ostream &os) const
Write the code for restart.
Definition: dynamicCode.C:744
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:90
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:208
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
This boundary condition provides a base class for 'mixed' type boundary conditions,...
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual void write(Ostream &) const
Write.
virtual Field< Type > & refValue()
virtual scalarField & valueFraction()
virtual Field< Type > & refGrad()
Traits class for primitives.
Definition: pTraits.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
A class for handling words, derived from string.
Definition: word.H:63
word capitalise() const
Return the word with the first letter capitalised.
Definition: wordI.H:131
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
void evaluate(GeometricField< Type, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, GeoMesh > &x)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict
volScalarField & p