scalarPredicatesI.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) 2018-2022 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
26\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29
31(
32 const word& opName,
33 const scalar opVal,
34 const scalar tol
35)
36{
37 return operation(opNames[opName], opVal, tol);
38}
39
40
42(
43 const Tuple2<word, scalar>& op,
44 const scalar tol
45)
46{
47 return operation(opNames[op.first()], op.second(), tol);
48}
49
50
52(
53 const std::pair<word, scalar>& op,
54 const scalar tol
55)
56{
57 return operation(opNames[op.first], op.second, tol);
58}
59
60
61// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62
64(
65 const scalar value,
66 label pos
67) const
68{
69 return (this->find(value, pos) >= 0);
70}
71
72
73inline bool Foam::predicates::scalars::match(const scalar value) const
74{
75 return this->matchAny(value);
76}
77
78
79inline bool Foam::predicates::scalars::matchAny(const scalar value) const
80{
81 for (const unary& test : *this)
82 {
83 if (test(value))
84 {
85 return true;
86 }
87 }
88
89 return false;
90}
91
92
93inline bool Foam::predicates::scalars::matchAll(const scalar value) const
94{
95 for (const unary& test : *this)
96 {
97 if (!test(value))
98 {
99 return false;
100 }
101 }
102
103 return (!this->empty());
104}
105
106
108(
109 const scalar value
110) const
111{
112 labelList indices(this->size());
113
114 label i = 0, count = 0;
115 for (const unary& test : *this)
116 {
117 if (test(value))
118 {
119 indices[count] = i;
120 ++count;
121 }
122 ++i;
123 }
124 indices.resize(count);
125
126 return indices;
127}
128
129
131(
132 const UList<scalar>& input,
133 const bool invert
134) const
135{
136 const label len = input.size();
137
138 labelList indices(len);
139
140 label count = 0;
141 for (label i=0; i < len; ++i)
142 {
143 if (match(input[i]) ? !invert : invert)
144 {
145 indices[count] = i;
146 ++count;
147 }
148 }
149 indices.resize(count);
150
151 return indices;
152}
153
154
155// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
156
157inline bool Foam::predicates::scalars::operator()(const scalar value) const
158{
159 return this->found(value);
160}
161
162
163// ************************************************************************* //
bool found
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
const T1 & first() const noexcept
Return first.
Definition: Tuple2.H:118
const T2 & second() const noexcept
Return second.
Definition: Tuple2.H:130
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Ostream & operator()() const
Output stream (master only).
Definition: ensightCaseI.H:74
std::function< bool(Foam::scalar)> unary
The unary function type for testing a scalar.
static unary operation(const opType op, const scalar opVal, const scalar tol=VSMALL)
Standard comparison method by type.
static const Enum< opType > opNames
Names for the opType enumeration.
bool matchAny(const scalar value) const
Match any condition in the list.
labelList matching(const scalar value) const
Extract list indices for all matches.
bool match(const scalar value) const
Match any condition in the list.
bool matchAll(const scalar value) const
Match all conditions in the list.
A class for handling words, derived from Foam::string.
Definition: word.H:68
dimensionedScalar pos(const dimensionedScalar &ds)
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:36