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 "dynamicBoxFvMesh.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "volFields.H"
30 #include "mathematicalConstants.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(dynamicBoxFvMesh, 0);
41 addToRunTimeSelectionTable(dynamicFvMesh, dynamicBoxFvMesh, IOobject);
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 dynamicBoxFvMesh::dynamicBoxFvMesh(const IOobject& io)
61 ).subDict(typeName + "Coeffs")
63 splitDirection_(movingMeshCoeffs_.lookup("splitDirection")),
64 leftEdge_(movingMeshCoeffs_.lookup("leftEdge")),
65 rightEdge_(movingMeshCoeffs_.lookup("rightEdge")),
66 amplitude_(movingMeshCoeffs_.lookup("amplitude")),
67 frequency_(readScalar(movingMeshCoeffs_.lookup("frequency"))),
80 motionMarkup_(stationaryPoints_.size(), 0)
82 if (mag(splitDirection_) < SMALL)
84 FatalErrorIn("dynamicBoxFvMesh::dynamicBoxFvMesh(const IOobject& io)")
85 << "Incorrect definition of split direction"
89 splitDirection_ /= mag(splitDirection_);
91 Info<< "Performing a moving mesh calculation: " << nl
92 << "splitDirection: " << splitDirection_ << nl
93 << "leftEdge: " << leftEdge_ << nl
94 << "rightEdge: " << rightEdge_ << nl
95 << "amplitude: " << amplitude_ << nl
96 << "frequency: " << frequency_ << endl;
98 // Calculate vertex markup
99 scalarField p = points() & splitDirection_;
100 scalar leftP = (leftEdge_ & splitDirection_);
101 scalar rightP = (rightEdge_ & splitDirection_);
103 // Re-scale p to be between 0 and 1
105 scalar minP = min(p);
110 scalar maxP = max(p);
115 Info << "leftP: " << leftP << " rightP: " << rightP << " min: " << min(p)
116 << " max: " << max(p);
119 motionMarkup_ += neg(p - leftP - SMALL)*p/leftP;
122 motionMarkup_ += neg(p - rightP + SMALL)*pos(p - leftP - SMALL);
125 motionMarkup_ += pos(p - rightP + SMALL)*(1.0 - p)/(1.0 - rightP);
128 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
130 dynamicBoxFvMesh::~dynamicBoxFvMesh()
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 bool dynamicBoxFvMesh::update()
138 scalar scalingFunction =
139 Foam::sin(2*mathematicalConstant::pi*frequency_*time().value());
141 Info<< "Mesh scaling. Time = " << time().value() << " scaling: "
142 << scalingFunction << endl;
144 pointField newPoints =
145 stationaryPoints_ + motionMarkup_*amplitude_*scalingFunction;
147 fvMesh::movePoints(newPoints);
149 // Mesh motion only - return false
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // ************************************************************************* //