Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyDisplacement / sixDoFRigidBodyDisplacementPointPatchVectorField.C
blobc001027d461a190633b440732d59d58aff768ffa
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-2011 OpenCFD Ltd.
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "sixDoFRigidBodyDisplacementPointPatchVectorField.H"
27 #include "pointPatchFields.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "Time.H"
30 #include "fvMesh.H"
31 #include "volFields.H"
32 #include "uniformDimensionedFields.H"
33 #include "forces.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 sixDoFRigidBodyDisplacementPointPatchVectorField::
43 sixDoFRigidBodyDisplacementPointPatchVectorField
45     const pointPatch& p,
46     const DimensionedField<vector, pointMesh>& iF
49     fixedValuePointPatchField<vector>(p, iF),
50     motion_(),
51     initialPoints_(p.localPoints()),
52     rhoInf_(1.0),
53     rhoName_("rho"),
54     lookupGravity_(-1),
55     g_(vector::zero)
59 sixDoFRigidBodyDisplacementPointPatchVectorField::
60 sixDoFRigidBodyDisplacementPointPatchVectorField
62     const pointPatch& p,
63     const DimensionedField<vector, pointMesh>& iF,
64     const dictionary& dict
67     fixedValuePointPatchField<vector>(p, iF, dict),
68     motion_(dict),
69     rhoInf_(1.0),
70     rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
71     lookupGravity_(-1),
72     g_(vector::zero)
74     if (rhoName_ == "rhoInf")
75     {
76         rhoInf_ = readScalar(dict.lookup("rhoInf"));
77     }
79     if (dict.readIfPresent("g", g_))
80     {
81         lookupGravity_ = -2;
82     }
84     if (!dict.found("value"))
85     {
86         updateCoeffs();
87     }
89     if (dict.found("initialPoints"))
90     {
91         initialPoints_ = vectorField("initialPoints", dict , p.size());
92     }
93     else
94     {
95         initialPoints_ = p.localPoints();
96     }
100 sixDoFRigidBodyDisplacementPointPatchVectorField::
101 sixDoFRigidBodyDisplacementPointPatchVectorField
103     const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
104     const pointPatch& p,
105     const DimensionedField<vector, pointMesh>& iF,
106     const pointPatchFieldMapper& mapper
109     fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
110     motion_(ptf.motion_),
111     initialPoints_(ptf.initialPoints_, mapper),
112     rhoInf_(ptf.rhoInf_),
113     rhoName_(ptf.rhoName_),
114     lookupGravity_(ptf.lookupGravity_),
115     g_(ptf.g_)
119 sixDoFRigidBodyDisplacementPointPatchVectorField::
120 sixDoFRigidBodyDisplacementPointPatchVectorField
122     const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
123     const DimensionedField<vector, pointMesh>& iF
126     fixedValuePointPatchField<vector>(ptf, iF),
127     motion_(ptf.motion_),
128     initialPoints_(ptf.initialPoints_),
129     rhoInf_(ptf.rhoInf_),
130     rhoName_(ptf.rhoName_),
131     lookupGravity_(ptf.lookupGravity_),
132     g_(ptf.g_)
136 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
138 void sixDoFRigidBodyDisplacementPointPatchVectorField::autoMap
140     const pointPatchFieldMapper& m
143     fixedValuePointPatchField<vector>::autoMap(m);
145     initialPoints_.autoMap(m);
149 void sixDoFRigidBodyDisplacementPointPatchVectorField::rmap
151     const pointPatchField<vector>& ptf,
152     const labelList& addr
155     const sixDoFRigidBodyDisplacementPointPatchVectorField& sDoFptf =
156         refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
158     fixedValuePointPatchField<vector>::rmap(sDoFptf, addr);
160     initialPoints_.rmap(sDoFptf.initialPoints_, addr);
164 void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs()
166     if (this->updated())
167     {
168         return;
169     }
171     if (lookupGravity_ < 0)
172     {
173         if (db().foundObject<uniformDimensionedVectorField>("g"))
174         {
175             if (lookupGravity_ == -2)
176             {
177                 FatalErrorIn
178                 (
179                     "void sixDoFRigidBodyDisplacementPointPatchVectorField"
180                     "::updateCoeffs()"
181                 )
182                     << "Specifying the value of g in this boundary condition "
183                     << "when g is available from the database is considered "
184                     << "a fatal error to avoid the possibility of inconsistency"
185                     << exit(FatalError);
186             }
187             else
188             {
189                 lookupGravity_ = 1;
190             }
191         }
192         else
193         {
194             lookupGravity_ = 0;
195         }
196     }
198     const polyMesh& mesh = this->dimensionedInternalField().mesh()();
199     const Time& t = mesh.time();
200     const pointPatch& ptPatch = this->patch();
202     // Patch force data is valid for the current positions, so
203     // calculate the forces on the motion object from this data, then
204     // update the positions
206     motion_.updatePosition(t.deltaTValue());
208     dictionary forcesDict;
210     forcesDict.add("patches", wordList(1, ptPatch.name()));
211     forcesDict.add("rhoInf", rhoInf_);
212     forcesDict.add("rhoName", rhoName_);
213     forcesDict.add("CofR", motion_.centreOfMass());
215     forces f("forces", db(), forcesDict);
217     forces::forcesMoments fm = f.calcForcesMoment();
219     // Get the forces on the patch faces at the current positions
221     if (lookupGravity_ == 1)
222     {
223         uniformDimensionedVectorField g =
224             db().lookupObject<uniformDimensionedVectorField>("g");
226         g_ = g.value();
227     }
229     motion_.updateForce
230     (
231         fm.first().first() + fm.first().second() + g_*motion_.mass(),
232         fm.second().first() + fm.second().second(),
233         t.deltaTValue()
234     );
236     Field<vector>::operator=
237     (
238         motion_.currentPosition(initialPoints_) - initialPoints_
239     );
241     fixedValuePointPatchField<vector>::updateCoeffs();
245 void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const
247     pointPatchField<vector>::write(os);
249     os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
251     if (rhoName_ == "rhoInf")
252     {
253         os.writeKeyword("rhoInf") << rhoInf_ << token::END_STATEMENT << nl;
254     }
256     if (lookupGravity_ == 0 || lookupGravity_ == -2)
257     {
258         os.writeKeyword("g") << g_ << token::END_STATEMENT << nl;
259     }
261     motion_.write(os);
263     initialPoints_.writeEntry("initialPoints", os);
265     writeEntry("value", os);
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 makePointPatchTypeField
273     pointPatchVectorField,
274     sixDoFRigidBodyDisplacementPointPatchVectorField
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 } // End namespace Foam
281 // ************************************************************************* //