FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/pointMesh.H>
28 #include <OpenFOAM/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 )
71 :
72  patch_(ptf.patch_),
73  internalField_(ptf.internalField_),
74  updated_(false),
75  patchType_(ptf.patchType_)
76 {}
77 
78 
79 template<class Type>
81 (
82  const pointPatchField<Type>& ptf,
84 )
85 :
86  patch_(ptf.patch_),
87  internalField_(iF),
88  updated_(false),
89  patchType_(ptf.patchType_)
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
95 template<class Type>
97 {
98  return patch_.boundaryMesh().mesh()();
99 }
100 
101 
102 template<class Type>
104 {
105  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
106 
107  if (patchType_.size())
108  {
109  os.writeKeyword("patchType") << patchType_
110  << token::END_STATEMENT << nl;
111  }
112 }
113 
114 
115 template<class Type>
117 {
118  return patchInternalField(internalField());
119 }
120 
121 
122 template<class Type>
123 template<class Type1>
125 (
126  const Field<Type1>& iF
127 ) const
128 {
129  // Check size
130  if (iF.size() != internalField().size())
131  {
133  (
134  "tmp<Field<Type1> > pointPatchField<"
135  "Type>::"
136  "patchInternalField(const Field<Type1>& iF) const"
137  ) << "given internal field does not correspond to the mesh. "
138  << "Field size: " << iF.size()
139  << " mesh size: " << internalField().size()
140  << abort(FatalError);
141  }
142 
143  // get addressing
144  const labelList& meshPoints = patch().meshPoints();
145 
146  tmp<Field<Type1> > tvalues(new Field<Type1>(meshPoints.size()));
147  Field<Type1>& values = tvalues();
148 
149  forAll (meshPoints, pointI)
150  {
151  values[pointI] = iF[meshPoints[pointI]];
152  }
153 
154  return tvalues;
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() != internalField().size())
168  {
170  (
171  "void pointPatchField<Type>::"
172  "addToInternalField("
173  "Field<Type1>& iF, const Field<Type1>& iF) const"
174  ) << "given internal field does not correspond to the mesh. "
175  << "Field size: " << iF.size()
176  << " mesh size: " << internalField().size()
177  << abort(FatalError);
178  }
179 
180  if (pF.size() != size())
181  {
183  (
184  "void pointPatchField<Type>::"
185  "addToInternalField("
186  "Field<Type1>& iF, const Field<Type1>& iF) const"
187  ) << "given patch field does not correspond to the mesh. "
188  << "Field size: " << pF.size()
189  << " mesh size: " << size()
190  << abort(FatalError);
191  }
192 
193  // Get the addressing
194  const labelList& mp = patch().meshPoints();
195 
196  forAll (mp, pointI)
197  {
198  iF[mp[pointI]] += pF[pointI];
199  }
200 }
201 
202 
203 template<class Type>
204 template<class Type1>
206 (
207  Field<Type1>& iF,
208  const Field<Type1>& pF,
209  const labelList& meshPoints
210 ) const
211 {
212  // Check size
213  if (iF.size() != internalField().size())
214  {
216  (
217  "void pointPatchField<Type>::"
218  "setInInternalField("
219  "Field<Type1>& iF, const Field<Type1>& iF) const"
220  ) << "given internal field does not correspond to the mesh. "
221  << "Field size: " << iF.size()
222  << " mesh size: " << internalField().size()
223  << abort(FatalError);
224  }
225 
226  if (pF.size() != meshPoints.size())
227  {
229  (
230  "void pointPatchField<Type>::"
231  "setInInternalField("
232  "Field<Type1>& iF, const Field<Type1>& iF) const"
233  ) << "given patch field does not correspond to the meshPoints. "
234  << "Field size: " << pF.size()
235  << " meshPoints size: " << size()
236  << abort(FatalError);
237  }
238 
239  forAll (meshPoints, pointI)
240  {
241  iF[meshPoints[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
253 {
254  setInInternalField(iF, pF, patch().meshPoints());
255 }
256 
257 
258 template<class Type>
260 {
261  if (!updated_)
262  {
263  updateCoeffs();
264  }
265 
266  updated_ = false;
267 }
268 
269 
270 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
271 
272 template<class Type>
273 Ostream& operator<<
274 (
275  Ostream& os,
276  const pointPatchField<Type>& ptf
277 )
278 {
279  ptf.write(os);
280 
281  os.check("Ostream& operator<<(Ostream&, const pointPatchField<Type>&)");
282 
283  return os;
284 }
285 
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 } // End namespace Foam
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 #include "newPointPatchField.C"
294 
295 // ************************ vim: set sw=4 sts=4 et: ************************ //