pointPatchField.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) 2020-2025 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 
29 #include "pointPatchField.H"
30 #include "pointMesh.H"
31 #include "dictionary.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
38  const pointPatch& p,
40 )
41 :
43  internalField_(iF)
44 {}
45 
46 
47 template<class Type>
49 (
50  const pointPatch& p,
52  const dictionary& dict
53 )
54 :
56  internalField_(iF)
57 {}
58 
59 
60 template<class Type>
62 (
63  const pointPatchField<Type>& ptf,
64  const pointPatch& p,
67 )
68 :
70  internalField_(iF)
71 {}
72 
73 
74 template<class Type>
76 (
77  const pointPatchField<Type>& ptf
78 )
79 :
81  internalField_(ptf.internalField_)
82 {}
83 
84 
85 template<class Type>
87 (
88  const pointPatchField<Type>& ptf,
90 )
91 :
93  internalField_(iF)
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
99 template<class Type>
101 {
102  os.writeEntry("type", type());
103 
104  if (!patchType().empty())
105  {
106  os.writeEntry("patchType", patchType());
107  }
108 }
109 
110 
111 template<class Type>
112 template<class Type1>
114 (
115  const UList<Type1>& internalData,
116  const labelUList& addressing,
117  UList<Type1>& pfld
118 ) const
119 {
120  if (FOAM_UNLIKELY(internalData.size() != primitiveField().size()))
121  {
123  << "Internal field size: " << internalData.size()
124  << " != mesh size: " << primitiveField().size() << nl
125  << abort(FatalError);
126  }
127 
128  // For v2412 and earlier this was a field:
129  // const label len = this->size();
130  // pfld.resize_nocopy(len);
131  //
132  // Now uses pre-sized storage
133 
134  const label len = pfld.size();
135 
136  #ifdef FULLDEBUG
137  if (FOAM_UNLIKELY((addressing.size() < len) || (this->size() < len)))
138  {
140  << "patchField size = " << len
141  << " but patch size = " << this->size()
142  << " and addressing size = " << addressing.size() << nl
143  << abort(FatalError);
144  }
145  #endif
146 
147  for (label i = 0; i < len; ++i)
148  {
149  pfld[i] = internalData[addressing[i]];
150  }
151 }
152 
153 
154 template<class Type>
155 template<class Type1>
158 (
159  const UList<Type1>& internalData,
160  const labelUList& addressing
161 ) const
162 {
163  auto tpfld = tmp<Field<Type1>>::New(this->size());
164  this->patchInternalField(internalData, addressing, tpfld.ref());
165  return tpfld;
166 }
167 
168 
169 template<class Type>
170 template<class Type1>
173 (
174  const UList<Type1>& internalData
175 ) const
176 {
177  auto tpfld = tmp<Field<Type1>>::New(this->size());
178  this->patchInternalField(internalData, patch().meshPoints(), tpfld.ref());
179  return tpfld;
180 }
181 
182 
183 template<class Type>
186 {
187  return patchInternalField(primitiveField());
188 }
189 
190 
191 template<class Type>
192 template<class Type1>
194 (
195  Field<Type1>& iF,
196  const Field<Type1>& pF
197 ) const
198 {
199  if (FOAM_UNLIKELY(iF.size() != primitiveField().size()))
200  {
202  << "Internal field size: " << iF.size()
203  << " != mesh size: " << primitiveField().size() << nl
204  << abort(FatalError);
205  }
206 
207  if (FOAM_UNLIKELY(pF.size() != size()))
208  {
210  << "Patch field size: " << pF.size()
211  << " != patch size: " << size() << nl
212  << abort(FatalError);
213  }
214 
215  // Get the addressing
216  const labelList& mp = patch().meshPoints();
217 
218  forAll(mp, pointi)
219  {
220  iF[mp[pointi]] += pF[pointi];
221  }
222 }
223 
224 
225 template<class Type>
226 template<class Type1>
228 (
229  Field<Type1>& iF,
230  const Field<Type1>& pF,
231  const labelUList& points
232 ) const
233 {
234  if (FOAM_UNLIKELY(iF.size() != primitiveField().size()))
235  {
237  << "Internal field size: " << iF.size()
238  << " != mesh size: " << primitiveField().size() << nl
239  << abort(FatalError);
240  }
241 
242  if (FOAM_UNLIKELY(pF.size() != size()))
243  {
245  << "Patch field size: " << pF.size()
246  << " != patch size: " << size() << nl
247  << abort(FatalError);
248  }
249 
250  // Get the addressing
251  const labelList& mp = patch().meshPoints();
252 
253  forAll(points, i)
254  {
255  label pointi = points[i];
256  iF[mp[pointi]] += pF[pointi];
257  }
258 }
259 
260 
261 template<class Type>
262 template<class Type1>
264 (
265  Field<Type1>& iF,
266  const Field<Type1>& pF,
267  const labelUList& meshPoints
268 ) const
269 {
270  if (FOAM_UNLIKELY(iF.size() != primitiveField().size()))
271  {
273  << "Internal field size: " << iF.size()
274  << " != mesh size: " << primitiveField().size() << nl
275  << abort(FatalError);
276  }
277 
278  if (FOAM_UNLIKELY(pF.size() != meshPoints.size()))
279  {
281  << "Patch field size: " << pF.size()
282  << " != meshPoints size: " << meshPoints.size() << nl
283  << abort(FatalError);
284  }
285 
286  forAll(meshPoints, pointi)
287  {
288  iF[meshPoints[pointi]] = pF[pointi];
289  }
290 }
291 
292 
293 template<class Type>
294 template<class Type1>
296 (
297  Field<Type1>& iF,
298  const Field<Type1>& pF
299 ) const
300 {
301  setInInternalField(iF, pF, patch().meshPoints());
302 }
303 
304 
305 template<class Type>
307 {
308  pointPatchFieldBase::setUpdated(true);
309 }
310 
311 
312 template<class Type>
314 {
315  if (!updated())
316  {
317  updateCoeffs();
318  }
319 
320  pointPatchFieldBase::setUpdated(false);
321  pointPatchFieldBase::setManipulated(false);
322 }
323 
324 
325 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
326 
327 template<class Type>
328 Foam::Ostream& Foam::operator<<
329 (
330  Ostream& os,
331  const pointPatchField<Type>& ptf
332 )
333 {
334  ptf.write(os);
335 
336  os.check(FUNCTION_NAME);
337 
338  return os;
339 }
340 
341 
342 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Template invariant parts for pointPatchField.
type
Types of root.
Definition: Roots.H:52
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
commsTypes
Communications types.
Definition: UPstream.H:77
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Foam::pointPatchFieldMapper.
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 write(Ostream &os) const
Write.
UList< label > labelUList
A UList of labels.
Definition: UList.H:76
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
Abstract base class for point-mesh patch fields.
const pointField & points
Generic templated field type.
Definition: Field.H:63
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
#define FOAM_UNLIKELY(cond)
Definition: stdFoam.H:64
errorManip< error > abort(error &err)
Definition: errorManip.H:139
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelUList &meshPoints) const
Given the internal field and a patch field, set the patch field in the internal field.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field, sets updated() to false.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:64
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field, add the patch field to the internal field.
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.
List< label > labelList
A List of labels.
Definition: List.H:61
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
const dimensionedScalar mp
Proton mass.