1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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
25 \*---------------------------------------------------------------------------*/
27 #include "displacementComponentLaplacianFvMotionSolver.H"
28 #include "motionDiffusivity.H"
29 #include "fvmLaplacian.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "mapPolyMesh.H"
32 #include "volPointInterpolation.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(displacementComponentLaplacianFvMotionSolver, 0);
40 addToRunTimeSelectionTable
43 displacementComponentLaplacianFvMotionSolver,
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 Foam::direction Foam::displacementComponentLaplacianFvMotionSolver::cmpt
60 else if (cmptName == "y")
64 else if (cmptName == "z")
72 "displacementComponentLaplacianFvMotionSolver::"
73 "displacementComponentLaplacianFvMotionSolver"
74 "(const polyMesh& mesh, Istream& msData)"
75 ) << "Given component name " << cmptName << " should be x, y or z"
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85 Foam::displacementComponentLaplacianFvMotionSolver::
86 displacementComponentLaplacianFvMotionSolver
94 cmpt_(cmpt(cmptName_)),
103 polyMesh::meshSubDir,
115 "pointDisplacement" + cmptName_,
116 fvMesh_.time().timeName(),
121 pointMesh::New(fvMesh_)
127 "cellDisplacement" + cmptName_,
128 mesh.time().timeName(),
130 IOobject::READ_IF_PRESENT,
137 pointDisplacement_.dimensions(),
140 cellMotionBoundaryTypes<scalar>(pointDisplacement_.boundaryField())
142 pointLocation_(NULL),
145 motionDiffusivity::New(*this, lookup("diffusivity"))
149 found("frozenPointsZone")
150 ? fvMesh_.pointZones().findZoneID(lookup("frozenPointsZone"))
157 fvMesh_.time().timeName(),
165 Info<< "displacementComponentLaplacianFvMotionSolver:" << nl
166 << " diffusivity : " << diffusivityPtr_().type() << nl
167 << " frozenPoints zone : " << frozenPointsZone_ << endl;
177 pointMesh::New(fvMesh_)
183 Info<< "displacementComponentLaplacianFvMotionSolver :"
184 << " Read pointVectorField "
185 << io.name() << " to be used for boundary conditions on points."
187 << "Boundary conditions:"
188 << pointLocation_().boundaryField().types() << endl;
194 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
196 Foam::displacementComponentLaplacianFvMotionSolver::
197 ~displacementComponentLaplacianFvMotionSolver()
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
203 Foam::tmp<Foam::pointField>
204 Foam::displacementComponentLaplacianFvMotionSolver::curPoints() const
206 volPointInterpolation::New(fvMesh_).interpolate
212 if (pointLocation_.valid())
216 Info<< "displacementComponentLaplacianFvMotionSolver : applying "
217 << " boundary conditions on " << pointLocation_().name()
218 << " to new point location."
222 // Apply pointLocation_ b.c. to mesh points.
224 pointLocation_().internalField() = fvMesh_.points();
226 pointLocation_().internalField().replace
229 points0_ + pointDisplacement_.internalField()
232 pointLocation_().correctBoundaryConditions();
234 // Implement frozen points
235 if (frozenPointsZone_ != -1)
237 const pointZone& pz = fvMesh_.pointZones()[frozenPointsZone_];
241 label pointI = pz[i];
243 pointLocation_()[pointI][cmpt_] = points0_[pointI];
247 twoDCorrectPoints(pointLocation_().internalField());
249 return tmp<pointField>(pointLocation_().internalField());
253 tmp<pointField> tcurPoints(new pointField(fvMesh_.points()));
258 points0_ + pointDisplacement_.internalField()
261 // Implement frozen points
262 if (frozenPointsZone_ != -1)
264 const pointZone& pz = fvMesh_.pointZones()[frozenPointsZone_];
268 label pointI = pz[i];
270 tcurPoints()[pointI][cmpt_] = points0_[pointI];
274 twoDCorrectPoints(tcurPoints());
281 void Foam::displacementComponentLaplacianFvMotionSolver::solve()
283 // The points have moved so before interpolation update
284 // the fvMotionSolver accordingly
285 movePoints(fvMesh_.points());
287 diffusivityPtr_->correct();
288 pointDisplacement_.boundaryField().updateCoeffs();
294 diffusivityPtr_->operator()(),
296 "laplacian(diffusivity,cellDisplacement)"
302 void Foam::displacementComponentLaplacianFvMotionSolver::updateMesh
304 const mapPolyMesh& mpm
307 fvMotionSolver::updateMesh(mpm);
309 // Map points0_. Bit special since we somehow have to come up with
310 // a sensible points0 position for introduced points.
311 // Find out scaling between points0 and current points
313 // Get the new points either from the map or the mesh
314 const scalarField points
316 mpm.hasMotionPoints()
317 ? mpm.preMotionPoints().component(cmpt_)
318 : fvMesh_.points().component(cmpt_)
321 // Get extents of points0 and points and determine scale
323 (gMax(points0_)-gMin(points0_))
324 /(gMax(points)-gMin(points));
326 scalarField newPoints0(mpm.pointMap().size());
328 forAll(newPoints0, pointI)
330 label oldPointI = mpm.pointMap()[pointI];
334 label masterPointI = mpm.reversePointMap()[oldPointI];
336 if (masterPointI == pointI)
338 newPoints0[pointI] = points0_[oldPointI];
342 // New point. Assume motion is scaling.
345 + scale*(points[pointI]-points[masterPointI]);
352 "displacementLaplacianFvMotionSolver::updateMesh"
353 "(const mapPolyMesh& mpm)"
354 ) << "Cannot work out coordinates of introduced vertices."
355 << " New vertex " << pointI << " at coordinate "
356 << points[pointI] << exit(FatalError);
359 points0_.transfer(newPoints0);
361 // Update diffusivity. Note two stage to make sure old one is de-registered
362 // before creating/registering new one.
363 diffusivityPtr_.reset(NULL);
364 diffusivityPtr_ = motionDiffusivity::New(*this, lookup("diffusivity"));
368 // ************************************************************************* //