MinMaxOps.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 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
26InNamespace
27 Foam
28
29Description
30 Global functions and operators related to the MinMax class.
31 Included by MinMax.H
32
33\*---------------------------------------------------------------------------*/
34
35#ifndef MinMaxOps_H
36#define MinMaxOps_H
37
38#include "MinMax.H"
39#include "VectorSpace.H"
40#include <type_traits>
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46
47// Global Functions
48
49//- The mag() function for min/max range
50template<class T>
51inline scalar mag(const MinMax<T>& range)
52{
53 return range.mag();
54}
55
56
57//- Return the value after clipping by the min/max limiter
58template<class T>
59inline T clip(const T& val, const MinMax<T>& range)
60{
61 return range.clip(val);
62}
63
64
65
66//- Return the value after clipping by the min/max limiter
67template<class T>
68struct clipOp
69{
70 T operator()(T& val, const MinMax<T>& range) const
71 {
72 return range.clip(val);
73 }
74};
75
76
77//- Clip value and assign inplace
78template<class T>
80{
81 bool operator()(T& val, const MinMax<T>& range) const
82 {
83 return range.inplaceClip(val);
84 }
85};
86
87
88//- Extract the min/max range from a list of values.
89template<class T>
90inline MinMax<T> minMax(const UList<T>& vals)
91{
92 return MinMax<T>(vals);
93}
94
95
96//- Combine two values to create a min/max range. Order is unimportant.
97template<class T>
98inline MinMax<T> minMax(const T& x, const T& y)
99{
100 return MinMax<T>(x).add(y);
101}
102
103
104//- Combine two MinMax ranges (same as x + y)
105template<class T>
106inline MinMax<T> minMax(const MinMax<T>& x, const MinMax<T>& y)
107{
108 return MinMax<T>(x).add(y);
109}
110
111
112//- Combine values and/or MinMax ranges
113template<class T>
115{
116 MinMax<T> operator()(const T& x, const T& y) const
117 {
118 return MinMax<T>(x).add(y);
119 }
120
121 MinMax<T> operator()(const MinMax<T>& x, const T& y) const
122 {
123 return MinMax<T>(x).add(y);
124 }
125
126 MinMax<T> operator()(const T& x, const MinMax<T>& y) const
127 {
128 return MinMax<T>(y).add(x);
129 }
130
132 {
133 return MinMax<T>(x).add(y); // Same as (x + y)
134 }
135};
136
137
138//- Combine assignment for MinMax range
139template<class T>
141{
143 {
144 return x.add(y);
145 }
146
148 {
149 return x.add(y);
150 }
151
153 {
154 return x.add(y);
155 }
156};
157
158
159//- The magnitude of an initial single value.
160inline scalarMinMax minMaxMag(const scalar val)
161{
162 return scalarMinMax(Foam::mag(val));
163}
164
165
166//- The magnitude of from an initial VectorSpace.
167template<class Form, class Cmpt, direction nCmpt>
169{
170 return scalarMinMax(Foam::mag(vs));
171}
172
173
174//- The min/max magnitudes from a list of values
175template<class T>
176inline scalarMinMax minMaxMag(const UList<T>& vals)
177{
178 scalarMinMax result;
179 for (const T& val : vals)
180 {
181 result += Foam::mag(val);
182 }
183
184 return result;
185}
186
187
188//- The min/max magnitudes from a min/max range
189template<class T>
191{
192 return
193 (
195 );
196}
197
198
199//- Combine the magitude of two values to create a min/max range.
200//- Order is unimportant.
201template<class T>
202inline scalarMinMax minMaxMag(const T& x, const T& y)
203{
204 return minMaxMag(x).add(Foam::mag(y));
205}
206
207
208//- Scalar combine two MinMax ranges of same type
209template<class T>
211{
212 return
213 (
214 minMaxMag(x)
215 .add(Foam::mag(y.min()))
216 .add(Foam::mag(y.max()))
217 );
218}
219
220
221//- Scalar combine two MinMax ranges of dissimilar types
222template<class T1, class T2>
224{
225 return
226 (
227 minMaxMag(x)
228 .add(Foam::mag(y.min()))
229 .add(Foam::mag(y.max()))
230 );
231}
232
233
234//- Scalar combine the magitude of a value.
235template<class T>
237{
238 scalarMinMax operator()(const scalarMinMax& x, const T& y) const
239 {
240 return minMaxMag(x).add(Foam::mag(y));
241 }
242
243 template<class T1, class T2>
245 {
246 return minMaxMag(x, y);
247 }
248};
249
250
251//- Combine assignment for MinMax range
252template<class T>
254{
256 {
257 x = minMaxMag(x);
258 return x.add(Foam::mag(y));
259 }
260
262 {
263 x = minMaxMag(x);
264
265 return
266 (
267 x
268 .add(Foam::mag(y.min()))
269 .add(Foam::mag(y.max()))
270 );
271 }
272
274 {
275 x = minMaxMag(x);
276
277 for (const T& val : y)
278 {
279 x.add(Foam::mag(val));
280 }
281
282 return x;
283 }
284};
285
286
287// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
288
289//- Combine two ranges
290template<class T>
291inline MinMax<T> operator+(const MinMax<T>& x, const MinMax<T>& y)
292{
293 return MinMax<T>(x).add(y);
294}
295
296
297//- Multiply range by scalar factor
298template<class T>
299inline MinMax<T> operator*(const MinMax<T>& x, const scalar& s)
300{
301 return MinMax<T>(x.min()*s, x.max()*s);
302}
303
304
305//- Divide range by scalar factor
306template<class T>
307inline MinMax<T> operator/(const MinMax<T>& x, const scalar& s)
308{
309 return MinMax<T>(x.min()/s, x.max()/s);
310}
311
312
313// Comparison
314
315template<class T, class U>
316inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
317operator<(const MinMax<T>& range, const U& val)
318{
319 return (range.compare(val) < 0);
320}
321
322template<class T, class U>
323inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
324operator<=(const MinMax<T>& range, const U& val)
325{
326 return (range.compare(val) <= 0);
327}
328
329template<class T, class U>
330inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
331operator>(const MinMax<T>& range, const U& val)
332{
333 return (range.compare(val) > 0);
334}
335
336template<class T, class U>
337inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
338operator>=(const MinMax<T>& range, const U& val)
339{
340 return (range.compare(val) >= 0);
341}
342
343
344template<class T, class U>
345inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
346operator<(const U& val, const MinMax<T>& range)
347{
348 return (range.compare(val) > 0);
349}
350
351template<class T, class U>
352inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
353operator<=(const U& val, const MinMax<T>& range)
354{
355 return (range.compare(val) >= 0);
356}
357
358template<class T, class U>
359inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
360operator>(const U& val, const MinMax<T>& range)
361{
362 return (range.compare(val) < 0);
363}
364
365template<class T, class U>
366inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
367operator>=(const U& val, const MinMax<T>& range)
368{
369 return (range.compare(val) <= 0);
370}
371
372
373// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374
375} // End namespace Foam
376
377#endif
378
379// ************************************************************************* //
scalar range
scalar y
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: MinMax.H:128
MinMax< T > & add(const MinMax &other)
Extend the range to include the other min/max range.
Definition: MinMaxI.H:263
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Templated vector space.
Definition: VectorSpace.H:79
U
Definition: pEqn.H:72
const volScalarField & T
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
dimensionSet clip(const dimensionSet &ds1, const dimensionSet &ds2)
Definition: dimensionSet.C:278
bool operator<=(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A same or older than B.
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
bool operator>=(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A same or newer than B.
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:117
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:61
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
bool operator<(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A older than B.
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &df)
bool operator>(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A newer than B.
Clip value and assign inplace.
Definition: MinMaxOps.H:80
bool operator()(T &val, const MinMax< T > &range) const
Definition: MinMaxOps.H:81
Return the value after clipping by the min/max limiter.
Definition: MinMaxOps.H:69
T operator()(T &val, const MinMax< T > &range) const
Definition: MinMaxOps.H:70
Combine assignment for MinMax range.
Definition: MinMaxOps.H:141
MinMax< T > & operator()(MinMax< T > &x, const T &y) const
Definition: MinMaxOps.H:142
MinMax< T > & operator()(MinMax< T > &x, const UList< T > &y) const
Definition: MinMaxOps.H:147
MinMax< T > & operator()(MinMax< T > &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:152
Combine assignment for MinMax range.
Definition: MinMaxOps.H:254
scalarMinMax & operator()(scalarMinMax &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:261
scalarMinMax & operator()(scalarMinMax &x, const T &y) const
Definition: MinMaxOps.H:255
scalarMinMax & operator()(scalarMinMax &x, const UList< T > &y) const
Definition: MinMaxOps.H:273
Scalar combine the magitude of a value.
Definition: MinMaxOps.H:237
scalarMinMax operator()(const MinMax< T1 > &x, const MinMax< T2 > &y) const
Definition: MinMaxOps.H:244
scalarMinMax operator()(const scalarMinMax &x, const T &y) const
Definition: MinMaxOps.H:238
Combine values and/or MinMax ranges.
Definition: MinMaxOps.H:115
MinMax< T > operator()(const T &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:126
MinMax< T > operator()(const T &x, const T &y) const
Definition: MinMaxOps.H:116
MinMax< T > operator()(const MinMax< T > &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:131
MinMax< T > operator()(const MinMax< T > &x, const T &y) const
Definition: MinMaxOps.H:121