FieldOps.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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Namespace
27 Foam::FieldOps
28
29Description
30 Various utility functions to work on Fields
31
32SourceFiles
33 FieldOps.C
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_FieldOps_H
38#define Foam_FieldOps_H
39
40#include "flipOp.H"
41#include "ListOps.H"
42#include "Tuple2.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48namespace FieldOps
49{
50
51/*---------------------------------------------------------------------------*\
52 Namespace FieldOps Declarations
53\*---------------------------------------------------------------------------*/
54
55//- Populate a field as the result of a unary operation on an input.
56// It is permissible for inputs/outputs to refer to the same field(s),
57// but partially overlapping regions are ill-defined.
58//
59// Examples,
60// \code
61// boolField result(sfield1.size());
62//
63// FieldOps::assign(result, sfield1, lessOp1<scalar>(0.5));
64// FieldOps::assign(result, lfield1, std::logical_not<bool>());
65// \endcode
66//
67// Example of using the Random::uniformGeneratorOp unary operator
68// to populate a random field,
69// \code
70// FieldOps::assign
71// (
72// sfield,
73// sfield,
74// Random::uniformGeneratorOp<scalar>(-15, 25)
75// );
76// \endcode
77//
78// \note wraps std::transform
79template<class Tout, class T1, class UnaryOp>
80void assign
81(
82 Field<Tout>& result,
83 const Field<T1>& a,
84 const UnaryOp& op
85);
86
87
88//- Populate a field as the result of a binary operation on two inputs.
89// It is permissible for inputs/outputs to refer to the same field(s),
90// but partially overlapping regions are ill-defined.
91//
92// Examples,
93// \code
94// FieldOps::assign(result, sfield1, sfield2, std::less<scalar>());
95// FieldOps::assign(result, lfield1, lfield2, std::logical_or<bool>());
96// \endcode
97//
98// \note wraps std::transform
99template<class Tout, class T1, class T2, class BinaryOp>
100void assign
101(
102 Field<Tout>& result,
103 const Field<T1>& a,
104 const Field<T2>& b,
105 const BinaryOp& bop
106);
107
108
109//- Emulate a ternary operation, selecting values from a or b
110//- depending on the binary predicate.
111//
112// Examples,
113// \code
114// FieldOps::ternary(result, sfield1, sfield2, std::less<scalar>());
115// \endcode
116template<class T, class BinaryOp>
117void ternary
118(
119 Field<T>& result,
120 const Field<T>& a,
121 const Field<T>& b,
122 const BinaryOp& bop
123);
124
125
126//- Emulate a ternary operation, selecting values from a or b
127//- depending on the conditional.
128//
129// The meaning of the conditional is adjusted by the flip operation,
130// which is typically Foam::identityOp() or Foam::flipBoolOp()
131//
132// Similar parameter requirements as Foam::subset()
133//
134// Examples,
135// \code
136// FieldOps::ternarySelect(result, selector, sfield1, sfield2);
137// \endcode
138template<class T, class BoolListType, class FlipOp>
139void ternarySelect
140(
141 Field<T>& result,
142 const BoolListType& cond,
143 const Field<T>& a,
144 const Field<T>& b,
145 const FlipOp& flip
146);
147
148
149//- Emulate a ternary operation, selecting values from a or b
150//- depending on the conditional.
151//
152// The meaning of the conditional is adjusted by the flip operation,
153// which is typically Foam::identityOp() or Foam::flipBoolOp()
154template<class T, class FlipOp>
155void ternarySelect
156(
157 Field<T>& result,
158 const bitSet& cond,
159 const Field<T>& a,
160 const Field<T>& b,
161 const FlipOp& flip
162);
163
164
165//- Emulated ternary operation, without condition flipping
166template<class T, class BoolListType>
168(
169 Field<T>& result,
170 const BoolListType& cond,
171 const Field<T>& a,
172 const Field<T>& b
173)
174{
175 ternarySelect(result, cond, a, b, identityOp{});
176}
177
178
179//- Emulated ternary operation, without condition flipping
180template<class T>
182(
183 Field<T>& result,
184 const bitSet& cond,
185 const Field<T>& a,
186 const Field<T>& b
187)
188{
189 ternarySelect(result, cond, a, b, identityOp{});
190}
191
192
193//- Locate the min value in a field and return it and associated data
194// This can be used, for example, to return a value/position combination.
195template<class T1, class T2>
197(
198 const Field<T1>& vals,
199 const Field<T2>& data
200);
201
202
203//- Locate the max value in a field and return it and associated data
204// This can be used, for example, to return a value/position combination.
205template<class T1, class T2>
207(
208 const Field<T1>& vals,
209 const Field<T2>& data
210);
211
212
213} // End namespace FieldOps
214
215// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216
217} // End namespace Foam
218
219// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220
221#ifdef NoRepository
222 #include "FieldOps.C"
223#endif
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226
227#endif
228
229// ************************************************************************* //
Various functions to operate on Lists.
Generic templated field type.
Definition: Field.H:82
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
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:36
void ternarySelect(Field< T > &result, const BoolListType &cond, const Field< T > &a, const Field< T > &b, const FlipOp &flip)
Definition: FieldOps.C:107
Tuple2< T1, T2 > findMaxData(const Field< T1 > &vals, const Field< T2 > &data)
Locate the max value in a field and return it and associated data.
Tuple2< T1, T2 > findMinData(const Field< T1 > &vals, const Field< T2 > &data)
Locate the min value in a field and return it and associated data.
void ternary(Field< T > &result, const Field< T > &a, const Field< T > &b, const BinaryOp &bop)
Definition: FieldOps.C:81
Namespace for OpenFOAM.
volScalarField & b
Definition: createFields.H:27