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>
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>
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 // ************************************************************************* //
Foam::hypotOp
Hypot operation (scalar only)
Definition: scalarOps.H:48
Foam::hypot
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:327
Foam::scalarModuloOp
Floating point modulo operation with divide-by-zero protection.
Definition: scalarOps.H:71
Foam::stabilise
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
Definition: DimensionedScalarField.C:43
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
scalar.H
Foam::scalarDivideOp
Scalar division with divide-by-zero protection.
Definition: scalarOps.H:60
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::hypotOp::operator()
T operator()(const T &x, const T &y) const
Definition: scalarOps.H:50
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::scalarModuloOp::operator()
T operator()(const T &x, const T2 &y) const
Definition: scalarOps.H:73
Foam::scalarDivideOp::operator()
T operator()(const T &x, const T2 &y) const
Definition: scalarOps.H:62
y
scalar y
Definition: LISASMDCalcMethod1.H:14