scalarOps.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  Functors that are scalar-specific.
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef scalarOps_H
35 #define scalarOps_H
36 
37 #include "scalar.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 //- Hypot operation (scalar only)
47 template<class T>
48 struct hypotOp
49 {
50  T operator()(const T& x, const T& y) const
51  {
52  return std::hypot(x, y);
53  }
54 };
55 
56 
57 //- Scalar division with divide-by-zero protection
58 // Uses stabilise, but could also handle as per modulo and return zero
59 template<class T, class T2=Foam::scalar>
60 struct scalarDivideOp
61 {
62  T operator()(const T& x, const T2& y) const
63  {
64  return (x / stabilise(y, pTraits<T2>::vsmall));
65  }
66 };
67 
68 
69 //- Floating point modulo operation with divide-by-zero protection
70 template<class T, class T2=Foam::scalar>
71 struct scalarModuloOp
72 {
73  T operator()(const T& x, const T2& y) const
74  {
76  {
77  return pTraits<T>::zero;
78  }
79  return std::fmod(x, y);
80  }
81 };
82 
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 } // End namespace Foam
87 
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 
90 #endif
91 
92 // ************************************************************************* //
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
T operator()(const T &x, const T2 &y) const
Definition: scalarOps.H:74
Scalar division with divide-by-zero protection.
Definition: scalarOps.H:59
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
dimensionedScalar stabilise(const dimensionedScalar &x, const dimensionedScalar &y)
scalar y
Hypot operation (scalar only)
Definition: scalarOps.H:44
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
T operator()(const T &x, const T &y) const
Definition: scalarOps.H:46
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
T operator()(const T &x, const T2 &y) const
Definition: scalarOps.H:61
Namespace for OpenFOAM.
Floating point modulo operation with divide-by-zero protection.
Definition: scalarOps.H:72