pointPatchField.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 "pointPatchField.H"
27 #include "pointMesh.H"
28 #include "dictionary.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const pointPatch& p,
37 )
38 :
39  patch_(p),
40  internalField_(iF),
41  updated_(false)
42 {}
43 
44 
45 template<class Type>
47 (
48  const pointPatch& p,
50  const dictionary& dict
51 )
52 :
53  patch_(p),
54  internalField_(iF),
55  updated_(false)
56 {}
57 
58 
59 template<class Type>
61 (
62  const pointPatchField<Type>& ptf,
63  const pointPatch& p,
65  const fieldMapper&
66 )
67 :
68  patch_(p),
69  internalField_(iF),
70  updated_(false)
71 {}
72 
73 
74 template<class Type>
76 (
77  const pointPatchField<Type>& ptf,
79 )
80 :
81  patch_(ptf.patch_),
82  internalField_(iF),
83  updated_(false)
84 {}
85 
86 
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 
89 template<class Type>
91 {
92  return patch_.db();
93 }
94 
95 
96 template<class Type>
98 {
99  return patch_.time();
100 }
101 
102 
103 template<class Type>
105 {
106  writeEntry(os, "type", type());
107 
108  if (overridesConstraint())
109  {
110  writeEntry(os, "patchType", patch().type());
111  }
112 }
113 
114 
115 template<class Type>
118 {
119  return patchInternalField(primitiveField());
120 }
121 
122 
123 template<class Type>
124 template<class Type1>
127 (
128  const Field<Type1>& iF,
129  const labelList& meshPoints
130 ) const
131 {
132  // Check size
133  if (iF.size() != primitiveField().size())
134  {
136  << "given internal field does not correspond to the mesh. "
137  << "Field size: " << iF.size()
138  << " mesh size: " << primitiveField().size()
139  << abort(FatalError);
140  }
141 
142  return tmp<Field<Type1>>(new Field<Type1>(iF, meshPoints));
143 }
144 
145 
146 template<class Type>
147 template<class Type1>
150 (
151  const Field<Type1>& iF
152 ) const
153 {
154  return patchInternalField(iF, patch().meshPoints());
155 }
156 
157 
158 template<class Type>
159 template<class Type1>
161 (
162  Field<Type1>& iF,
163  const Field<Type1>& pF
164 ) const
165 {
166  // Check size
167  if (iF.size() != primitiveField().size())
168  {
170  << "given internal field does not correspond to the mesh. "
171  << "Field size: " << iF.size()
172  << " mesh size: " << primitiveField().size()
173  << abort(FatalError);
174  }
175 
176  if (pF.size() != size())
177  {
179  << "given patch field does not correspond to the mesh. "
180  << "Field size: " << pF.size()
181  << " mesh size: " << size()
182  << abort(FatalError);
183  }
184 
185  // Get the addressing
186  const labelList& mp = patch().meshPoints();
187 
188  forAll(mp, pointi)
189  {
190  iF[mp[pointi]] += pF[pointi];
191  }
192 }
193 
194 
195 template<class Type>
196 template<class Type1>
198 (
199  Field<Type1>& iF,
200  const Field<Type1>& pF,
201  const labelList& points
202 ) const
203 {
204  // Check size
205  if (iF.size() != primitiveField().size())
206  {
208  << "given internal field does not correspond to the mesh. "
209  << "Field size: " << iF.size()
210  << " mesh size: " << primitiveField().size()
211  << abort(FatalError);
212  }
213 
214  if (pF.size() != size())
215  {
217  << "given patch field does not correspond to the mesh. "
218  << "Field size: " << pF.size()
219  << " mesh size: " << size()
220  << abort(FatalError);
221  }
222 
223  // Get the addressing
224  const labelList& mp = patch().meshPoints();
225 
226  forAll(points, i)
227  {
228  label pointi = points[i];
229  iF[mp[pointi]] += pF[pointi];
230  }
231 }
232 
233 
234 template<class Type>
235 template<class Type1>
237 (
238  Field<Type1>& iF,
239  const Field<Type1>& pF,
240  const labelList& meshPoints
241 ) const
242 {
243  // Check size
244  if (iF.size() != primitiveField().size())
245  {
247  << "given internal field does not correspond to the mesh. "
248  << "Field size: " << iF.size()
249  << " mesh size: " << primitiveField().size()
250  << abort(FatalError);
251  }
252 
253  if (pF.size() != meshPoints.size())
254  {
256  << "given patch field does not correspond to the meshPoints. "
257  << "Field size: " << pF.size()
258  << " meshPoints size: " << size()
259  << abort(FatalError);
260  }
261 
262  forAll(meshPoints, pointi)
263  {
264  iF[meshPoints[pointi]] = pF[pointi];
265  }
266 }
267 
268 
269 template<class Type>
270 template<class Type1>
272 (
273  Field<Type1>& iF,
274  const Field<Type1>& pF
275 ) const
276 {
277  setInternalField(iF, pF, patch().meshPoints());
278 }
279 
280 
281 template<class Type>
283 {
284  if (!updated_)
285  {
286  updateCoeffs();
287  }
288 
289  updated_ = false;
290 }
291 
292 
293 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
294 
295 template<class Type>
296 Foam::Ostream& Foam::operator<<
297 (
298  Ostream& os,
299  const pointPatchField<Type>& ptf
300 )
301 {
302  ptf.write(os);
303 
304  os.check("Ostream& operator<<(Ostream&, const pointPatchField<Type>&)");
305 
306  return os;
307 }
308 
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 #include "pointPatchFieldNew.C"
313 
314 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:83
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:108
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
commsTypes
Types of communications.
Definition: UPstream.H:65
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Registry of regIOobjects.
const Time & time() const
Return time.
const objectRegistry & db() const
Return the objectRegistry.
Abstract base class for point-mesh patch fields.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
const Time & time() const
Return time.
virtual void write(Ostream &) const
Write.
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
const objectRegistry & db() const
Return local objectRegistry.
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field,.
void setInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
A class for managing temporary objects.
Definition: tmp.H:55
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
const dimensionedScalar mp
Proton mass.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
volScalarField & p