DimensionedField.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 Copyright (C) 2015-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "DimensionedField.H"
30#include "dimensionedType.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34// Check mesh for two fields
35#define checkField(df1, df2, op) \
36if (&(df1).mesh() != &(df2).mesh()) \
37{ \
38 FatalErrorInFunction \
39 << "different mesh for fields " \
40 << (df1).name() << " and " << (df2).name() \
41 << " during operation " << op \
42 << abort(FatalError); \
43}
44
45
46// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47
48template<class Type, class GeoMesh>
50{
51 const label fieldSize = this->size();
52 if (fieldSize)
53 {
54 const label meshSize = GeoMesh::size(this->mesh_);
55 if (fieldSize != meshSize)
56 {
58 << "size of field = " << fieldSize
59 << " is not the same as the size of mesh = "
60 << meshSize
61 << abort(FatalError);
62 }
63 }
64}
65
66
67// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68
69template<class Type, class GeoMesh>
71(
72 const IOobject& io,
73 const Mesh& mesh,
74 const dimensionSet& dims,
75 const Field<Type>& field
76)
77:
79 Field<Type>(field),
80 mesh_(mesh),
81 dimensions_(dims),
82 oriented_()
83{
84 checkFieldSize();
85}
86
87
88template<class Type, class GeoMesh>
90(
91 const IOobject& io,
92 const Mesh& mesh,
93 const dimensionSet& dims,
95)
96:
98 Field<Type>(std::move(field)),
99 mesh_(mesh),
100 dimensions_(dims)
101{
102 checkFieldSize();
103}
104
105
106template<class Type, class GeoMesh>
108(
109 const IOobject& io,
110 const Mesh& mesh,
111 const dimensionSet& dims,
113)
114:
116 Field<Type>(std::move(field)),
117 mesh_(mesh),
118 dimensions_(dims)
119{
120 checkFieldSize();
121}
122
123
124template<class Type, class GeoMesh>
126(
127 const IOobject& io,
128 const Mesh& mesh,
129 const dimensionSet& dims,
130 const tmp<Field<Type>>& tfield
131)
134 Field<Type>(tfield.constCast(), tfield.movable()),
135 mesh_(mesh),
136 dimensions_(dims),
137 oriented_()
138{
139 tfield.clear();
140 checkFieldSize();
142
143
144template<class Type, class GeoMesh>
146(
147 const IOobject& io,
148 const Mesh& mesh,
149 const dimensionSet& dims,
150 const bool checkIOFlags
151)
152:
154 Field<Type>(GeoMesh::size(mesh)),
155 mesh_(mesh),
156 dimensions_(dims),
157 oriented_()
158{
159 if (checkIOFlags)
160 {
162 }
163}
164
165
166template<class Type, class GeoMesh>
168(
169 const IOobject& io,
170 const Mesh& mesh,
171 const dimensioned<Type>& dt,
172 const bool checkIOFlags
173)
174:
176 Field<Type>(GeoMesh::size(mesh), dt.value()),
177 mesh_(mesh),
178 dimensions_(dt.dimensions()),
179 oriented_()
180{
181 if (checkIOFlags)
182 {
184 }
185}
186
187
188template<class Type, class GeoMesh>
190(
192)
193:
194 regIOobject(df),
195 Field<Type>(df),
196 mesh_(df.mesh_),
197 dimensions_(df.dimensions_),
198 oriented_(df.oriented_)
199{}
200
201
202template<class Type, class GeoMesh>
204(
206)
208 DimensionedField<Type, GeoMesh>(df, true)
209{}
211
212template<class Type, class GeoMesh>
214(
216 bool reuse
217)
218:
219 regIOobject(df, reuse),
220 Field<Type>(df, reuse),
221 mesh_(df.mesh_),
222 dimensions_(df.dimensions_),
223 oriented_(df.oriented_)
224{}
225
226
227template<class Type, class GeoMesh>
231)
232:
233 DimensionedField<Type, GeoMesh>(tdf.constCast(), tdf.movable())
234{
235 tdf.clear();
237
238
239template<class Type, class GeoMesh>
241(
242 const IOobject& io,
244)
247 Field<Type>(df),
248 mesh_(df.mesh_),
249 dimensions_(df.dimensions_),
250 oriented_(df.oriented_)
251{}
253
254template<class Type, class GeoMesh>
256(
257 const IOobject& io,
260:
261 DimensionedField<Type, GeoMesh>(io, df, true)
262{}
263
264
265template<class Type, class GeoMesh>
267(
268 const IOobject& io,
270 bool reuse
271)
272:
273 regIOobject(io, df),
274 Field<Type>(df, reuse),
275 mesh_(df.mesh_),
276 dimensions_(df.dimensions_),
277 oriented_(df.oriented_)
278{}
279
280
281template<class Type, class GeoMesh>
283(
284 const IOobject& io,
286)
287:
288 DimensionedField<Type, GeoMesh>(io, tdf.constCast(), tdf.movable())
289{
290 tdf.clear();
291}
292
293
294template<class Type, class GeoMesh>
296(
297 const word& newName,
299)
300:
301 regIOobject(newName, df, newName != df.name()),
302 Field<Type>(df),
303 mesh_(df.mesh_),
304 dimensions_(df.dimensions_),
305 oriented_(df.oriented_)
306{}
307
308
309template<class Type, class GeoMesh>
311(
312 const word& newName,
314)
315:
316 DimensionedField<Type, GeoMesh>(newName, df, true)
317{}
318
319
320template<class Type, class GeoMesh>
322(
323 const word& newName,
325 bool reuse
326)
327:
328 regIOobject(newName, df, true),
329 Field<Type>(df, reuse),
330 mesh_(df.mesh_),
331 dimensions_(df.dimensions_),
332 oriented_(df.oriented_)
333{}
334
335
336template<class Type, class GeoMesh>
338(
339 const word& newName,
341)
342:
343 DimensionedField<Type, GeoMesh>(newName, tdf.constCast(), tdf.movable())
344{
345 tdf.clear();
346}
347
348
349template<class Type, class GeoMesh>
352{
354}
355
356
357// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
358
359template<class Type, class GeoMesh>
361<
363 <
365 >
366>
368(
369 const direction d
370) const
371{
373 (
375 (
376 name() + ".component(" + ::Foam::name(d) + ')',
377 instance(),
378 db()
379 ),
380 mesh_,
381 dimensions_
382 );
383
384 Foam::component(tresult.ref(), *this, d);
385
386 return tresult;
387}
388
389
390template<class Type, class GeoMesh>
392(
393 const direction d,
394 const DimensionedField
395 <
397 >& df
398)
399{
401}
402
404template<class Type, class GeoMesh>
406(
407 const direction d,
408 const tmp
411 <
413 >
414 >& tdf
415)
416{
417 replace(d, tdf());
418 tdf.clear();
419}
420
421
422template<class Type, class GeoMesh>
427 (
429 (
430 name() + ".T()",
431 instance(),
432 db()
433 ),
434 mesh_,
435 dimensions_
436 );
438 Foam::T(tresult.ref(), *this);
440 return tresult;
441}
444template<class Type, class GeoMesh>
447 return
449 (
450 this->name() + ".average()",
451 this->dimensions(),
452 gAverage(field())
453 );
454}
455
456
457template<class Type, class GeoMesh>
459(
460 const DimensionedField<scalar, GeoMesh>& weightField
461) const
462{
463 return
465 (
466 this->name() + ".weightedAverage(weights)",
467 this->dimensions(),
468 gSum(weightField*field())/gSum(weightField)
469 );
470}
471
472
473template<class Type, class GeoMesh>
475(
476 const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
477) const
478{
479 dimensioned<Type> result = weightedAverage(tweightField());
480 tweightField.clear();
481 return result;
482}
483
484
485// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
486
487template<class Type, class GeoMesh>
489(
491)
492{
493 if (this == &df)
494 {
495 return; // Self-assignment is a no-op
496 }
497
498 checkField(*this, df, "=");
499
500 dimensions_ = df.dimensions();
501 oriented_ = df.oriented();
503}
504
505
506template<class Type, class GeoMesh>
508(
510)
511{
512 auto& df = tdf.constCast();
513
514 if (this == &df)
515 {
516 return; // Self-assignment is a no-op
517 }
518
519 checkField(*this, df, "=");
520
521 dimensions_ = df.dimensions();
522 oriented_ = df.oriented();
523 this->transfer(df);
524 tdf.clear();
525}
526
527
528template<class Type, class GeoMesh>
530(
531 const dimensioned<Type>& dt
532)
533{
534 dimensions_ = dt.dimensions();
536}
537
538
539#define COMPUTED_ASSIGNMENT(TYPE, op) \
540 \
541template<class Type, class GeoMesh> \
542void Foam::DimensionedField<Type, GeoMesh>::operator op \
543( \
544 const DimensionedField<TYPE, GeoMesh>& df \
545) \
546{ \
547 checkField(*this, df, #op); \
548 \
549 dimensions_ op df.dimensions(); \
550 oriented_ op df.oriented(); \
551 Field<Type>::operator op(df); \
552} \
553 \
554template<class Type, class GeoMesh> \
555void Foam::DimensionedField<Type, GeoMesh>::operator op \
556( \
557 const tmp<DimensionedField<TYPE, GeoMesh>>& tdf \
558) \
559{ \
560 operator op(tdf()); \
561 tdf.clear(); \
562} \
563 \
564template<class Type, class GeoMesh> \
565void Foam::DimensionedField<Type, GeoMesh>::operator op \
566( \
567 const dimensioned<TYPE>& dt \
568) \
569{ \
570 dimensions_ op dt.dimensions(); \
571 Field<Type>::operator op(dt.value()); \
572}
573
578
579#undef COMPUTED_ASSIGNMENT
580
581// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
582
583#undef checkField
584
585// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
586
587#include "DimensionedFieldIO.C"
588#include "DimensionedFieldNew.C"
590
591// ************************************************************************* //
#define checkField(df1, df2, op)
#define COMPUTED_ASSIGNMENT(TYPE, op)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
tmp< DimensionedField< Type, GeoMesh > > T() const
Return the field transpose (only defined for second rank tensors)
tmp< DimensionedField< Type, GeoMesh > > clone() const
Clone.
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh > &weightField) const
Calculate and return weighted average.
void replace(const direction d, const DimensionedField< cmptType, GeoMesh > &df)
Replace a component field of the field.
dimensioned< Type > average() const
Calculate and return arithmetic average.
Generic templated field type.
Definition: Field.H:82
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:641
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:557
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:49
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:109
Generic dimensioned Type class.
const dimensionSet & dimensions() const
Return const reference to dimensions.
const Type & value() const
Return const reference to value.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Type gSum(const FieldField< Field, Type > &f)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
uint8_t direction
Definition: direction.H:56
Type gAverage(const FieldField< Field, Type > &f)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
propsDict readIfPresent("fields", acceptFields)