BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / src / dynamicMesh / dynamicFvMesh / dynamicBoxFvMesh / dynamicBoxFvMesh.C
bloba40bde86ab2ae47056ca2d72be344474f60380f7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(dynamicBoxFvMesh, 0);
41 addToRunTimeSelectionTable(dynamicFvMesh, dynamicBoxFvMesh, IOobject);
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 dynamicBoxFvMesh::dynamicBoxFvMesh(const IOobject& io)
48     dynamicFvMesh(io),
49     movingMeshCoeffs_
50     (
51         IOdictionary
52         (
53             IOobject
54             (
55                 "dynamicMeshDict",
56                 io.time().constant(),
57                 *this,
58                 IOobject::MUST_READ,
59                 IOobject::NO_WRITE
60             )
61         ).subDict(typeName + "Coeffs")
62     ),
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"))),
68     stationaryPoints_
69     (
70         IOobject
71         (
72             "points",
73             io.time().constant(),
74             meshSubDir,
75             *this,
76             IOobject::MUST_READ,
77             IOobject::NO_WRITE
78         )
79     ),
80     motionMarkup_(stationaryPoints_.size(), 0)
82     if (mag(splitDirection_) < SMALL)
83     {
84         FatalErrorIn("dynamicBoxFvMesh::dynamicBoxFvMesh(const IOobject& io)")
85             << "Incorrect definition of split direction"
86             << abort(FatalError);
87     }
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);
106     p -= minP;
107     leftP -= minP;
108     rightP -= minP;
110     scalar maxP = max(p);
111     p /= maxP;
112     leftP /= maxP;
113     rightP /= maxP;
115     Info << "leftP: " << leftP << " rightP: " << rightP << " min: " << min(p)
116          << " max: " << max(p);
118     // Left part
119     motionMarkup_ += neg(p - leftP - SMALL)*p/leftP;
121     // Centre part
122     motionMarkup_ += neg(p - rightP + SMALL)*pos(p - leftP - SMALL);
124     // Right part
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
150     return false;
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // ************************************************************************* //