Loading...
Searching...
No Matches
elasticityMotionSolver.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2007-2023 PCOpt/NTUA
9 Copyright (C) 2013-2023 FOSS GP
10 Copyright (C) 2019 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28\*---------------------------------------------------------------------------*/
29
31#include "motionInterpolation.H"
32#include "motionDiffusivity.H"
33#include "wallDist.H"
35#include "fvMatrices.H"
36#include "fvcDiv.H"
37#include "fvmDiv.H"
38#include "fvmDiv.H"
39#include "fvmLaplacian.H"
40#include "surfaceInterpolate.H"
43// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44
45namespace Foam
46{
48
50 (
54 );
55}
56
57
58// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
59
61{
62 // Adjust boundary conditions based on the steps to be executed
64 {
68 {
69 auto& fixedValueBCs =
71 fixedValueBCs == fixedValueBCs/scalar(nSteps_);
72 }
73 }
74 /*
75 // Adjust boundary conditions based on the steps to be executed
76 forAll(pointMotionU_.boundaryField(), patchI)
77 {
78 pointPatchVectorField& pointBCs =
79 pointMotionU_.boundaryFieldRef()[patchI];
80 if (isA<fixedValuePointPatchVectorField>(pointBCs))
81 {
82 auto& fixedValueBCs =
83 refCast<fixedValuePointPatchVectorField>(pointBCs);
84 fixedValueBCs == fixedValueBCs/scalar(nSteps_);
85 }
86 }
87
88 // Copy boundary conditions to internalField
89 // Needed for interpolation to faces
90 pointMotionU_.boundaryFieldRef().updateCoeffs();
91
92 // Interpolate boundary conditions from points to faces
93 forAll(cellMotionU_.boundaryField(), pI)
94 {
95 fvPatchVectorField& bField = cellMotionU_.boundaryFieldRef()[pI];
96 if (isA<fixedValueFvPatchVectorField>(bField))
97 {
98 const pointField& points = fvMesh_.points();
99 const polyPatch& patch = mesh().boundaryMesh()[pI];
100 forAll(bField, fI)
101 {
102 bField[fI] = patch[fI].average(points, pointMotionU_);
103 }
104 }
106 */
107}
108
109
110// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111
112Foam::elasticityMotionSolver::elasticityMotionSolver
113(
114 const polyMesh& mesh,
115 const IOdictionary& dict
116)
117:
119 fvMesh_
120 (
121 const_cast<fvMesh&>
122 (
123 refCast<const fvMesh>(mesh)
124 )
125 ),
126 pointMotionU_
127 (
129 (
130 "pointMotionU",
131 mesh.time().timeName(),
132 mesh,
133 IOobject::READ_IF_PRESENT,
134 IOobject::AUTO_WRITE
135 ),
138 fixedValuePointPatchVectorField::typeName
139 ),
140 cellMotionU_
141 (
143 (
144 "cellMotionU",
145 mesh.time().timeName(),
146 mesh,
147 IOobject::READ_IF_PRESENT,
148 IOobject::AUTO_WRITE
149 ),
150 fvMesh_,
151 dimensionedVector(pointMotionU_.dimensions(), Zero),
152 pointMotionU_.boundaryField().types()
153 ),
154 interpolationPtr_
155 (
156 coeffDict().found("interpolation")
157 ? motionInterpolation::New(fvMesh_, coeffDict().lookup("interpolation"))
158 : motionInterpolation::New(fvMesh_)
159 ),
160 diffusivityPtr_
161 (
162 motionDiffusivity::New(fvMesh_, coeffDict().lookup("diffusivity"))
163 ),
164 nSteps_(this->coeffDict().get<label>("steps")),
165 nIters_(this->coeffDict().get<label>("iters")),
166 tolerance_(this->coeffDict().get<scalar>("tolerance"))
167{}
168
169
170// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173{
174 return tmp<pointField>::New(mesh().points());
175}
176
177
179{
180 // Re-init to zero
181 cellMotionU_.primitiveFieldRef() = Zero;
182
183 // Adjust boundary conditions based on the number of steps to be executed
184 // and interpolate to faces
185 setBoundaryConditions();
186
187 // Solve the elasticity equations in a stepped manner
188 for (label istep = 0; istep < nSteps_; ++istep)
189 {
190 Info<< "Step " << istep << endl;
191
192 // Update diffusivity
193 diffusivityPtr_->correct();
194 const surfaceScalarField E(diffusivityPtr_->operator()());
195 const surfaceVectorField& Sf = fvMesh_.Sf();
196 for (label iter = 0; iter < nIters_; ++iter)
197 {
198 Info<< "Iteration " << iter << endl;
199 cellMotionU_.storePrevIter();
200 fvVectorMatrix dEqn
201 (
202 fvm::laplacian(2*E, cellMotionU_)
203 + fvc::div(2*E*(fvc::interpolate(fvc::grad(cellMotionU_)) & Sf))
204 - fvc::div(E*fvc::interpolate(fvc::div(cellMotionU_))*Sf)
205 );
206
207 scalar residual = mag(dEqn.solve().initialResidual());
208 cellMotionU_.relax();
209
210 // Print execution time
211 fvMesh_.time().printExecutionTime(Info);
212
213 // Check convergence
214 if (residual < tolerance_)
215 {
216 Info<< "\n***Reached mesh movement convergence limit for step "
217 << istep
218 << " iteration " << iter << "***\n\n";
219 break;
220 }
221 }
222
223 interpolationPtr_->interpolate
224 (
225 cellMotionU_,
226 pointMotionU_
227 );
228
229 tmp<vectorField> newPoints
230 (
231 fvMesh_.points() + pointMotionU_.primitiveField()
232 );
233
234 /*
235 // Interpolate from cells to points
236 interpolationPtr_->interpolate(cellMotionU_, pointMotionU_);
237
238 syncTools::syncPointList
239 (
240 fvMesh_,
241 pointMotionU_.primitiveFieldRef(),
242 maxEqOp<vector>(),
243 vector::zero
244 );
245
246 vectorField newPoints
247 (
248 mesh().points() + pointMotionU_.primitiveFieldRef()
249 );
250 */
251
252 // Move points and check mesh
253 fvMesh_.movePoints(newPoints);
254 fvMesh_.checkMesh(true);
255
256 if (debug)
257 {
258 Info<< " Writing new mesh points " << endl;
260 (
262 (
263 "points",
264 mesh().pointsInstance(),
266 mesh(),
270 ),
271 mesh().points()
272 );
273 points.write();
274 }
275 }
276}
277
280{
281 // Do nothing
282}
283
284
286{
287 // Update diffusivity. Note two stage to make sure old one is de-registered
288 // before creating/registering new one.
289 diffusivityPtr_.reset(nullptr);
290 diffusivityPtr_ = motionDiffusivity::New
291 (
292 fvMesh_,
293 coeffDict().lookup("diffusivity")
294 );
295}
296
297
298// ************************************************************************* //
bool found
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition IOobject.C:456
const Type & initialResidual() const noexcept
Return initial residual.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
Mesh deformation based on the linear elasticity equations. The boundary displacement is set as a boun...
virtual tmp< pointField > curPoints() const
Return point location. Mesh is actually moved in solve().
autoPtr< motionDiffusivity > diffusivityPtr_
Diffusivity used to control the motion.
label nSteps_
Intermediate steps to solve the PDEs.
scalar tolerance_
Residual threshold.
label nIters_
Number of laplacian iterations per solution step.
void setBoundaryConditions()
Set boundary conditions of cellMotionU based on pointMotionU.
autoPtr< motionInterpolation > interpolationPtr_
Interpolation used to transfer cell displacement to the points.
virtual void movePoints(const pointField &)
Update local data for geometry changes.
fvMesh & fvMesh_
Since the mesh deformation is broken down to multiple steps, mesh points need to be moved here....
virtual void updateMesh(const mapPolyMesh &)
Update the mesh corresponding to given map.
virtual void solve()
Solve for motion.
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Abstract base class for cell-centre mesh motion diffusivity.
static autoPtr< motionDiffusivity > New(const fvMesh &mesh, Istream &mdData)
Select null constructed.
Base class for interpolation of cell displacement fields, generated by fvMotionSolvers,...
Virtual base class for mesh motion solver.
const polyMesh & mesh() const
Return reference to mesh.
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
virtual tmp< pointField > newPoints()
Provide new points for motion. Solves for motion.
motionSolver(const polyMesh &mesh)
Construct from polyMesh.
const dictionary & coeffDict() const
Const access to the coefficients dictionary.
Mesh representing a set of points created from polyMesh.
Definition pointMesh.H:49
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
Definition polyMesh.H:411
Lookup type of boundary radiation properties.
Definition lookup.H:60
A class for managing temporary objects.
Definition tmp.H:75
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Calculate the divergence of the given field.
Calculate the matrix for the divergence of the given field and flux.
Calculate the matrix for the laplacian of the field.
const pointField & points
word timeName
Definition getTimeIndex.H:3
Namespace for handling debugging switches.
Definition debug.C:45
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition fvcGrad.C:47
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition fvcDiv.C:42
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Namespace for OpenFOAM.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
const dimensionSet dimless
Dimensionless.
messageStream Info
Information stream (stdout output on master, null elsewhere).
vectorIOField pointIOField
pointIOField is a vectorIOField.
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
fvMatrix< vector > fvVectorMatrix
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
vectorField pointField
pointField is a vectorField.
fvPatchField< vector > fvPatchVectorField
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299