GeometricFieldOps.H
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) 2019,2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 InNamespace
27  Foam::FieldOps
28 
29 Description
30  Various utility functions to work on geometric fields
31 
32 SourceFiles
33  GeometricFieldOps.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Foam_GeometricFieldOps_H
38 #define Foam_GeometricFieldOps_H
39 
40 #include "FieldOps.H"
41 #include "GeometricField.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 namespace FieldOps
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Namespace FieldOps Declarations
52 \*---------------------------------------------------------------------------*/
53 
54 //- Populate a geometric field as the result of a unary operation on an input.
55 // It is permissible for inputs/outputs to refer to the same field(s),
56 // but partially overlapping regions are ill-defined.
57 template
58 <
59  class Tout, class T1, class UnaryOp,
60  template<class> class PatchField, class GeoMesh
61 >
62 void assign
63 (
66  const UnaryOp& op
67 )
68 {
70  (
71  result.primitiveFieldRef(),
72  a.primitiveField(),
73  op
74  );
75 
76  auto& bfld = result.boundaryFieldRef();
77 
78  const label len = bfld.size();
79 
80  for (label i = 0; i < len; ++i)
81  {
83  (
84  bfld[i],
85  a.boundaryField()[i],
86  op
87  );
88  }
91  {
92  result.boundaryField().check();
93  }
94 }
95 
96 
97 //- Populate a geometric field from the binary operation on two inputs.
98 // It is permissible for inputs/outputs to refer to the same field(s),
99 // but partially overlapping regions are ill-defined.
100 template
101 <
102  class Tout, class T1, class T2, class BinaryOp,
103  template<class> class PatchField, class GeoMesh
104 >
105 void assign
106 (
110  const BinaryOp& bop
111 )
112 {
114  (
115  result.primitiveFieldRef(),
116  a.primitiveField(),
117  b.primitiveField(),
118  bop
119  );
120 
121  auto& bfld = result.boundaryFieldRef();
122 
123  const label len = bfld.size();
124 
125  for (label i = 0; i < len; ++i)
126  {
128  (
129  bfld[i],
130  a.boundaryField()[i],
131  b.boundaryField()[i],
132  bop
133  );
134  }
137  {
138  result.boundaryField().check();
139  }
140 }
141 
142 
143 //- Emulate a ternary operation, selecting values from a or b
144 //- depending on the binary predicate.
145 template
146 <
147  class T, class BinaryOp,
148  template<class> class PatchField, class GeoMesh
149 >
150 void ternary
151 (
155  const BinaryOp& bop
156 )
157 {
159  (
160  result.primitiveFieldRef(),
161  a.primitiveField(),
162  b.primitiveField(),
163  bop
164  );
165 
166  auto& bfld = result.boundaryFieldRef();
167 
168  const label len = bfld.size();
169 
170  for (label i = 0; i < len; ++i)
171  {
173  (
174  bfld[i],
175  a.boundaryField()[i],
176  b.boundaryField()[i],
177  bop
178  );
179  }
182  {
183  result.boundaryField().check();
184  }
185 }
186 
187 
188 //- Emulate a ternary operation, selecting field values from a or b
189 //- depending on the conditional.
190 //
191 // Since boolean fields are not normally used, a flip operation is
192 // a general requirement.
193 template
194 <
195  class T, class BoolType, class FlipOp,
196  template<class> class PatchField, class GeoMesh
197 >
198 void ternarySelect
199 (
204  const FlipOp& flip
205 )
206 {
208  (
209  result.primitiveFieldRef(),
210  cond.primitiveField(),
211  a.primitiveField(),
212  b.primitiveField(),
213  flip
214  );
215 
216  auto& bfld = result.boundaryFieldRef();
217 
218  const label len = bfld.size();
219 
220  for (label i = 0; i < len; ++i)
221  {
223  (
224  bfld[i],
225  cond.boundaryField()[i],
226  a.boundaryField()[i],
227  b.boundaryField()[i],
228  flip
229  );
230  }
233  {
234  result.boundaryField().check();
235  }
236 }
237 
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 } // End namespace FieldOps
242 } // End namespace Foam
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #endif
247 
248 // ************************************************************************* //
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
void ternarySelect(Field< T > &result, const BoolListType &cond, const Field< T > &a, const Field< T > &b, const FlipOp &flip)
Emulate a ternary operation, selecting values from a or b depending on the conditional.
Definition: FieldOps.C:99
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
void assign(Field< Tout > &result, const Field< T1 > &a, const UnaryOp &op)
Populate a field as the result of a unary operation on an input.
Definition: FieldOps.C:28
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Generic GeometricBoundaryField class.
Definition: areaFieldsFwd.H:46
void ternary(Field< T > &result, const Field< T > &a, const Field< T > &b, const BinaryOp &bop)
Emulate a ternary operation, selecting values from a or b depending on the binary predicate...
Definition: FieldOps.C:73
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:42
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
void correctLocalBoundaryConditions()
Correct boundary conditions after a purely local operation. Is.
Namespace for OpenFOAM.