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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
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 
54 inline Foam::label Foam::lumpedPointInterpolator::nearest() const
55 {
56  return nearest_;
57 }
58 
59 
60 inline Foam::label Foam::lumpedPointInterpolator::next() const
61 {
62  return next1_;
63 }
64 
65 
66 inline Foam::label Foam::lumpedPointInterpolator::next1() const
67 {
68  return next1_;
69 }
70 
71 
72 inline Foam::label Foam::lumpedPointInterpolator::next2() const
73 {
74  return next2_;
75 }
76 
77 
78 inline Foam::scalar Foam::lumpedPointInterpolator::weight0() const
79 {
80  return scalar(1) - weight1_ - weight2_;
81 }
82 
83 
84 inline Foam::scalar Foam::lumpedPointInterpolator::weight1() const
85 {
86  return weight1_;
87 }
88 
89 
90 inline Foam::scalar Foam::lumpedPointInterpolator::weight2() const
91 {
92  return weight2_;
93 }
94 
95 
96 inline 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 
169 template<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 // ************************************************************************* //
Foam::lumpedPointInterpolator::weight2
scalar weight2() const
Definition: lumpedPointInterpolatorI.H:90
Foam::lumpedPointInterpolator::interpolate
T interpolate(const UList< T > &input) const
Linear interpolated value between nearest and next locations.
Definition: lumpedPointInterpolatorI.H:170
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::Barycentric2D
Templated 2D Barycentric derived from VectorSpace. Has 3 components, one of which is redundant.
Definition: Barycentric2D.H:54
Foam::lumpedPointInterpolator::nearest
label nearest() const
The nearest control point, or -1 if invalid.
Definition: lumpedPointInterpolatorI.H:54
Foam::lumpedPointInterpolator::valid
bool valid() const
Valid if there is an associated nearest point.
Definition: lumpedPointInterpolatorI.H:48
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::lumpedPointInterpolator::next
label next() const
The first neighbour control point - identical to next1()
Definition: lumpedPointInterpolatorI.H:60
Foam::lumpedPointInterpolator::next1
label next1() const
The first neighbour control point, or -1 if invalid.
Definition: lumpedPointInterpolatorI.H:66
Foam::lumpedPointInterpolator::lumpedPointInterpolator
lumpedPointInterpolator()
Default construct, with zero weighting and invalid ids.
Definition: lumpedPointInterpolatorI.H:30
Foam::lumpedPointInterpolator::set
void set(const triFace &ids, const barycentric2D &weights)
Assign all control points and their weights.
Definition: lumpedPointInterpolatorI.H:155
Foam::triFace
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:69
Foam::lumpedPointInterpolator::weight0
scalar weight0() const
The weighting for the nearest point.
Definition: lumpedPointInterpolatorI.H:78
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::lumpedPointInterpolator::weight1
scalar weight1() const
Definition: lumpedPointInterpolatorI.H:84
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Foam::lumpedPointInterpolator
A simple linear interpolator between two locations, which are referenced by index.
Definition: lumpedPointInterpolator.H:59
Foam::lumpedPointInterpolator::next2
label next2() const
The second neighbour control point, or -1 if invalid.
Definition: lumpedPointInterpolatorI.H:72