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 -------------------------------------------------------------------------------
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
28 
29 Description
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 
44 namespace Foam
45 {
46 
47 // Global Functions
48 
49 //- The mag() function for min/max range
50 template<class T>
51 inline 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
58 template<class T>
59 inline 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
67 template<class T>
68 struct 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
78 template<class T>
79 struct clipEqOp
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.
89 template<class T>
90 inline 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.
97 template<class T>
98 inline 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)
105 template<class T>
106 inline 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
113 template<class T>
114 struct minMaxOp
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 
131  MinMax<T> operator()(const MinMax<T>& x, const MinMax<T>& y) const
132  {
133  return MinMax<T>(x).add(y); // Same as (x + y)
134  }
135 };
136 
137 
138 //- Combine assignment for MinMax range
139 template<class T>
141 {
142  MinMax<T>& operator()(MinMax<T>& x, const T& y) const
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.
160 inline scalarMinMax minMaxMag(const scalar val)
161 {
162  return scalarMinMax(Foam::mag(val));
163 }
164 
165 
166 //- The magnitude of from an initial VectorSpace.
167 template<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
175 template<class T>
176 inline 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
189 template<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.
201 template<class T>
202 inline 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
209 template<class T>
210 inline scalarMinMax minMaxMag(const MinMax<T>& x, const MinMax<T>& y)
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
222 template<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.
235 template<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
252 template<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
290 template<class T>
291 inline 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
298 template<class T>
299 inline 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
306 template<class T>
307 inline 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 
315 template<class T, class U>
316 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
317 operator<(const MinMax<T>& range, const U& val)
318 {
319  return (range.compare(val) < 0);
320 }
321 
322 template<class T, class U>
323 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
324 operator<=(const MinMax<T>& range, const U& val)
325 {
326  return (range.compare(val) <= 0);
327 }
328 
329 template<class T, class U>
330 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
331 operator>(const MinMax<T>& range, const U& val)
332 {
333  return (range.compare(val) > 0);
334 }
335 
336 template<class T, class U>
337 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
338 operator>=(const MinMax<T>& range, const U& val)
339 {
340  return (range.compare(val) >= 0);
341 }
342 
343 
344 template<class T, class U>
345 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
346 operator<(const U& val, const MinMax<T>& range)
347 {
348  return (range.compare(val) > 0);
349 }
350 
351 template<class T, class U>
352 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
353 operator<=(const U& val, const MinMax<T>& range)
354 {
355  return (range.compare(val) >= 0);
356 }
357 
358 template<class T, class U>
359 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
360 operator>(const U& val, const MinMax<T>& range)
361 {
362  return (range.compare(val) < 0);
363 }
364 
365 template<class T, class U>
366 inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
367 operator>=(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 // ************************************************************************* //
Foam::minMaxEqOp::operator()
MinMax< T > & operator()(MinMax< T > &x, const UList< T > &y) const
Definition: MinMaxOps.H:147
VectorSpace.H
Foam::minMaxOp::operator()
MinMax< T > operator()(const MinMax< T > &x, const T &y) const
Definition: MinMaxOps.H:121
Foam::minMaxMagEqOp::operator()
scalarMinMax & operator()(scalarMinMax &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:261
Foam::minMaxEqOp::operator()
MinMax< T > & operator()(MinMax< T > &x, const T &y) const
Definition: MinMaxOps.H:142
Foam::minMaxOp::operator()
MinMax< T > operator()(const MinMax< T > &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:131
Foam::clipOp::operator()
T operator()(T &val, const MinMax< T > &range) const
Definition: MinMaxOps.H:70
Foam::operator<=
bool operator<=(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A same or older than B.
Definition: IOstreamOption.H:408
s
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))
Definition: gmvOutputSpray.H:25
Foam::minMaxMagEqOp
Combine assignment for MinMax range.
Definition: MinMaxOps.H:253
MinMax.H
Foam::minMaxEqOp::operator()
MinMax< T > & operator()(MinMax< T > &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:152
Foam::minMaxMagEqOp::operator()
scalarMinMax & operator()(scalarMinMax &x, const T &y) const
Definition: MinMaxOps.H:255
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::clipOp
Return the value after clipping by the min/max limiter.
Definition: MinMaxOps.H:68
Foam::scalarMinMax
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:117
Foam::minMaxMagOp
Scalar combine the magitude of a value.
Definition: MinMaxOps.H:236
Foam::minMaxMag
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:330
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
Foam::operator>=
bool operator>=(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A same or newer than B.
Definition: IOstreamOption.H:428
Foam::minMaxOp::operator()
MinMax< T > operator()(const T &x, const MinMax< T > &y) const
Definition: MinMaxOps.H:126
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::operator/
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
Definition: dimensionedScalar.C:68
U
U
Definition: pEqn.H:72
Foam::minMaxOp
Combine values and/or MinMax ranges.
Definition: MinMaxOps.H:114
Foam::clip
dimensionSet clip(const dimensionSet &ds1, const dimensionSet &ds2)
Definition: dimensionSet.C:278
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::clipEqOp::operator()
bool operator()(T &val, const MinMax< T > &range) const
Definition: MinMaxOps.H:81
Foam::MinMax::add
MinMax< T > & add(const MinMax &other)
Extend the range to include the other min/max range.
Definition: MinMaxI.H:263
Foam::operator+
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::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:590
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::minMaxOp::operator()
MinMax< T > operator()(const T &x, const T &y) const
Definition: MinMaxOps.H:116
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::clipEqOp
Clip value and assign inplace.
Definition: MinMaxOps.H:79
Foam::operator<
bool operator<(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A older than B.
Definition: IOstreamOption.H:398
Foam::minMax
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:61
Foam::minMaxMagOp::operator()
scalarMinMax operator()(const scalarMinMax &x, const T &y) const
Definition: MinMaxOps.H:238
Foam::MinMax
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: HashSet.H:76
Foam::minMaxMagEqOp::operator()
scalarMinMax & operator()(scalarMinMax &x, const UList< T > &y) const
Definition: MinMaxOps.H:273
Foam::minMaxMagOp::operator()
scalarMinMax operator()(const MinMax< T1 > &x, const MinMax< T2 > &y) const
Definition: MinMaxOps.H:244
Foam::minMaxEqOp
Combine assignment for MinMax range.
Definition: MinMaxOps.H:140
y
scalar y
Definition: LISASMDCalcMethod1.H:14
Foam::operator>
bool operator>(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A newer than B.
Definition: IOstreamOption.H:418