BUG: PointEdgeWave : n cyclics bool instead of label
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyDisplacement / sixDoFRigidBodyDisplacementPointPatchVectorField.C
bloba83311db77fed8d83bc625ba1ceaa60fa084e55d
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),
54     rhoName_("rho"),
55     lookupGravity_(-1),
56     g_(vector::zero)
60 sixDoFRigidBodyDisplacementPointPatchVectorField::
61 sixDoFRigidBodyDisplacementPointPatchVectorField
63     const pointPatch& p,
64     const DimensionedField<vector, pointMesh>& iF,
65     const dictionary& dict
68     fixedValuePointPatchField<vector>(p, iF, dict),
69     motion_(dict),
70     rhoInf_(1.0),
71     rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
72     lookupGravity_(-1),
73     g_(vector::zero)
75     if (rhoName_ == "rhoInf")
76     {
77         rhoInf_ = readScalar(dict.lookup("rhoInf"));
78     }
80     if (dict.found("g"))
81     {
82         lookupGravity_ = -2;
84         g_ = dict.lookup("g");
85     }
87     if (!dict.found("value"))
88     {
89         updateCoeffs();
90     }
92     if (dict.found("initialPoints"))
93     {
94         initialPoints_ = vectorField("initialPoints", dict , p.size());
95     }
96     else
97     {
98         initialPoints_ = p.localPoints();
99     }
103 sixDoFRigidBodyDisplacementPointPatchVectorField::
104 sixDoFRigidBodyDisplacementPointPatchVectorField
106     const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
107     const pointPatch& p,
108     const DimensionedField<vector, pointMesh>& iF,
109     const pointPatchFieldMapper& mapper
112     fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
113     motion_(ptf.motion_),
114     initialPoints_(ptf.initialPoints_, mapper),
115     rhoInf_(ptf.rhoInf_),
116     rhoName_(ptf.rhoName_),
117     lookupGravity_(ptf.lookupGravity_),
118     g_(ptf.g_)
122 sixDoFRigidBodyDisplacementPointPatchVectorField::
123 sixDoFRigidBodyDisplacementPointPatchVectorField
125     const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
126     const DimensionedField<vector, pointMesh>& iF
129     fixedValuePointPatchField<vector>(ptf, iF),
130     motion_(ptf.motion_),
131     initialPoints_(ptf.initialPoints_),
132     rhoInf_(ptf.rhoInf_),
133     rhoName_(ptf.rhoName_),
134     lookupGravity_(ptf.lookupGravity_),
135     g_(ptf.g_)
139 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
141 void sixDoFRigidBodyDisplacementPointPatchVectorField::autoMap
143     const pointPatchFieldMapper& m
146     fixedValuePointPatchField<vector>::autoMap(m);
148     initialPoints_.autoMap(m);
152 void sixDoFRigidBodyDisplacementPointPatchVectorField::rmap
154     const pointPatchField<vector>& ptf,
155     const labelList& addr
158     const sixDoFRigidBodyDisplacementPointPatchVectorField& sDoFptf =
159         refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
161     fixedValuePointPatchField<vector>::rmap(sDoFptf, addr);
163     initialPoints_.rmap(sDoFptf.initialPoints_, addr);
167 void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs()
169     if (this->updated())
170     {
171         return;
172     }
174     if (lookupGravity_ < 0)
175     {
176         if (db().foundObject<uniformDimensionedVectorField>("g"))
177         {
178             if (lookupGravity_ == -2)
179             {
180                 FatalErrorIn
181                 (
182                     "void sixDoFRigidBodyDisplacementPointPatchVectorField"
183                     "::updateCoeffs()"
184                 )
185                     << "Specifying the value of g in this boundary condition "
186                     << "when g is available from the database is considered "
187                     << "a fatal error to avoid the possibility of inconsistency"
188                     << exit(FatalError);
189             }
190             else
191             {
192                 lookupGravity_ = 1;
193             }
194         }
195         else
196         {
197             lookupGravity_ = 0;
198         }
199     }
201     const polyMesh& mesh = this->dimensionedInternalField().mesh()();
202     const Time& t = mesh.time();
203     const pointPatch& ptPatch = this->patch();
205     // Patch force data is valid for the current positions, so
206     // calculate the forces on the motion object from this data, then
207     // update the positions
209     motion_.updatePosition(t.deltaTValue());
211     dictionary forcesDict;
213     forcesDict.add("patches", wordList(1, ptPatch.name()));
214     forcesDict.add("rhoInf", rhoInf_);
215     forcesDict.add("rhoName", rhoName_);
216     forcesDict.add("CofR", motion_.centreOfMass());
218     forces f("forces", db(), forcesDict);
220     forces::forcesMoments fm = f.calcForcesMoment();
222     // Get the forces on the patch faces at the current positions
224     if (lookupGravity_ == 1)
225     {
226         uniformDimensionedVectorField g =
227             db().lookupObject<uniformDimensionedVectorField>("g");
229         g_ = g.value();
230     }
232     motion_.updateForce
233     (
234         fm.first().first() + fm.first().second() + g_*motion_.mass(),
235         fm.second().first() + fm.second().second(),
236         t.deltaTValue()
237     );
239     Field<vector>::operator=
240     (
241         motion_.currentPosition(initialPoints_) - initialPoints_
242     );
244     fixedValuePointPatchField<vector>::updateCoeffs();
248 void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const
250     pointPatchField<vector>::write(os);
252     os.writeKeyword("rhoInf") << rhoInf_ << token::END_STATEMENT << nl;
254     os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
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 // ************************************************************************* //