sixDoFMotion: Adding restraints and constraints to the motion of objects.
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyDisplacement / sixDoFRigidBodyDisplacementPointPatchVectorField.C
blob59ae40b2b54264cdecd5621b3e40489d46606dad
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 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 "sixDoFRigidBodyDisplacementPointPatchVectorField.H"
28 #include "pointPatchFields.H"
29 #include "addToRunTimeSelectionTable.H"
30 #include "Time.H"
31 #include "fvMesh.H"
32 #include "volFields.H"
33 #include "uniformDimensionedFields.H"
34 #include "forces.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 sixDoFRigidBodyDisplacementPointPatchVectorField::
44 sixDoFRigidBodyDisplacementPointPatchVectorField
46     const pointPatch& p,
47     const DimensionedField<vector, pointMesh>& iF
50     fixedValuePointPatchField<vector>(p, iF),
51     motion_(),
52     initialPoints_(p.localPoints()),
53     rhoInf_(1.0)
57 sixDoFRigidBodyDisplacementPointPatchVectorField::
58 sixDoFRigidBodyDisplacementPointPatchVectorField
60     const pointPatch& p,
61     const DimensionedField<vector, pointMesh>& iF,
62     const dictionary& dict
65     fixedValuePointPatchField<vector>(p, iF, dict),
66     motion_(dict),
67     rhoInf_(readScalar(dict.lookup("rhoInf")))
69     if (!dict.found("value"))
70     {
71         updateCoeffs();
72     }
74     if (dict.found("initialPoints"))
75     {
76         initialPoints_ = vectorField("initialPoints", dict , p.size());
77     }
78     else
79     {
80         initialPoints_ = p.localPoints();
81     }
85 sixDoFRigidBodyDisplacementPointPatchVectorField::
86 sixDoFRigidBodyDisplacementPointPatchVectorField
88     const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
89     const pointPatch& p,
90     const DimensionedField<vector, pointMesh>& iF,
91     const pointPatchFieldMapper& mapper
94     fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
95     motion_(ptf.motion_),
96     initialPoints_(ptf.initialPoints_, mapper),
97     rhoInf_(ptf.rhoInf_)
101 sixDoFRigidBodyDisplacementPointPatchVectorField::
102 sixDoFRigidBodyDisplacementPointPatchVectorField
104     const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
105     const DimensionedField<vector, pointMesh>& iF
108     fixedValuePointPatchField<vector>(ptf, iF),
109     motion_(ptf.motion_),
110     initialPoints_(ptf.initialPoints_),
111     rhoInf_(ptf.rhoInf_)
115 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
117 void sixDoFRigidBodyDisplacementPointPatchVectorField::autoMap
119     const pointPatchFieldMapper& m
122     fixedValuePointPatchField<vector>::autoMap(m);
124     initialPoints_.autoMap(m);
128 void sixDoFRigidBodyDisplacementPointPatchVectorField::rmap
130     const pointPatchField<vector>& ptf,
131     const labelList& addr
134     const sixDoFRigidBodyDisplacementPointPatchVectorField& sDoFptf =
135         refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
137     fixedValuePointPatchField<vector>::rmap(sDoFptf, addr);
139     initialPoints_.rmap(sDoFptf.initialPoints_, addr);
143 void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs()
145     if (this->updated())
146     {
147         return;
148     }
150     const polyMesh& mesh = this->dimensionedInternalField().mesh()();
151     const Time& t = mesh.time();
152     const pointPatch& ptPatch = this->patch();
154     // Patch force data is valid for the current positions, so
155     // calculate the forces on the motion object from this data, then
156     // update the positions
158     motion_.updatePosition(t.deltaTValue());
160     dictionary forcesDict;
162     forcesDict.add("patches", wordList(1, ptPatch.name()));
163     forcesDict.add("rhoInf", rhoInf_);
164     forcesDict.add("CofR", motion_.centreOfMass());
166     forces f("forces", db(), forcesDict);
168     forces::forcesMoments fm = f.calcForcesMoment();
170     // Get the forces on the patch faces at the current positions
172     vector gravity = vector::zero;
174     if (db().foundObject<uniformDimensionedVectorField>("g"))
175     {
176         uniformDimensionedVectorField g =
177             db().lookupObject<uniformDimensionedVectorField>("g");
179         gravity = g.value();
180     }
182     motion_.updateForce
183     (
184         fm.first().first() + fm.first().second() + gravity*motion_.mass(),
185         fm.second().first() + fm.second().second(),
186         t.deltaTValue()
187     );
189     Field<vector>::operator=
190     (
191         motion_.currentPosition(initialPoints_) - initialPoints_
192     );
194     fixedValuePointPatchField<vector>::updateCoeffs();
198 void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const
200     pointPatchField<vector>::write(os);
201     motion_.write(os);
202     os.writeKeyword("rhoInf")
203         << rhoInf_ << token::END_STATEMENT << nl;
204     initialPoints_.writeEntry("initialPoints", os);
205     writeEntry("value", os);
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 makePointPatchTypeField
213     pointPatchVectorField,
214     sixDoFRigidBodyDisplacementPointPatchVectorField
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 } // End namespace Foam
221 // ************************************************************************* //