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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "pointPatchField.H"
29 #include "pointMesh.H"
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const pointPatch& p,
39 )
40 :
41  patch_(p),
42  internalField_(iF),
43  updated_(false),
44  patchType_(word::null)
45 {}
46 
47 
48 template<class Type>
50 (
51  const pointPatch& p,
53  const dictionary& dict
54 )
55 :
56  patch_(p),
57  internalField_(iF),
58  updated_(false),
59  patchType_(dict.lookupOrDefault<word>("patchType", word::null))
60 {}
61 
62 
63 template<class Type>
65 (
66  const pointPatchField<Type>& ptf,
67  const pointPatch& p,
70 )
71 :
72  patch_(p),
73  internalField_(iF),
74  updated_(false),
75  patchType_(ptf.patchType_)
76 {}
77 
78 
79 template<class Type>
81 (
82  const pointPatchField<Type>& ptf
83 )
84 :
85  patch_(ptf.patch_),
86  internalField_(ptf.internalField_),
87  updated_(false),
88  patchType_(ptf.patchType_)
89 {}
90 
91 
92 template<class Type>
94 (
95  const pointPatchField<Type>& ptf,
97 )
98 :
99  patch_(ptf.patch_),
100  internalField_(iF),
101  updated_(false),
102  patchType_(ptf.patchType_)
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
108 template<class Type>
110 {
111  return patch_.boundaryMesh().mesh()();
112 }
113 
114 
115 template<class Type>
117 {
118  os.writeEntry("type", type());
119 
120  if (patchType_.size())
121  {
122  os.writeEntry("patchType", patchType_);
123  }
124 }
125 
126 
127 template<class Type>
130 {
131  return patchInternalField(primitiveField());
132 }
133 
134 
135 template<class Type>
136 template<class Type1>
139 (
140  const Field<Type1>& iF,
141  const labelList& meshPoints
142 ) const
143 {
144  // Check size
145  if (iF.size() != primitiveField().size())
146  {
148  << "given internal field does not correspond to the mesh. "
149  << "Field size: " << iF.size()
150  << " mesh size: " << primitiveField().size()
151  << abort(FatalError);
152  }
153 
154  return tmp<Field<Type1>>::New(iF, meshPoints);
155 }
156 
157 
158 template<class Type>
159 template<class Type1>
162 (
163  const Field<Type1>& iF
164 ) const
165 {
166  return patchInternalField(iF, patch().meshPoints());
167 }
168 
169 
170 template<class Type>
171 template<class Type1>
173 (
174  Field<Type1>& iF,
175  const Field<Type1>& pF
176 ) const
177 {
178  // Check size
179  if (iF.size() != primitiveField().size())
180  {
182  << "given internal field does not correspond to the mesh. "
183  << "Field size: " << iF.size()
184  << " mesh size: " << primitiveField().size()
185  << abort(FatalError);
186  }
187 
188  if (pF.size() != size())
189  {
191  << "given patch field does not correspond to the mesh. "
192  << "Field size: " << pF.size()
193  << " mesh size: " << size()
194  << abort(FatalError);
195  }
196 
197  // Get the addressing
198  const labelList& mp = patch().meshPoints();
199 
200  forAll(mp, pointi)
201  {
202  iF[mp[pointi]] += pF[pointi];
203  }
204 }
205 
206 
207 template<class Type>
208 template<class Type1>
210 (
211  Field<Type1>& iF,
212  const Field<Type1>& pF,
213  const labelList& points
214 ) const
215 {
216  // Check size
217  if (iF.size() != primitiveField().size())
218  {
220  << "given internal field does not correspond to the mesh. "
221  << "Field size: " << iF.size()
222  << " mesh size: " << primitiveField().size()
223  << abort(FatalError);
224  }
225 
226  if (pF.size() != size())
227  {
229  << "given patch field does not correspond to the mesh. "
230  << "Field size: " << pF.size()
231  << " mesh size: " << size()
232  << abort(FatalError);
233  }
234 
235  // Get the addressing
236  const labelList& mp = patch().meshPoints();
237 
238  forAll(points, i)
239  {
240  label pointi = points[i];
241  iF[mp[pointi]] += pF[pointi];
242  }
243 }
244 
245 
246 template<class Type>
247 template<class Type1>
249 (
250  Field<Type1>& iF,
251  const Field<Type1>& pF,
252  const labelList& meshPoints
253 ) const
254 {
255  // Check size
256  if (iF.size() != primitiveField().size())
257  {
259  << "given internal field does not correspond to the mesh. "
260  << "Field size: " << iF.size()
261  << " mesh size: " << primitiveField().size()
262  << abort(FatalError);
263  }
264 
265  if (pF.size() != meshPoints.size())
266  {
268  << "given patch field does not correspond to the meshPoints. "
269  << "Field size: " << pF.size()
270  << " meshPoints size: " << size()
271  << abort(FatalError);
272  }
273 
274  forAll(meshPoints, pointi)
275  {
276  iF[meshPoints[pointi]] = pF[pointi];
277  }
278 }
279 
280 
281 template<class Type>
282 template<class Type1>
284 (
285  Field<Type1>& iF,
286  const Field<Type1>& pF
287 ) const
288 {
289  setInInternalField(iF, pF, patch().meshPoints());
290 }
291 
292 
293 template<class Type>
295 {
296  if (!updated_)
297  {
298  updateCoeffs();
299  }
300 
301  updated_ = false;
302 }
303 
304 
305 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
306 
307 template<class Type>
308 Foam::Ostream& Foam::operator<<
309 (
310  Ostream& os,
311  const pointPatchField<Type>& ptf
312 )
313 {
314  ptf.write(os);
315 
316  os.check(FUNCTION_NAME);
317 
318  return os;
319 }
320 
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #include "pointPatchFieldNew.C"
325 
326 // ************************************************************************* //
Foam::pointPatchField::addToInternalField
void addToInternalField(Field< Type1 > &iF, const Field< Type1 > &pF) const
Given the internal field and a patch field,.
Definition: pointPatchField.C:173
Foam::constant::atomic::mp
const dimensionedScalar mp
Proton mass.
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
pointPatchField.H
Foam::pointPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
Definition: pointPatchField.C:294
Foam::pointPatchField::db
const objectRegistry & db() const
Return local objectRegistry.
Definition: pointPatchField.C:109
Foam::pointPatchField::pointPatchField
pointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Definition: pointPatchField.C:36
pointPatchFieldNew.C
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::pointPatchField
Abstract base class for point-mesh patch fields.
Definition: pointMVCWeight.H:60
Foam::pointPatchField::setInInternalField
void setInInternalField(Field< Type1 > &iF, const Field< Type1 > &pF, const labelList &meshPoints) const
Given the internal field and a patch field,.
Definition: pointPatchField.C:249
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::label
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:62
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::pointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: pointPatchField.C:116
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:66
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
dictionary.H
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:261
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:219
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::pointPatchField::patchInternalField
tmp< Field< Type > > patchInternalField() const
Return field created from appropriate internal field values.
Definition: pointPatchField.C:129
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
pointMesh.H
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54