FieldField.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-2015 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 Description
25  Generic fieldField type.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "FieldField.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 #ifdef FULLDEBUG
37 
38 template<template<class> class Field, class Type1, class Type2>
39 void checkFields
40 (
41  const FieldField<Field, Type1>& f1,
42  const FieldField<Field, Type2>& f2,
43  const char* op
44 )
45 {
46  if (f1.size() != f2.size())
47  {
49  << " FieldField<" << pTraits<Type1>::typeName
50  << "> f1(" << f1.size() << ')'
51  << " and FieldField<" << pTraits<Type2>::typeName
52  << "> f2(" << f2.size() << ')'
53  << endl << " for operation " << op
54  << abort(FatalError);
55  }
56 }
57 
58 template<template<class> class Field, class Type1, class Type2, class Type3>
59 void checkFields
60 (
61  const FieldField<Field, Type1>& f1,
62  const FieldField<Field, Type2>& f2,
63  const FieldField<Field, Type3>& f3,
64  const char* op
65 )
66 {
67  if (f1.size() != f2.size() || f1.size() != f3.size())
68  {
70  << " FieldField<" << pTraits<Type1>::typeName
71  << "> f1(" << f1.size() << ')'
72  << ", FieldField<" <<pTraits<Type2>::typeName
73  << "> f2(" << f2.size() << ')'
74  << " and FieldField<"<<pTraits<Type3>::typeName
75  << "> f3("<<f3.size() << ')'
76  << endl << " for operation " << op
77  << abort(FatalError);
78  }
79 }
80 
81 #else
82 
83 template<template<class> class Field, class Type1, class Type2>
84 void checkFields
85 (
88  const char* op
89 )
90 {}
91 
92 template<template<class> class Field, class Type1, class Type2, class Type3>
93 void checkFields
94 (
98  const char* op
99 )
100 {}
101 
102 #endif
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
107 template<template<class> class Field, class Type>
109 :
110  PtrList<Field<Type> >()
111 {}
112 
113 
114 template<template<class> class Field, class Type>
116 :
117  PtrList<Field<Type> >(size)
118 {}
119 
120 
121 template<template<class> class Field, class Type>
122 FieldField<Field, Type>::FieldField
123 (
124  const word& type,
125  const FieldField<Field, Type>& ff
126 )
127 :
128  PtrList<Field<Type> >(ff.size())
129 {
130  forAll(*this, i)
131  {
132  set(i, Field<Type>::New(type, ff[i]));
133  }
134 }
135 
136 
137 template<template<class> class Field, class Type>
138 FieldField<Field, Type>::FieldField(const FieldField<Field, Type>& f)
139 :
140  refCount(),
141  PtrList<Field<Type> >(f)
142 {}
143 
144 
145 template<template<class> class Field, class Type>
146 FieldField<Field, Type>::FieldField(FieldField<Field, Type>& f, bool reUse)
147 :
148  refCount(),
149  PtrList<Field<Type> >(f, reUse)
150 {}
151 
152 
153 template<template<class> class Field, class Type>
154 FieldField<Field, Type>::FieldField(const PtrList<Field<Type> >& tl)
155 :
156  PtrList<Field<Type> >(tl)
157 {}
158 
159 
160 // Construct as copy of tmp<FieldField>
161 #ifndef NoConstructFromTmp
162 template<template<class> class Field, class Type>
163 FieldField<Field, Type>::FieldField(const tmp<FieldField<Field, Type> >& tf)
164 :
165  PtrList<Field<Type> >
166  (
167  const_cast<FieldField<Field, Type>&>(tf()),
168  tf.isTmp()
169  )
170 {
171  const_cast<FieldField<Field, Type>&>(tf()).resetRefCount();
172 }
173 #endif
174 
175 
176 template<template<class> class Field, class Type>
177 FieldField<Field, Type>::FieldField(Istream& is)
178 :
179  PtrList<Field<Type> >(is)
180 {}
181 
182 
183 template<template<class> class Field, class Type>
185 {
187 }
188 
189 
190 template<template<class> class Field, class Type>
191 template<class Type2>
193 (
195 )
196 {
198  (
199  new FieldField<Field, Type>(ff.size())
200  );
201 
202  forAll(*nffPtr, i)
203  {
204  nffPtr->set(i, Field<Type>::NewCalculatedType(ff[i]).ptr());
205  }
206 
207  return tmp<FieldField<Field, Type> >(nffPtr);
208 }
209 
210 
211 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
212 
213 template<template<class> class Field, class Type>
215 {
216  forAll(*this, i)
217  {
218  this->operator[](i).negate();
219  }
220 }
221 
222 
223 template<template<class> class Field, class Type>
226 (
227  const direction d
228 ) const
229 {
231  (
233  NewCalculatedType(*this)
234  );
235 
236  ::Foam::component(Component(), *this, d);
237 
238  return Component;
239 }
240 
241 
242 template<template<class> class Field, class Type>
244 (
245  const direction d,
247 )
248 {
249  forAll(*this, i)
250  {
251  this->operator[](i).replace(d, sf[i]);
252  }
253 }
254 
255 
256 template<template<class> class Field, class Type>
257 void FieldField<Field, Type>::replace
258 (
259  const direction d,
260  const cmptType& s
261 )
262 {
263  forAll(*this, i)
264  {
265  this->operator[](i).replace(d, s);
266  }
267 }
268 
269 
270 template<template<class> class Field, class Type>
272 {
273  tmp<FieldField<Field, Type> > transpose
274  (
276  );
277 
278  ::Foam::T(transpose(), *this);
279  return transpose;
280 }
281 
282 
283 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
284 
285 template<template<class> class Field, class Type>
287 {
288  if (this == &f)
289  {
291  << "attempted assignment to self"
292  << abort(FatalError);
293  }
294 
295  forAll(*this, i)
296  {
297  this->operator[](i) = f[i];
298  }
299 }
300 
301 
302 template<template<class> class Field, class Type>
303 void FieldField<Field, Type>::operator=(const tmp<FieldField>& tf)
304 {
305  if (this == &(tf()))
306  {
308  << "attempted assignment to self"
309  << abort(FatalError);
310  }
311 
312  // This is dodgy stuff, don't try this at home.
313  FieldField* fieldPtr = tf.ptr();
314  PtrList<Field<Type> >::transfer(*fieldPtr);
315  delete fieldPtr;
316 }
317 
318 
319 template<template<class> class Field, class Type>
320 void FieldField<Field, Type>::operator=(const Type& t)
321 {
322  forAll(*this, i)
323  {
324  this->operator[](i) = t;
325  }
326 }
327 
328 
329 #define COMPUTED_ASSIGNMENT(TYPE, op) \
330  \
331 template<template<class> class Field, class Type> \
332 void FieldField<Field, Type>::operator op(const FieldField<Field, TYPE>& f) \
333 { \
334  forAll(*this, i) \
335  { \
336  this->operator[](i) op f[i]; \
337  } \
338 } \
339  \
340 template<template<class> class Field, class Type> \
341 void FieldField<Field, Type>::operator op \
342 ( \
343  const tmp<FieldField<Field, TYPE> >& tf \
344 ) \
345 { \
346  operator op(tf()); \
347  tf.clear(); \
348 } \
349  \
350 template<template<class> class Field, class Type> \
351 void FieldField<Field, Type>::operator op(const TYPE& t) \
352 { \
353  forAll(*this, i) \
354  { \
355  this->operator[](i) op t; \
356  } \
357 }
358 
359 COMPUTED_ASSIGNMENT(Type, +=)
360 COMPUTED_ASSIGNMENT(Type, -=)
361 COMPUTED_ASSIGNMENT(scalar, *=)
362 COMPUTED_ASSIGNMENT(scalar, /=)
363 
364 #undef COMPUTED_ASSIGNMENT
365 
366 
367 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
368 
369 template<template<class> class Field, class Type>
371 {
372  os << static_cast<const PtrList<Field<Type> >&>(f);
373  return os;
374 }
375 
376 
377 template<template<class> class Field, class Type>
379 {
380  os << tf();
381  tf.clear();
382  return os;
383 }
384 
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 } // End namespace Foam
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 # include "FieldFieldFunctions.C"
393 
394 // ************************************************************************* //
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:41
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::FieldField
Generic field type.
Definition: FieldField.H:51
FieldField.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::FieldField::FieldField
FieldField()
Construct null.
Definition: FieldField.C:108
Foam::checkFields
void checkFields(const FieldField< Field, Type1 > &, const FieldField< Field, Type2 > &, const char *op)
Definition: FieldField.C:85
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
tf
const tensorField & tf
Definition: getPatchFieldTensor.H:36
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:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
COMPUTED_ASSIGNMENT
#define COMPUTED_ASSIGNMENT(TYPE, op)
Definition: FieldField.C:329
f1
scalar f1
Definition: createFields.H:28
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::negate
void negate(FieldField< Field, Type > &res, const FieldField< Field, Type > &f)
Foam::FatalError
error FatalError
operator<<
std::ostream & operator<<(std::ostream &os, const Vector< C > &v)
Definition: Test-Field.H:39
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
sf
volScalarField sf(fieldObject, mesh)
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::fv::ff
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
Definition: CrankNicolsonDdtScheme.C:272
Foam::FieldField::cmptType
pTraits< Type >::cmptType cmptType
Component type.
Definition: FieldField.H:82
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
T
const volScalarField & T
Definition: createFields.H:25
f
labelList f(nPoints)
Foam::direction
unsigned char direction
Definition: direction.H:43
FieldFieldFunctions.C
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588