1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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"
32 #include "volFields.H"
33 #include "uniformDimensionedFields.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 sixDoFRigidBodyDisplacementPointPatchVectorField::
44 sixDoFRigidBodyDisplacementPointPatchVectorField
47 const DimensionedField<vector, pointMesh>& iF
50 fixedValuePointPatchField<vector>(p, iF),
52 initialPoints_(p.localPoints()),
60 sixDoFRigidBodyDisplacementPointPatchVectorField::
61 sixDoFRigidBodyDisplacementPointPatchVectorField
64 const DimensionedField<vector, pointMesh>& iF,
65 const dictionary& dict
68 fixedValuePointPatchField<vector>(p, iF, dict),
71 rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
75 if (rhoName_ == "rhoInf")
77 rhoInf_ = readScalar(dict.lookup("rhoInf"));
84 g_ = dict.lookup("g");
87 if (!dict.found("value"))
92 if (dict.found("initialPoints"))
94 initialPoints_ = vectorField("initialPoints", dict , p.size());
98 initialPoints_ = p.localPoints();
103 sixDoFRigidBodyDisplacementPointPatchVectorField::
104 sixDoFRigidBodyDisplacementPointPatchVectorField
106 const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
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_),
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_),
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()
174 if (lookupGravity_ < 0)
176 if (db().foundObject<uniformDimensionedVectorField>("g"))
178 if (lookupGravity_ == -2)
182 "void sixDoFRigidBodyDisplacementPointPatchVectorField"
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"
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)
226 uniformDimensionedVectorField g =
227 db().lookupObject<uniformDimensionedVectorField>("g");
234 fm.first().first() + fm.first().second() + g_*motion_.mass(),
235 fm.second().first() + fm.second().second(),
239 Field<vector>::operator=
241 motion_.currentPosition(initialPoints_) - initialPoints_
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)
258 os.writeKeyword("g") << g_ << token::END_STATEMENT << nl;
263 initialPoints_.writeEntry("initialPoints", os);
265 writeEntry("value", os);
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 makePointPatchTypeField
273 pointPatchVectorField,
274 sixDoFRigidBodyDisplacementPointPatchVectorField
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 } // End namespace Foam
281 // ************************************************************************* //