valuePointPatchField.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-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2023 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 "pointPatchFieldMapper.H"
31 
32 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const dictionary& dict,
39 )
40 {
41  if (!IOobjectOption::isAnyRead(readOpt)) return false;
42  const auto& p = pointPatchFieldBase::patch();
43 
44 
45  const auto* eptr = dict.findEntry("value", keyType::LITERAL);
46 
47  if (eptr)
48  {
49  Field<Type>::assign(*eptr, p.size());
50  return true;
51  }
52 
53  if (IOobjectOption::isReadRequired(readOpt))
54  {
56  << "Required entry 'value' : missing for patch " << p.name()
57  << " in dictionary " << dict.relativeName() << nl
58  << exit(FatalIOError);
59  }
60 
61  return false;
62 }
63 
64 
65 template<class Type>
67 {
68  const labelUList& meshPoints = pointPatchFieldBase::patch().meshPoints();
69 
70  const Field<Type>& iF = this->primitiveField();
71  Field<Type>& pfld = *this;
72 
73  pfld.resize_nocopy(meshPoints.size()); // In general this is a no-op
74 
75  forAll(meshPoints, i)
76  {
77  pfld[i] = iF[meshPoints[i]];
78  }
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
83 
84 template<class Type>
86 (
87  const pointPatch& p,
89 )
90 :
91  pointPatchField<Type>(p, iF),
92  Field<Type>(p.size())
93 {}
94 
95 
96 template<class Type>
98 (
99  const pointPatch& p,
101  const Type& value
102 )
103 :
104  pointPatchField<Type>(p, iF),
105  Field<Type>(p.size(), value)
106 {}
107 
108 
109 template<class Type>
111 (
112  const pointPatch& p,
114  const dictionary& dict,
115  IOobjectOption::readOption requireValue
116 )
117 :
118  pointPatchField<Type>(p, iF, dict),
119  Field<Type>(p.size())
120 {
121  if (!readValueEntry(dict, requireValue))
122  {
123  // Not read (eg, optional and missing): define zero
125  }
126 }
127 
128 
129 template<class Type>
131 (
132  const valuePointPatchField<Type>& ptf,
133  const pointPatch& p,
134  const DimensionedField<Type, pointMesh>& iF,
135  const pointPatchFieldMapper& mapper
136 )
137 :
138  pointPatchField<Type>(ptf, p, iF, mapper),
139  Field<Type>(ptf, mapper)
140 {}
141 
142 
143 template<class Type>
145 (
146  const valuePointPatchField<Type>& ptf,
148 )
149 :
150  pointPatchField<Type>(ptf, iF),
151  Field<Type>(ptf)
152 {}
153 
154 
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
156 
157 template<class Type>
159 (
160  const pointPatchFieldMapper& m
161 )
162 {
164 }
165 
166 
167 template<class Type>
169 (
170  const pointPatchField<Type>& ptf,
171  const labelList& addr
172 )
173 {
175  (
177  (
178  ptf
179  ),
180  addr
181  );
182 }
183 
184 
185 template<class Type>
187 {
188  if (this->updated())
189  {
190  return;
191  }
192 
193  // Get internal field to insert values into
194  Field<Type>& iF = const_cast<Field<Type>&>(this->primitiveField());
195 
196  this->setInInternalField(iF, *this);
197 
199 }
200 
201 
202 template<class Type>
204 {
205  // Get internal field to insert values into
206  Field<Type>& iF = const_cast<Field<Type>&>(this->primitiveField());
207 
208  this->setInInternalField(iF, *this);
209 
211 }
212 
213 
214 template<class Type>
216 {
218  this->writeValueEntry(os);
219 }
220 
221 
222 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
223 
224 template<class Type>
226 (
227  const valuePointPatchField<Type>& ptf
228 )
229 {
231 }
232 
233 
234 template<class Type>
236 (
237  const pointPatchField<Type>& ptf
238 )
239 {
240  Field<Type>::operator=(this->patchInternalField());
241 }
242 
243 
244 template<class Type>
246 (
247  const Field<Type>& tf
248 )
249 {
251 }
252 
253 
254 template<class Type>
256 (
257  const Type& t
258 )
259 {
261 }
262 
263 
264 template<class Type>
266 (
267  const valuePointPatchField<Type>& ptf
268 )
269 {
271 }
272 
273 
274 template<class Type>
276 (
277  const pointPatchField<Type>& ptf
278 )
279 {
280  Field<Type>::operator=(this->patchInternalField());
281 }
282 
283 
284 template<class Type>
286 (
287  const Field<Type>& tf
288 )
289 {
291 }
292 
293 
294 template<class Type>
296 (
297  const Type& t
298 )
299 {
301 }
302 
303 
304 // ************************************************************************* //
void extrapolateInternal()
Assign the patch field from the internal field.
dictionary dict
Foam::valuePointPatchField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
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
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
Foam::pointPatchFieldMapper.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void write(Ostream &) const
Write.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Abstract base class for point-mesh patch fields.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
valuePointPatchField(const valuePointPatchField &)=default
Copy construct.
Generic templated field type.
Definition: Field.H:62
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.
virtual void autoMap(const pointPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void assign(Field< Tout > &result, const Field< T1 > &a, const UnaryOp &op)
Populate a field as the result of a unary operation on an input.
Definition: FieldOps.C:28
OBJstream os(runTime.globalPath()/outputName)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
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.
volScalarField & p
virtual void rmap(const pointPatchField< Type > &, const labelList &)
Reverse map the given PointPatchField onto.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
readOption
Enumeration defining read preferences.