BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / src / dynamicMesh / dynamicFvMesh / subsetMotionSolverFvMesh / subsetMotionSolverFvMesh.C
blobd8ce75d43e3d8d1742b6800d8fe90bd5db1c03c9
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 "subsetMotionSolverFvMesh.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "cellSet.H"
30 #include "motionSolver.H"
31 #include "volFields.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(subsetMotionSolverFvMesh, 0);
39     addToRunTimeSelectionTable
40     (
41         dynamicFvMesh,
42         subsetMotionSolverFvMesh,
43         IOobject
44     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::subsetMotionSolverFvMesh::subsetMotionSolverFvMesh(const IOobject& io)
52     dynamicFvMesh(io),
53     movingMeshCoeffs_
54     (
55         IOdictionary
56         (
57             IOobject
58             (
59                 "dynamicMeshDict",
60                 io.time().constant(),
61                 *this,
62                 IOobject::MUST_READ,
63                 IOobject::NO_WRITE
64             )
65         ).subDict(typeName + "Coeffs")
66     ),
67     subsetMesh_
68     (
69         IOobject
70         (
71             "motion",
72             io.time().constant(),
73             *this,
74             IOobject::NO_READ,
75             IOobject::NO_WRITE
76         ),
77         *this
78     ),
79     motionPtr_(NULL),
80     alpha_(readScalar(movingMeshCoeffs_.lookup("alpha")))
82     // Create subset
83     word setName = movingMeshCoeffs_.lookup("set");
85     cellSet currentSet
86     (
87         IOobject
88         (
89             setName,
90             io.time().constant(),
91             polyMesh::meshSubDir/"sets",
92             *this,
93             IOobject::MUST_READ,
94             IOobject::NO_WRITE
95         )
96     );
98     subsetMesh_.setLargeCellSubset(currentSet, -1);
100     // Create motion solver on the subset
101     motionPtr_ = motionSolver::New(subsetMesh_.subMesh());
103     // Read motion under-relaxation
104     if (alpha_ < 0 || alpha_ > 1.0)
105     {
106         FatalErrorIn
107         (
108             "subsetMotionSolverFvMesh::subsetMotionSolverFvMesh"
109             "(const IOobject& io)"
110         )   << "Ill-defined motion under-relaxation: "
111             << "should be between 0 and 1."
112             << "  Alpha = " << alpha_ << abort(FatalError);
113     }
117 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
119 Foam::subsetMotionSolverFvMesh::~subsetMotionSolverFvMesh()
123 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
125 const Foam::fvMeshSubset& Foam::subsetMotionSolverFvMesh::subsetMesh() const
127     return subsetMesh_;
131 bool Foam::subsetMotionSolverFvMesh::update()
133     // Get the points from the moving part
134     pointField subsetPoints = motionPtr_->newPoints();
136     //- Get copy of mesh points
137     pointField p = allPoints();
139     //- Map the moving part
140     const labelList& subsetPointAddr = subsetMesh_.pointMap();
142     forAll (subsetPoints, subsetI)
143     {
144         p[subsetPointAddr[subsetI]] = subsetPoints[subsetI];
145     }
147     subsetMesh_.subMesh().movePoints(subsetPoints);
149     // Under-relax mesh motion
150     p = alpha_*p + (1 - alpha_)*allPoints();
152     fvMesh::movePoints(p);
154     // Mesh motion only - return false
155     return false;
159 // ************************************************************************* //