uniformFixedValuePointPatchField.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2024 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 
30 #include "SubField.H"
31 #include "polyPatch.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
34 
35 // Alternative
36 // refCast<const facePointPatch>(p).patch()
37 
38 template<class Type>
39 const Foam::polyPatch*
41 {
42  const polyMesh& mesh = p.boundaryMesh().mesh()();
43  label patchi = mesh.boundaryMesh().findPatchID(p.name());
44 
45  if (patchi == -1)
46  {
47  return nullptr;
48  }
49  else
50  {
51  return &mesh.boundaryMesh()[patchi];
52  }
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
57 
58 template<class Type>
61 (
62  const pointPatch& p,
64 )
65 :
66  fixedValuePointPatchField<Type>(p, iF),
67  refValueFunc_(nullptr),
68  refPointValueFunc_(nullptr)
69 {}
70 
71 
72 template<class Type>
75 (
76  const pointPatch& p,
78  const dictionary& dict
79 )
80 :
81  fixedValuePointPatchField<Type>(p, iF, dict, IOobjectOption::NO_READ),
82  refValueFunc_
83  (
84  this->getPatch(p)
85  ? PatchFunction1<Type>::New
86  (
87  *(this->getPatch(p)),
88  "uniformValue",
89  dict,
90  false // generate point values
91  )
92  : nullptr
93  ),
94  refPointValueFunc_
95  (
96  this->getPatch(p)
97  ? nullptr
98  : Function1<Type>::New
99  (
100  "uniformValue",
101  dict,
102  &this->internalField().db()
103  )
104  )
105 {
106  if (!this->readValueEntry(dict))
107  {
108  // Ensure field has reasonable initial values
109  this->extrapolateInternal();
110 
111  // Evaluate to assign a value
112  this->evaluate();
113  }
114 }
115 
116 
117 template<class Type>
120 (
121  const uniformFixedValuePointPatchField<Type>& ptf,
122  const pointPatch& p,
123  const DimensionedField<Type, pointMesh>& iF,
124  const pointPatchFieldMapper& mapper
125 )
126 :
127  fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
128  refValueFunc_(ptf.refValueFunc_.clone(*(this->getPatch(p)))),
129  refPointValueFunc_(ptf.refPointValueFunc_.clone())
130 {
131  if (mapper.direct() && !mapper.hasUnmapped())
132  {
133  // Use mapping instead of re-evaluation
134  this->map(ptf, mapper);
135  }
136  else
137  {
138  // Evaluate since value not mapped
139  this->evaluate();
140  }
141 }
142 
143 
144 template<class Type>
147 (
148  const uniformFixedValuePointPatchField<Type>& ptf
149 )
150 :
151  fixedValuePointPatchField<Type>(ptf),
152  refValueFunc_(ptf.refValueFunc_.clone(*(this->getPatch(this->patch())))),
153  refPointValueFunc_(ptf.refPointValueFunc_.clone())
154 {}
155 
156 
157 template<class Type>
160 (
163 )
164 :
165  fixedValuePointPatchField<Type>(ptf, iF),
166  refValueFunc_(ptf.refValueFunc_.clone(*(this->getPatch(this->patch())))),
167  refPointValueFunc_(ptf.refPointValueFunc_.clone())
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
173 template<class Type>
175 (
176  const pointPatchFieldMapper& mapper
177 )
178 {
180 
181  if (refValueFunc_)
182  {
183  refValueFunc_().autoMap(mapper);
184 
185  if (refValueFunc_().constant())
186  {
187  // If mapper is not dependent on time we're ok to evaluate
188  this->evaluate();
189  }
190  }
191  if (refPointValueFunc_)
192  {
193  if (refPointValueFunc_().constant())
194  {
195  // If mapper is not dependent on time we're ok to evaluate
196  this->evaluate();
197  }
198  }
199 }
200 
201 
202 template<class Type>
204 (
205  const pointPatchField<Type>& ptf,
206  const labelList& addr
207 )
208 {
210 
211  const uniformFixedValuePointPatchField& tiptf =
212  refCast<const uniformFixedValuePointPatchField>(ptf);
213 
214  if (refValueFunc_ && tiptf.refValueFunc_)
215  {
216  refValueFunc_().rmap(tiptf.refValueFunc_(), addr);
217  }
218 }
219 
220 
221 template<class Type>
223 {
224  if (this->updated())
225  {
226  return;
227  }
228  const scalar t = this->db().time().timeOutputValue();
229 
230  if (refValueFunc_)
231  {
232  valuePointPatchField<Type>::operator=(refValueFunc_->value(t));
233  }
234  else
235  {
236  valuePointPatchField<Type>::operator=(refPointValueFunc_->value(t));
237  }
239 }
240 
241 
242 template<class Type>
244 write(Ostream& os) const
245 {
246  // Note: write value
248  if (refValueFunc_)
249  {
250  refValueFunc_->writeData(os);
251  }
252  if (refPointValueFunc_)
253  {
254  refPointValueFunc_->writeData(os);
255  }
256 }
257 
258 
259 // ************************************************************************* //
void extrapolateInternal()
Assign the patch field from the internal field.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A FixedValue boundary condition for pointField.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field.
Foam::pointPatchFieldMapper.
virtual void operator=(const valuePointPatchField< Type > &)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void write(Ostream &) const
Write.
dynamicFvMesh & mesh
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:302
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
OBJstream os(runTime.globalPath()/outputName)
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
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.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:64
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const std::string patch
OpenFOAM patch number as a std::string.
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
List< label > labelList
A List of labels.
Definition: List.H:61
volScalarField & p
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
Enables the specification of a uniform fixed value condition.
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given PointPatchField onto.
uniformFixedValuePointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.