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-------------------------------------------------------------------------------
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 Functors that are scalar-specific.
31
32\*---------------------------------------------------------------------------*/
33
34#ifndef scalarOps_H
35#define scalarOps_H
36
37#include "scalar.H"
38
39// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40
41namespace Foam
42{
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46//- Hypot operation (scalar only)
47template<class T>
48struct 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
59template<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
70template<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// ************************************************************************* //
scalar y
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
const volScalarField & T
Namespace for OpenFOAM.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
dimensionedScalar stabilise(const dimensionedScalar &x, const dimensionedScalar &y)
Hypot operation (scalar only)
Definition: scalarOps.H:49
T operator()(const T &x, const T &y) const
Definition: scalarOps.H:50
A non-counting (dummy) refCount.
Definition: refCount.H:59
Scalar division with divide-by-zero protection.
Definition: scalarOps.H:61
T operator()(const T &x, const T2 &y) const
Definition: scalarOps.H:62
Floating point modulo operation with divide-by-zero protection.
Definition: scalarOps.H:72
T operator()(const T &x, const T2 &y) const
Definition: scalarOps.H:73