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
25 \*---------------------------------------------------------------------------*/
27 #include "dynamicBodyFvMesh.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "motionSolver.H"
30 #include "volFields.H"
31 #include "mathematicalConstants.H"
32 #include "tetMotionSolver.H"
33 #include "laplaceTetMotionSolver.H"
34 #include "fixedValueTetPolyPatchFields.H"
35 #include "transformField.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(dynamicBodyFvMesh, 0);
42 addToRunTimeSelectionTable(dynamicFvMesh, dynamicBodyFvMesh, IOobject);
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 Foam::dynamicBodyFvMesh::dynamicBodyFvMesh(const IOobject& io)
63 ).subDict(typeName + "Coeffs")
65 motionPtr_(motionSolver::New(*this)),
68 dynamicMeshCoeffs_.lookup("bodyPatchName")
73 dynamicMeshCoeffs_.lookup("translationDirection")
77 readScalar(dynamicMeshCoeffs_.lookup("translationAmplitude"))
81 readScalar(dynamicMeshCoeffs_.lookup("translationFrequency"))
83 initialRotationOrigin_
85 dynamicMeshCoeffs_.lookup("initialRotationOrigin")
89 dynamicMeshCoeffs_.lookup("rotationAxis")
93 readScalar(dynamicMeshCoeffs_.lookup("rotationAmplitude"))
97 readScalar(dynamicMeshCoeffs_.lookup("rotationFrequency"))
100 bodyPatchID_ = boundaryMesh().findPatchID(bodyPatchName_);
106 "dynamicBodyFvMesh::dynamicBodyFvMesh(const IOobject& io)"
108 << "Can't find patch: " << bodyPatchName_
112 translationDirection_ /= mag(translationDirection_) + SMALL;
114 rotationAxis_ /= mag(rotationAxis_) + SMALL;
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 Foam::dynamicBodyFvMesh::~dynamicBodyFvMesh()
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 bool Foam::dynamicBodyFvMesh::update()
128 scalar curTime = time().value();
129 scalar oldTime = curTime - time().deltaT().value();
134 == laplaceTetMotionSolver::typeName
137 tetMotionSolver& mSolver =
138 dynamic_cast<tetMotionSolver&>
144 translationAmplitude_
146 sin(2*mathematicalConstant::pi*translationFrequency_*curTime)
147 - sin(2*mathematicalConstant::pi*translationFrequency_*oldTime)
149 *translationDirection_;
155 sin(2*mathematicalConstant::pi*rotationFrequency_*curTime)
156 - sin(2*mathematicalConstant::pi*rotationFrequency_*oldTime)
159 vector curRotationOrigin =
160 initialRotationOrigin_
161 + translationDirection_
162 *translationAmplitude_
163 *sin(2*mathematicalConstant::pi*translationFrequency_*oldTime);
165 const pointField& oldPoints =
166 mSolver.tetMesh().boundary()[bodyPatchID_].localPoints();
169 r0 -= rotationAxis_*(rotationAxis_ & r0);
172 // http://mathworld.wolfram.com/RotationFormula.html
175 + rotationAxis_*(rotationAxis_ & r0)*(1 - cos(rotAngle))
176 + (r0 ^ rotationAxis_)*sin(rotAngle);
178 tensor T = rotationTensor(r0, r1);
181 transform(T, oldPoints - curRotationOrigin)
186 tetPointVectorField& motionU = mSolver.motionU();
190 motionU.boundaryField()[bodyPatchID_].type()
191 == fixedValueTetPolyPatchVectorField::typeName
194 fixedValueTetPolyPatchVectorField& motionUBodyPatch =
195 refCast<fixedValueTetPolyPatchVectorField>
197 motionU.boundaryField()[bodyPatchID_]
200 motionUBodyPatch == (trans + rot)/time().deltaT().value();
204 FatalErrorIn("dynamicBodyFvMesh::update()")
205 << "Bounary condition on " << motionU.name()
206 << " for " << bodyPatchName_ << " patch is "
207 << motionU.boundaryField()[bodyPatchID_].type()
209 << fixedValueTetPolyPatchVectorField::typeName
215 FatalErrorIn("dynamicBodyFvMesh::update()")
216 << "Selected mesh motion solver is "
217 << motionPtr_->type()
219 << tetMotionSolver::typeName
223 fvMesh::movePoints(motionPtr_->newPoints());
225 // Mesh motion only - return false
230 // ************************************************************************* //