exprOps.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::expressions
28
29Description
30 Operations involving expressions.
31
32SourceFiles
33 exprOps.H
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef exprOps_H
38#define exprOps_H
39
40#include "scalar.H"
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46
47/*---------------------------------------------------------------------------*\
48 Namespace expressions Declarations
49\*---------------------------------------------------------------------------*/
50
51namespace expressions
52{
53
54//- Convert [0-1] values (usually scalars) as false/true
55template<class T>
56struct boolOp
57{
58 bool operator()(const T& val) const
59 {
60 return (0.5 < Foam::mag(val));
61 }
62};
63
64//- Inverse of boolOp()
65template<class T>
67{
68 bool operator()(const T& val) const
69 {
70 return (Foam::mag(val) < 0.5);
71 }
72};
73
74//- Convert to bool, pass-through for bool
75template<>
76struct boolOp<bool>
77{
78 bool operator()(bool val) const
79 {
80 return val;
81 }
82};
83
84//- Inverse of boolOp, no conversion required for bool
85template<>
87{
88 bool operator()(bool val) const
89 {
90 return !val;
91 }
92};
93
94//- Logical 'and', possibly with scalars as (false, true) values
95template<class T>
97{
98 bool operator()(const T& a, const T& b) const
99 {
100 return (boolOp<T>()(a) && boolOp<T>()(b));
101 }
102};
103
104//- Logical 'or', possibly with scalars as (false, true) values
105template<class T>
107{
108 bool operator()(const T& a, const T& b) const
109 {
110 return (boolOp<T>()(a) || boolOp<T>()(b));
111 }
112};
113
114//- Logical 'xor', possibly with scalars as (false, true) values
115template<class T>
117{
118 bool operator()(const T& a, const T& b) const
119 {
120 return (boolOp<T>()(a) != boolOp<T>()(b));
121 }
122};
123
124
125} // End namespace expressions
126
127// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128
129} // End namespace Foam
130
131
132// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133
134#endif
135
136// ************************************************************************* //
const volScalarField & T
bool
Definition: EEqn.H:20
Namespace for OpenFOAM.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
volScalarField & b
Definition: createFields.H:27
Logical 'and', possibly with scalars as (false, true) values.
Definition: exprOps.H:97
bool operator()(const T &a, const T &b) const
Definition: exprOps.H:98
bool operator()(bool val) const
Definition: exprOps.H:88
Inverse of boolOp()
Definition: exprOps.H:67
bool operator()(const T &val) const
Definition: exprOps.H:68
bool operator()(bool val) const
Definition: exprOps.H:78
Convert [0-1] values (usually scalars) as false/true.
Definition: exprOps.H:57
bool operator()(const T &val) const
Definition: exprOps.H:58
Logical 'or', possibly with scalars as (false, true) values.
Definition: exprOps.H:107
bool operator()(const T &a, const T &b) const
Definition: exprOps.H:108
Logical 'xor', possibly with scalars as (false, true) values.
Definition: exprOps.H:117
bool operator()(const T &a, const T &b) const
Definition: exprOps.H:118