fieldsExpressionTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2021 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 "fieldsExpression.H"
27 #include "volFields.H"
28 #include "surfaceFields.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template
33 <
34  template<class> class GeoField,
35  template<class ...> class Op,
36  class TypeA,
37  class TypeB,
38  class Enable
39 >
41 (
42  const GeoField<TypeA>& a,
43  const GeoField<TypeB>& b
44 )
45 {
46  return store(resultName_, Op<GeoField<TypeA>, GeoField<TypeB>>()(a, b));
47 }
48 
49 
50 template
51 <
52  template<class> class GeoField,
53  template<class ...> class Op,
54  class ... Args
55 >
57 (
58  const Args& ...
59 )
60 {
61  return false;
62 }
63 
64 
65 template
66 <
67  template<class> class GeoField,
68  template<class ...> class Op,
69  class TypeA,
70  class TypeB
71 >
73 {
74  if
75  (
76  i == 0
77  && foundObject<GeoField<TypeA>>(fieldNames_[0])
78  )
79  {
81  return store
82  (
84  lookupObject<GeoField<TypeA>>(fieldNames_[0]).clone()
85  );
86  }
87 
88  if
89  (
90  i > 0
91  && foundObject<GeoField<TypeA>>(resultName_)
92  && foundObject<GeoField<TypeB>>(fieldNames_[i])
93  )
94  {
96  lookupObject<GeoField<TypeA>>(resultName_).clone();
97  const GeoField<TypeB>& b =
98  lookupObject<GeoField<TypeB>>(fieldNames_[i]);
99 
101  return opAndStore<GeoField, Op>(a(), b);
102  }
103 
104  return false;
105 }
106 
107 
108 template
109 <
110  template<class> class GeoField,
111  template<class ...> class Op,
112  class TypeA
113 >
115 {
116  bool success = false;
117 
118  #define processType(Type, none) \
119  success = success || foldAB<GeoField, Op, TypeA, Type>(i);
121  #undef processType
122 
123  return success;
124 }
125 
126 
127 template<template<class> class GeoField, template<class ...> class Op>
129 {
130  bool success = false;
131 
132  #define processType(Type, none) \
133  success = success || foldA<GeoField, Op, Type>(i);
135  #undef processType
136 
137  return success;
138 }
139 
140 
141 template<template<class> class GeoField, template<class ...> class Op>
143 {
144  forAll(fieldNames_, i)
145  {
146  if (!fold<GeoField, Op>(i))
147  {
148  return false;
149  }
150  }
151 
152  return true;
153 }
154 
155 
156 template<template<class ...> class Op>
158 {
159  return
160  calcGeoFieldOp<VolField, Op>()
161  || calcGeoFieldOp<SurfaceField, Op>();
162 }
163 
164 
165 // ************************************************************************* //
Foam::surfaceFields.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
#define Op(opName, op)
Definition: ops.H:101
#define processType(Type, none)
#define FOR_ALL_FIELD_TYPES(Macro,...)
Definition: fieldTypes.H:50
const ObjectType & lookupObject(const word &fieldName) const
Lookup object from the objectRegistry.
wordList fieldNames_
Names of fields to process.
bool foldA(const label i)
Fold the fields expression up one place.
bool calcGeoFieldOp()
Calculate and store the fields expression for the given geometric.
bool foundObject(const word &fieldName) const
Find field in the objectRegistry.
bool foldAB(const label i)
Fold the fields expression up one place.
bool success
bool fold(const label i)
Fold the fields expression up one place.
bool clearObject(const word &fieldName)
Clear field from the objectRegistry if present.
bool store(const tmp< ObjectType > &tfield)
Store the given field in the objectRegistry.
word resultName_
Name of result fields.
bool calcOp()
Calculate and store the fields expression for the given operation.
autoPtr< functionObject > clone() const
Return clone.
A class for managing temporary objects.
Definition: PtrList.H:53
bool opAndStore(const GeoField< TypeA > &a, const GeoField< TypeB > &b)
Operate on the fields and store the result. Supported overload.