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-2024 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  store(resultName_, Op<GeoField<TypeA>, GeoField<TypeB>>()(a, b));
47 
48  return true;
49 }
50 
51 
52 template
53 <
54  template<class> class GeoField,
55  template<class ...> class Op,
56  class ... Args
57 >
59 (
60  const Args& ...
61 )
62 {
63  return false;
64 }
65 
66 
67 template
68 <
69  template<class> class GeoField,
70  template<class ...> class Op,
71  class TypeA,
72  class TypeB
73 >
75 {
76  if
77  (
78  i == 0
79  && foundObject<GeoField<TypeA>>(fieldNames_[0])
80  )
81  {
82  clearObject(resultName_);
83  store
84  (
85  resultName_,
86  lookupObject<GeoField<TypeA>>(fieldNames_[0]).clone()
87  );
88 
89  return true;
90  }
91 
92  if
93  (
94  i > 0
95  && foundObject<GeoField<TypeA>>(resultName_)
96  && foundObject<GeoField<TypeB>>(fieldNames_[i])
97  )
98  {
100  lookupObject<GeoField<TypeA>>(resultName_).clone();
101  const GeoField<TypeB>& b =
102  lookupObject<GeoField<TypeB>>(fieldNames_[i]);
103 
104  clearObject(resultName_);
105  return opAndStore<GeoField, Op>(a(), b);
106  }
107 
108  return false;
109 }
110 
111 
112 template
113 <
114  template<class> class GeoField,
115  template<class ...> class Op,
116  class TypeA
117 >
119 {
120  bool success = false;
121 
122  #define processType(Type, none) \
123  success = success || foldAB<GeoField, Op, TypeA, Type>(i);
125  #undef processType
126 
127  return success;
128 }
129 
130 
131 template<template<class> class GeoField, template<class ...> class Op>
133 {
134  bool success = false;
135 
136  #define processType(Type, none) \
137  success = success || foldA<GeoField, Op, Type>(i);
139  #undef processType
140 
141  return success;
142 }
143 
144 
145 template<template<class> class GeoField, template<class ...> class Op>
147 {
148  forAll(fieldNames_, i)
149  {
150  if (!fold<GeoField, Op>(i))
151  {
152  return false;
153  }
154  }
155 
156  return true;
157 }
158 
159 
160 template<template<class ...> class Op>
162 {
163  return
164  calcGeoFieldOp<VolField, Op>()
165  || calcGeoFieldOp<VolInternalField, Op>()
166  || calcGeoFieldOp<SurfaceField, Op>();
167 }
168 
169 
170 // ************************************************************************* //
bool success
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
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 fold(const label i)
Fold the fields expression up one place.
word resultName_
Name of result fields.
bool foldAB(const label i)
Fold the fields expression up one place.
bool opAndStore(const GeoField< TypeA > &a, const GeoField< TypeB > &b)
Operate on the fields and store the result. Supported overload.
bool calcOp()
Calculate and store the fields expression for the given operation.
ObjectType & store(const tmp< ObjectType > &tfield)
Store the given field in the objectRegistry.
A class for managing temporary objects.
Definition: tmp.H:55
#define processType(Type, none)
volScalarField & b
Definition: createFields.H:27
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
T clone(const T &t)
Definition: List.H:55
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
#define Op(opName, op)
Definition: ops.H:100
Foam::surfaceFields.