fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / interpolations / RBFInterpolation / RBFInterpolation.C
blobd82cfa85baa4f11e2c48a1cf12792f572ee00fb0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Author
26     Frank Bos, TU Delft.  All rights reserved.
27     Dubravko Matijasevic, FSB Zagreb.
29 \*---------------------------------------------------------------------------*/
31 #include "RBFInterpolation.H"
32 #include "demandDrivenData.H"
34 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
36 const Foam::scalarSquareMatrix& Foam::RBFInterpolation::B() const
38     if (!BPtr_)
39     {
40         calcB();
41     }
43     return *BPtr_;
47 void Foam::RBFInterpolation::calcB() const
49     // Determine inverse of boundary connectivity matrix
50     label polySize(4);
52     if (!polynomials_)
53     {
54         polySize = 0;
55     }
57     // Fill Nb x Nb matrix
58     simpleMatrix<scalar> A(controlPoints_.size()+polySize);
60     const label nControlPoints = controlPoints_.size();
61     for (label i = 0; i < nControlPoints; i++)
62     {
63         scalarField weights = RBF_->weights(controlPoints_, controlPoints_[i]);
65         for (label col = 0; col < nControlPoints; col++)
66         {
67             A[i][col] = weights[col];
68         }
69     }
71     if (polynomials_)
72     {
73         for
74         (
75             label row = nControlPoints;
76             row < nControlPoints + 1;
77             row++
78         )
79         {
80             for (label col = 0; col < nControlPoints; col++)
81             {
82                 A[col][row] = 1.0;
83                 A[row][col] = 1.0;
84             }
85         }
87         // Fill in X components of polynomial part of matrix
88         for
89         (
90             label row = nControlPoints + 1;
91             row < nControlPoints + 2;
92             row++
93         )
94         {
95             for (label col = 0; col < nControlPoints; col++)
96             {
97                 A[col][row] = controlPoints_[col].x();
98                 A[row][col] = controlPoints_[col].x();
99             }
100         }
102         // Fill in Y components of polynomial part of matrix
103         for
104         (
105             label row = nControlPoints + 2;
106             row < nControlPoints + 3;
107             row++
108         )
109         {
110             for (label col = 0; col < nControlPoints; col++)
111             {
112                 A[col][row] = controlPoints_[col].y();
113                 A[row][col] = controlPoints_[col].y();
114             }
115         }
116         // Fill in Z components of polynomial part of matrix
117         for
118         (
119             label row = nControlPoints + 3;
120             row < nControlPoints + 4;
121             row++
122         )
123         {
124             for (label col = 0; col < nControlPoints; col++)
125             {
126                 A[col][row] = controlPoints_[col].z();
127                 A[row][col] = controlPoints_[col].z();
128             }
129         }
131         // Fill 4x4 zero part of matrix
132         for
133         (
134             label row = nControlPoints;
135             row < nControlPoints + 4;
136             row++
137         )
138         {
139             for
140             (
141                 label col = nControlPoints;
142                 col < nControlPoints + 4;
143                 col++
144             )
145             {
146                 A[row][col] = 0.0;
147             }
148         }
149     }
151     // HJ and FB (05 Jan 2009)
152     // Collect ALL control points from ALL CPUs
153     // Create an identical inverse for all CPUs
155     Info<< "Inverting RBF motion matrix" << endl;
157     BPtr_ = new scalarSquareMatrix(A.LUinvert());
161 void Foam::RBFInterpolation::clearOut()
163     deleteDemandDrivenData(BPtr_);
167 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
169 Foam::RBFInterpolation::RBFInterpolation
171     const dictionary& dict,
172     const vectorField& controlPoints,
173     const vectorField& allPoints
176     dict_(dict),
177     controlPoints_(controlPoints),
178     allPoints_(allPoints),
179     RBF_(RBFFunction::New(word(dict.lookup("RBF")), dict)),
180     BPtr_(NULL),
181     focalPoint_(dict.lookup("focalPoint")),
182     innerRadius_(readScalar(dict.lookup("innerRadius"))),
183     outerRadius_(readScalar(dict.lookup("outerRadius"))),
184     polynomials_(dict.lookup("polynomials"))
188 Foam::RBFInterpolation::RBFInterpolation
190     const RBFInterpolation& rbf
193     dict_(rbf.dict_),
194     controlPoints_(rbf.controlPoints_),
195     allPoints_(rbf.allPoints_),
196     RBF_(rbf.RBF_->clone()),
197     BPtr_(NULL),
198     focalPoint_(rbf.focalPoint_),
199     innerRadius_(rbf.innerRadius_),
200     outerRadius_(rbf.outerRadius_),
201     polynomials_(rbf.polynomials_)
205 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
207 Foam::RBFInterpolation::~RBFInterpolation()
209     clearOut();
213 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
215 void Foam::RBFInterpolation::movePoints()
217     clearOut();
221 // ************************************************************************* //