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
83 if (polynomials_)
84 {
85 for
86 (
87 label row = nControlPoints;
88 row < nControlPoints + 4;
89 row++
90 )
91 {
92 for (label col = 0; col < nControlPoints; col++)
93 {
94 beta[row - nControlPoints] += mat[row][col] * ctrlField[col];
95 }
96 }
97 }
98
99 // Evaluation
100 scalar t;
101 // Algorithmic improvement, Matteo Lombardi. 21/Mar/2011
102 forAll (dataPoints_, flPoint)
103 {
104 // Cut-off function to justify neglecting outer boundary points
105 t = (mag(dataPoints_[flPoint] - focalPoint_) - innerRadius_) /
106 (outerRadius_ - innerRadius_);
107
108 if (t >= 1)
109 {
110 // Increment is zero: w = 0
111 result[flPoint] = 0 * result[flPoint];
112 }
113 else
114 {
115 // Full calculation of weights
116 scalarField weights =
117 RBF_->weights(controlPoints_, dataPoints_[flPoint]);
118 forAll (controlPoints_, i)
119 {
120 result[flPoint] += weights[i] * alpha[i];
121 }
122
123 if (polynomials_)
124 {
125 result[flPoint] +=
126 beta[0]
127 + beta[1] * dataPoints_[flPoint].x()
128 + beta[2] * dataPoints_[flPoint].y()
129 + beta[3] * dataPoints_[flPoint].z();
130 }
131
132 scalar w;
133
134 if (t <= 0)
135 {
136 w = 1.0;
137 }
138 else
139 {
140 w = 1 - sqr(t) * (3 - 2 * t);
141 }
142
143 result[flPoint] = w * result[flPoint];
144 }
145 }
146 return tresult;
147}
148
149
150// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151
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