1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 RBF interpolation templates
29 Frank Bos, TU Delft. All rights reserved.
30 Dubravko Matijasevic, FSB Zagreb.
32 \*---------------------------------------------------------------------------*/
34 #include "RBFInterpolation.H"
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
39 Foam::tmp<Foam::Field<Type> > Foam::RBFInterpolation::interpolate
41 const Field<Type>& ctrlField
44 // HJ and FB (05 Jan 2009)
45 // Collect the values from ALL control points to all CPUs
46 // Then, each CPU will do interpolation only on local allPoints_
48 if (ctrlField.size() != controlPoints_.size())
52 "tmp<Field<Type> > RBFInterpolation::interpolate\n"
54 " const Field<Type>& ctrlField\n"
56 ) << "Incorrect size of source field. Size = " << ctrlField.size()
57 << " nControlPoints = " << controlPoints_.size()
61 tmp<Field<Type> > tresult
63 new Field<Type>(allPoints_.size(), pTraits<Type>::zero)
66 Field<Type>& result = tresult();
69 // 1) Calculate alpha and beta coefficients using the Inverse
70 // 2) Calculate displacements of internal nodes using RBF values,
72 // 3) Return displacements using tresult()
74 const label nControlPoints = controlPoints_.size();
75 const scalarSquareMatrix& mat = this->B();
77 // Determine interpolation coefficients
78 Field<Type> alpha(nControlPoints, pTraits<Type>::zero);
79 Field<Type> beta(4, pTraits<Type>::zero);
81 for (label row = 0; row < nControlPoints; row++)
83 for (label col = 0; col < nControlPoints; col++)
85 alpha[row] += mat[row][col]*ctrlField[col];
93 label row = nControlPoints;
94 row < nControlPoints + 4;
98 for (label col = 0; col < nControlPoints; col++)
100 beta[row - nControlPoints] += mat[row][col]*ctrlField[col];
108 // Algorithmic improvement, Matteo Lombardi. 21/Mar/2011
110 forAll (allPoints_, flPoint)
112 // Cut-off function to justify neglecting outer boundary points
113 t = (Foam::mag(allPoints_[flPoint] - focalPoint_) - innerRadius_)/
114 (outerRadius_ - innerRadius_);
118 // Increment is zero: w = 0
119 result[flPoint] = 0*result[flPoint];
123 // Full calculation of weights
124 scalarField weights =
125 RBF_->weights(controlPoints_, allPoints_[flPoint]);
127 forAll (controlPoints_, i)
129 result[flPoint] += weights[i]*alpha[i];
136 + beta[1]*allPoints_[flPoint].x()
137 + beta[2]*allPoints_[flPoint].y()
138 + beta[3]*allPoints_[flPoint].z();
149 w = 1 - sqr(t)*(3-2*t);
152 result[flPoint] = w*result[flPoint];
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //