lumpedPointInterpolatorI.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-2020 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// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29
31:
33{}
34
35
37:
38 nearest_(id),
39 next1_(id),
40 next2_(id),
41 weight1_(Zero),
42 weight2_(Zero)
43{}
44
45
46// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
47
49{
50 return nearest_ != -1;
51}
52
53
55{
56 return nearest_;
57}
58
59
60inline Foam::label Foam::lumpedPointInterpolator::next() const
61{
62 return next1_;
63}
64
65
66inline Foam::label Foam::lumpedPointInterpolator::next1() const
67{
68 return next1_;
69}
70
71
72inline Foam::label Foam::lumpedPointInterpolator::next2() const
73{
74 return next2_;
75}
76
77
78inline Foam::scalar Foam::lumpedPointInterpolator::weight0() const
79{
80 return scalar(1) - weight1_ - weight2_;
81}
82
83
84inline Foam::scalar Foam::lumpedPointInterpolator::weight1() const
85{
86 return weight1_;
87}
88
89
90inline Foam::scalar Foam::lumpedPointInterpolator::weight2() const
91{
92 return weight2_;
93}
94
95
96inline void Foam::lumpedPointInterpolator::nearest(const label id)
97{
98 nearest_ = id;
99 next(id, Zero);
100}
101
102
104(
105 const label id,
106 scalar weight
107)
108{
109 if (weight < scalar(0))
110 {
111 weight = 0;
112 }
113 else if (weight > scalar(1))
114 {
115 weight = 1;
116 }
117
118 next1_ = id;
119 next2_ = id;
120 weight1_ = weight;
121 weight2_ = Zero;
122}
123
124
126(
127 const label id,
128 scalar weight,
129 const label position
130)
131{
132 if (weight < scalar(0))
133 {
134 weight = 0;
135 }
136 else if (weight > scalar(1))
137 {
138 weight = 1;
139 }
140
141 if (!position)
142 {
143 next1_ = id;
144 weight1_ = weight;
145 }
146 else
147 {
148 next2_ = id;
149 weight2_ = weight;
150 }
151}
152
153
155(
156 const triFace& ids,
157 const barycentric2D& weights
158)
159{
160 nearest_ = ids[0];
161 next1_ = ids[1];
162 next2_ = ids[2];
163
164 weight1_ = weights[1];
165 weight2_ = weights[2];
166}
167
168
169template<class T>
171{
172 if (nearest_ == -1)
173 {
174 return Zero;
175 }
176 else if (next1_ == -1 || next1_ == nearest_)
177 {
178 return input[nearest_];
179 }
180
181 return
182 (
183 input[nearest_] * (1-weight1_-weight2_)
184 + input[next1_] * (weight1_)
185 + input[next2_] * (weight2_)
186 );
187}
188
189
190// ************************************************************************* //
Templated 2D Barycentric derived from VectorSpace. Has 3 components, one of which is redundant.
Definition: Barycentric2D.H:57
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
A simple linear interpolator between two locations, which are referenced by index.
bool valid() const
Valid if there is an associated nearest point.
scalar weight0() const
The weighting for the nearest point.
label next2() const
The second neighbour control point, or -1 if invalid.
lumpedPointInterpolator()
Default construct, with zero weighting and invalid ids.
label nearest() const
The nearest control point, or -1 if invalid.
label next1() const
The first neighbour control point, or -1 if invalid.
label next() const
The first neighbour control point - identical to next1()
bool interpolate() const noexcept
Same as isPointData()
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:72
bool set() const
Are all the vector set.
Definition: triadI.H:76
const volScalarField & T
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131