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 | Copyright (C) 2011-2013 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
37 template<class Type>
39 (
40  const pointPatch& p,
42 )
43 :
44  patch_(p),
45  internalField_(iF),
46  updated_(false),
47  patchType_(word::null)
48 {}
49 
50 
51 template<class Type>
53 (
54  const pointPatch& p,
56  const dictionary& dict
57 )
58 :
59  patch_(p),
60  internalField_(iF),
61  updated_(false),
62  patchType_(dict.lookupOrDefault<word>("patchType", word::null))
63 {}
64 
65 
66 template<class Type>
68 (
69  const pointPatchField<Type>& ptf,
70  const pointPatch& p,
73 )
74 :
75  patch_(p),
76  internalField_(iF),
77  updated_(false),
78  patchType_(ptf.patchType_)
79 {}
80 
81 
82 template<class Type>
84 (
85  const pointPatchField<Type>& ptf
86 )
87 :
88  patch_(ptf.patch_),
89  internalField_(ptf.internalField_),
90  updated_(false),
91  patchType_(ptf.patchType_)
92 {}
93 
94 
95 template<class Type>
97 (
98  const pointPatchField<Type>& ptf,
100 )
101 :
102  patch_(ptf.patch_),
103  internalField_(iF),
104  updated_(false),
105  patchType_(ptf.patchType_)
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
111 template<class Type>
113 {
114  return patch_.boundaryMesh().mesh()();
115 }
116 
117 
118 template<class Type>
120 {
121  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
122 
123  if (patchType_.size())
124  {
125  os.writeKeyword("patchType") << patchType_
126  << token::END_STATEMENT << nl;
127  }
128 }
129 
130 
131 template<class Type>
133 {
134  return patchInternalField(internalField());
135 }
136 
137 
138 template<class Type>
139 template<class Type1>
141 (
142  const Field<Type1>& iF,
143  const labelList& meshPoints
144 ) const
145 {
146  // Check size
147  if (iF.size() != internalField().size())
148  {
150  (
151  "tmp<Field<Type1> > pointPatchField<"
152  "Type>::"
153  "patchInternalField(const Field<Type1>& iF) const"
154  ) << "given internal field does not correspond to the mesh. "
155  << "Field size: " << iF.size()
156  << " mesh size: " << internalField().size()
157  << abort(FatalError);
158  }
159 
160  return tmp<Field<Type1> >(new Field<Type1>(iF, meshPoints));
161 }
162 
163 
164 template<class Type>
165 template<class Type1>
167 (
168  const Field<Type1>& iF
169 ) const
170 {
171  return patchInternalField(iF, patch().meshPoints());
172 }
173 
174 
175 template<class Type>
176 template<class Type1>
178 (
179  Field<Type1>& iF,
180  const Field<Type1>& pF
181 ) const
182 {
183  // Check size
184  if (iF.size() != internalField().size())
185  {
187  (
188  "void pointPatchField<Type>::"
189  "addToInternalField("
190  "Field<Type1>& iF, const Field<Type1>& iF) const"
191  ) << "given internal field does not correspond to the mesh. "
192  << "Field size: " << iF.size()
193  << " mesh size: " << internalField().size()
194  << abort(FatalError);
195  }
196 
197  if (pF.size() != size())
198  {
200  (
201  "void pointPatchField<Type>::"
202  "addToInternalField("
203  "Field<Type1>& iF, const Field<Type1>& iF) const"
204  ) << "given patch field does not correspond to the mesh. "
205  << "Field size: " << pF.size()
206  << " mesh size: " << size()
207  << abort(FatalError);
208  }
209 
210  // Get the addressing
211  const labelList& mp = patch().meshPoints();
212 
213  forAll(mp, pointI)
214  {
215  iF[mp[pointI]] += pF[pointI];
216  }
217 }
218 
219 
220 template<class Type>
221 template<class Type1>
223 (
224  Field<Type1>& iF,
225  const Field<Type1>& pF,
226  const labelList& points
227 ) const
228 {
229  // Check size
230  if (iF.size() != internalField().size())
231  {
233  (
234  "void pointPatchField<Type>::"
235  "addToInternalField("
236  "Field<Type1>& iF, const Field<Type1>& iF, const labelList&) const"
237  ) << "given internal field does not correspond to the mesh. "
238  << "Field size: " << iF.size()
239  << " mesh size: " << internalField().size()
240  << abort(FatalError);
241  }
242 
243  if (pF.size() != size())
244  {
246  (
247  "void pointPatchField<Type>::"
248  "addToInternalField("
249  "Field<Type1>& iF, const Field<Type1>& iF, const labelList&) const"
250  ) << "given patch field does not correspond to the mesh. "
251  << "Field size: " << pF.size()
252  << " mesh size: " << size()
253  << abort(FatalError);
254  }
255 
256  // Get the addressing
257  const labelList& mp = patch().meshPoints();
258 
259  forAll(points, i)
260  {
261  label pointI = points[i];
262  iF[mp[pointI]] += pF[pointI];
263  }
264 }
265 
266 
267 template<class Type>
268 template<class Type1>
270 (
271  Field<Type1>& iF,
272  const Field<Type1>& pF,
273  const labelList& meshPoints
274 ) const
275 {
276  // Check size
277  if (iF.size() != internalField().size())
278  {
280  (
281  "void pointPatchField<Type>::"
282  "setInInternalField("
283  "Field<Type1>& iF, const Field<Type1>& iF) const"
284  ) << "given internal field does not correspond to the mesh. "
285  << "Field size: " << iF.size()
286  << " mesh size: " << internalField().size()
287  << abort(FatalError);
288  }
289 
290  if (pF.size() != meshPoints.size())
291  {
293  (
294  "void pointPatchField<Type>::"
295  "setInInternalField("
296  "Field<Type1>& iF, const Field<Type1>& iF) const"
297  ) << "given patch field does not correspond to the meshPoints. "
298  << "Field size: " << pF.size()
299  << " meshPoints size: " << size()
300  << abort(FatalError);
301  }
302 
303  forAll(meshPoints, pointI)
304  {
305  iF[meshPoints[pointI]] = pF[pointI];
306  }
307 }
308 
309 
310 template<class Type>
311 template<class Type1>
313 (
314  Field<Type1>& iF,
315  const Field<Type1>& pF
316 ) const
317 {
318  setInInternalField(iF, pF, patch().meshPoints());
319 }
320 
321 
322 template<class Type>
324 {
325  if (!updated_)
326  {
327  updateCoeffs();
328  }
329 
330  updated_ = false;
331 }
332 
333 
334 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
335 
336 template<class Type>
337 Ostream& operator<<
338 (
339  Ostream& os,
340  const pointPatchField<Type>& ptf
341 )
342 {
343  ptf.write(os);
344 
345  os.check("Ostream& operator<<(Ostream&, const pointPatchField<Type>&)");
346 
347  return os;
348 }
349 
350 
351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 
353 } // End namespace Foam
354 
355 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 
357 #include "pointPatchFieldNew.C"
358 
359 // ************************************************************************* //
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
const objectRegistry & db() const
Return local objectRegistry.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::blocking)
Evaluate the patch field.
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
const dimensionedScalar mp
Proton mass.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Abstract base class for point-mesh patch fields.
static const char nl
Definition: Ostream.H:260
commsTypes
Types of communications.
Definition: UPstream.H:64
#define forAll(list, i)
Definition: UList.H:421
Pre-declare SubField and related Field type.
Definition: Field.H:57
errorManip< error > abort(error &err)
Definition: errorManip.H:131
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::pointPatchFieldMapper.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field,.
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
error FatalError
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Registry of regIOobjects.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
A class for managing temporary objects.
Definition: PtrList.H:118
static const word null
An empty word.
Definition: word.H:77
conserve internalField()+
virtual void write(Ostream &) const
Write.