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 -------------------------------------------------------------------------------
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::expressions
28 
29 Description
30  Operations involving expressions.
31 
32 SourceFiles
33  exprOps.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef exprOps_H
38 #define exprOps_H
39 
40 #include "scalar.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Namespace expressions Declarations
49 \*---------------------------------------------------------------------------*/
50 
51 namespace expressions
52 {
53 
54 //- Convert [0-1] values (usually scalars) as false/true
55 template<class T>
56 struct boolOp
57 {
58  bool operator()(const T& val) const
59  {
60  return (0.5 < Foam::mag(val));
61  }
62 };
63 
64 //- Inverse of boolOp()
65 template<class T>
66 struct boolNotOp
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
75 template<>
76 struct 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
85 template<>
86 struct boolNotOp<bool>
87 {
88  bool operator()(bool val) const
89  {
90  return !val;
91  }
92 };
93 
94 //- Logical 'and', possibly with scalars as (false, true) values
95 template<class T>
96 struct boolAndOp
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
105 template<class T>
106 struct boolOrOp
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
115 template<class T>
116 struct boolXorOp
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 // ************************************************************************* //
Foam::expressions::boolAndOp
Logical 'and', possibly with scalars as (false, true) values.
Definition: exprOps.H:96
Foam::expressions::boolNotOp
Inverse of boolOp()
Definition: exprOps.H:66
Foam::expressions::boolOrOp::operator()
bool operator()(const T &a, const T &b) const
Definition: exprOps.H:108
Foam::expressions::boolXorOp::operator()
bool operator()(const T &a, const T &b) const
Definition: exprOps.H:118
Foam::expressions::boolOrOp
Logical 'or', possibly with scalars as (false, true) values.
Definition: exprOps.H:106
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::expressions::boolXorOp
Logical 'xor', possibly with scalars as (false, true) values.
Definition: exprOps.H:116
Foam::expressions::boolNotOp::operator()
bool operator()(const T &val) const
Definition: exprOps.H:68
Foam::expressions::boolAndOp::operator()
bool operator()(const T &a, const T &b) const
Definition: exprOps.H:98
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
scalar.H
Foam::expressions::boolOp
Convert [0-1] values (usually scalars) as false/true.
Definition: exprOps.H:56
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::expressions::boolOp::operator()
bool operator()(const T &val) const
Definition: exprOps.H:58
bool
bool
Definition: EEqn.H:20
Foam::expressions::boolOp< bool >::operator()
bool operator()(bool val) const
Definition: exprOps.H:78
Foam::expressions::boolNotOp< bool >::operator()
bool operator()(bool val) const
Definition: exprOps.H:88