Loading...
Searching...
No Matches
RBFInterpolationTemplates.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 4.0
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7-------------------------------------------------------------------------------
8License
9 This file is part of foam-extend.
10
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
15
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23
24Description
25 RBF interpolation templates
26
27Author
28 Frank Bos, TU Delft. All rights reserved.
29 Dubravko Matijasevic, FSB Zagreb.
30
31\*---------------------------------------------------------------------------*/
32
33#include "RBFInterpolation.H"
34
35// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36
37template<class Type>
38Foam::tmp<Foam::Field<Type >> Foam::RBFInterpolation::interpolate
39(
40 const Field<Type>& ctrlField
41) const
42{
43 // HJ and FB (05 Jan 2009)
44 // Collect the values from ALL control points to all CPUs
45 // Then, each CPU will do interpolation only on local dataPoints_
46 if (ctrlField.size() != controlPoints_.size())
47 {
48 FatalErrorIn
49 (
50 "tmp<Field<Type> > RBFInterpolation::interpolate\n"
51 "(\n"
52 " const Field<Type>& ctrlField\n"
53 ") const"
54 ) << "Incorrect size of source field. Size = " << ctrlField.size()
55 << " nControlPoints = " << controlPoints_.size()
56 << abort(FatalError);
57 }
58
59 tmp<Field<Type >> tresult
60 (
61 new Field<Type>(dataPoints_.size(), pTraits<Type>::zero)
62 );
63 Field<Type>& result = const_cast<Field<Type>&>(tresult());
64 // FB 21-12-2008
65 // 1) Calculate alpha and beta coefficients using the Inverse
66 // 2) Calculate displacements of internal nodes using RBF values,
67 // alpha's and beta's
68 // 3) Return displacements using tresult()
69 const label nControlPoints = controlPoints_.size();
70 const scalarSquareMatrix& mat = this->B();
71 // Determine interpolation coefficients
72 Field<Type> alpha(nControlPoints, pTraits<Type>::zero);
73 Field<Type> beta(4, pTraits<Type>::zero);
74
75 for (label row = 0; row < nControlPoints; row++)
76 {
77 for (label col = 0; col < nControlPoints; col++)
78 {
79 alpha[row] += mat[row][col] * ctrlField[col];
80 }
81 }
82 if (polynomials_)
83 {
84 for
85 (
86 label row = nControlPoints;
87 row < nControlPoints + 4;
88 row++
89 )
90 {
91 for (label col = 0; col < nControlPoints; col++)
92 {
93 beta[row - nControlPoints] += mat[row][col] * ctrlField[col];
94 }
95 }
96 }
97 // Evaluation
98 scalar t;
99 // Algorithmic improvement, Matteo Lombardi. 21/Mar/2011
100 forAll (dataPoints_, flPoint)
101 {
102 // Cut-off function to justify neglecting outer boundary points
103 t = (mag(dataPoints_[flPoint] - focalPoint_) - innerRadius_) /
104 (outerRadius_ - innerRadius_);
105
106 if (t >= 1)
107 {
108 // Increment is zero: w = 0
109 result[flPoint] = 0 * result[flPoint];
110 }
111 else
112 {
113 // Full calculation of weights
114 scalarField weights =
115 RBF_->weights(controlPoints_, dataPoints_[flPoint]);
116 forAll (controlPoints_, i)
117 {
118 result[flPoint] += weights[i] * alpha[i];
119 }
120
121 if (polynomials_)
122 {
123 result[flPoint] +=
124 beta[0]
125 + beta[1] * dataPoints_[flPoint].x()
126 + beta[2] * dataPoints_[flPoint].y()
127 + beta[3] * dataPoints_[flPoint].z();
128 }
129
130 scalar w;
131
132 if (t <= 0)
133 {
134 w = 1.0;
135 }
136 else
137 {
138 w = 1 - sqr(t) * (3 - 2 * t);
139 }
140
141 result[flPoint] = w * result[flPoint];
142 }
143 }
144
145 return tresult;
146}
147
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
forAll(example_CG.gList, solutionI)
Definition CGtest.H:21
tmp< Field< Type > > interpolate(const Field< Type > &ctrlField) const
singVal col(i)
dimensionedScalar & beta
label i
Definition pEqn.H:46