1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "RBFMotionSolver.H"
27 #include "addToRunTimeSelectionTable.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(RBFMotionSolver, 0);
35 addToRunTimeSelectionTable
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 void Foam::RBFMotionSolver::makeControlIDs()
47 // Points that are neither on moving nor on static patches
48 // will be marked with 0
49 labelList markedPoints(mesh().nPoints(), 0);
51 // Mark all points on moving patches with 1
52 label nMovingPoints = 0;
54 forAll (movingPatches_, patchI)
56 // Find the patch in boundary
58 mesh().boundaryMesh().findPatchID(movingPatches_[patchI]);
62 FatalErrorIn("void RBFMotionSolver::makeControlIDs()")
63 << "Patch " << movingPatches_[patchI] << " not found. "
64 << "valid patch names: " << mesh().boundaryMesh().names()
68 const labelList& mp = mesh().boundaryMesh()[patchIndex].meshPoints();
72 markedPoints[mp[i]] = 1;
77 // Mark moving points and select control points from moving patches
78 movingIDs_.setSize(nMovingPoints);
80 Info<< "Total points on moving boundaries: " << nMovingPoints << endl;
82 const pointField& points = mesh().points();
84 // Re-use counter to count moving points
85 // Note: the control points also hold static points in the second part
86 // of the list if static patches are included in the RBF
90 // Count moving points first
91 forAll (markedPoints, i)
93 if (markedPoints[i] == 1)
95 // Grab internal point
96 movingIDs_[nMovingPoints] = i;
101 movingIDs_.setSize(nMovingPoints);
103 // Actual location of moving points will be set later on request
105 movingPoints_.setSize(nMovingPoints, vector::zero);
107 // Mark all points on static patches with -1
108 label nStaticPoints = 0;
110 forAll (staticPatches_, patchI)
112 // Find the patch in boundary
114 mesh().boundaryMesh().findPatchID(staticPatches_[patchI]);
118 FatalErrorIn("void RBFMotionSolver::makeControlPoints()")
119 << "Patch " << staticPatches_[patchI] << " not found. "
120 << "valid patch names: " << mesh().boundaryMesh().names()
121 << abort(FatalError);
124 const labelList& mp = mesh().boundaryMesh()[patchIndex].meshPoints();
128 markedPoints[mp[i]] = -1;
133 Info<< "Total points on static boundaries: " << nStaticPoints << endl;
134 staticIDs_.setSize(nStaticPoints);
139 // Count total number of control points
140 forAll (markedPoints, i)
142 if (markedPoints[i] == -1)
144 staticIDs_[nStaticPoints] = i;
149 staticIDs_.setSize(nStaticPoints);
151 // Control IDs also potentially include points on static patches
153 controlIDs_.setSize(movingIDs_.size() + staticIDs_.size());
154 motion_.setSize(controlIDs_.size(), vector::zero);
156 label nControlPoints = 0;
158 forAll (movingPatches_, patchI)
160 // Find the patch in boundary
162 mesh().boundaryMesh().findPatchID(movingPatches_[patchI]);
164 const labelList& mp = mesh().boundaryMesh()[patchIndex].meshPoints();
168 label pickedPoint = 0;
169 pickedPoint < mp.size();
170 pickedPoint += coarseningRatio_
173 // Pick point as control point
174 controlIDs_[nControlPoints] = mp[pickedPoint];
176 // Mark the point as picked
177 markedPoints[mp[pickedPoint]] = 2;
182 Info<< "Selected " << nControlPoints
183 << " control points on moving boundaries" << endl;
185 if (includeStaticPatches_)
187 forAll (staticPatches_, patchI)
189 // Find the patch in boundary
191 mesh().boundaryMesh().findPatchID(staticPatches_[patchI]);
193 const labelList& mp =
194 mesh().boundaryMesh()[patchIndex].meshPoints();
198 label pickedPoint = 0;
199 pickedPoint < mp.size();
200 pickedPoint += coarseningRatio_
203 // Pick point as control point
204 controlIDs_[nControlPoints] = mp[pickedPoint];
206 // Mark the point as picked
207 markedPoints[mp[pickedPoint]] = 2;
212 Info<< "Selected " << nControlPoints
213 << " total control points" << endl;
216 // Resize control IDs
217 controlIDs_.setSize(nControlPoints);
219 // Pick up point locations
220 controlPoints_.setSize(nControlPoints);
222 // Set control points
223 forAll (controlIDs_, i)
225 controlPoints_[i] = points[controlIDs_[i]];
228 // Pick up all internal points
229 internalIDs_.setSize(points.size());
230 internalPoints_.setSize(points.size());
232 // Count internal points
233 label nInternalPoints = 0;
235 forAll (markedPoints, i)
237 if (markedPoints[i] == 0)
239 // Grab internal point
240 internalIDs_[nInternalPoints] = i;
241 internalPoints_[nInternalPoints] = points[i];
246 Info << "Number of internal points: " << nInternalPoints << endl;
249 internalIDs_.setSize(nInternalPoints);
250 internalPoints_.setSize(nInternalPoints);
254 void Foam::RBFMotionSolver::setMovingPoints() const
256 const pointField& points = mesh().points();
259 forAll (movingIDs_, i)
261 movingPoints_[i] = points[movingIDs_[i]];
266 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
268 Foam::RBFMotionSolver::RBFMotionSolver
270 const polyMesh& mesh,
275 movingPatches_(lookup("movingPatches")),
276 staticPatches_(lookup("staticPatches")),
277 coarseningRatio_(readLabel(lookup("coarseningRatio"))),
278 includeStaticPatches_(lookup("includeStaticPatches")),
279 frozenInterpolation_(lookup("frozenInterpolation")),
290 subDict("interpolation"),
299 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
301 Foam::RBFMotionSolver::~RBFMotionSolver()
305 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
307 void Foam::RBFMotionSolver::setMotion(const vectorField& m)
309 if (m.size() != movingIDs_.size())
313 "void RBFMotionSolver::setMotion(const vectorField& m)"
314 ) << "Incorrect size of motion points: m = " << m.size()
315 << " movingIDs = " << movingIDs_.size()
316 << abort(FatalError);
319 // Motion of static points is zero and moving points are first
320 // in the list. HJ, 24/Mar/2011
321 motion_ = vector::zero;
328 if (!frozenInterpolation_)
330 // Set control points
331 const pointField& points = mesh().points();
333 forAll (controlIDs_, i)
335 controlPoints_[i] = points[controlIDs_[i]];
338 // Re-calculate interpolation
339 interpolation_.movePoints();
344 const Foam::vectorField& Foam::RBFMotionSolver::movingPoints() const
346 // Update moving points based on current mesh
349 return movingPoints_;
353 Foam::tmp<Foam::pointField> Foam::RBFMotionSolver::curPoints() const
355 // Prepare new points: same as old point
356 tmp<pointField> tcurPoints
358 new vectorField(mesh().nPoints(), vector::zero)
360 pointField& curPoints = tcurPoints();
362 // Add motion to existing points
364 // 1. Insert prescribed motion of moving points
365 forAll (movingIDs_, i)
367 curPoints[movingIDs_[i]] = motion_[i];
370 // 2. Insert zero motion of static points
371 forAll (staticIDs_, i)
373 curPoints[staticIDs_[i]] = vector::zero;
376 // Set motion of control
377 vectorField motionOfControl(controlIDs_.size());
379 // 2. Capture positions of control points
380 forAll (controlIDs_, i)
382 motionOfControl[i] = curPoints[controlIDs_[i]];
385 // Call interpolation
386 vectorField interpolatedMotion =
387 interpolation_.interpolate(motionOfControl);
389 // 3. Insert RBF interpolated motion
390 forAll (internalIDs_, i)
392 curPoints[internalIDs_[i]] = interpolatedMotion[i];
395 // 4. Add old point positions
396 curPoints += mesh().points();
398 twoDCorrectPoints(tcurPoints());
404 void Foam::RBFMotionSolver::solve()
408 void Foam::RBFMotionSolver::updateMesh(const mapPolyMesh&)
410 // Recalculate control point IDs
415 // ************************************************************************* //