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),
57 sixDoFRigidBodyDisplacementPointPatchVectorField::
58 sixDoFRigidBodyDisplacementPointPatchVectorField
61 const DimensionedField<vector, pointMesh>& iF,
62 const dictionary& dict
65 fixedValuePointPatchField<vector>(p, iF, dict),
67 rhoInf_(readScalar(dict.lookup("rhoInf")))
69 if (!dict.found("value"))
76 p0_ = vectorField("p0", dict , p.size());
80 p0_ = p.localPoints();
85 sixDoFRigidBodyDisplacementPointPatchVectorField::
86 sixDoFRigidBodyDisplacementPointPatchVectorField
88 const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
90 const DimensionedField<vector, pointMesh>& iF,
91 const pointPatchFieldMapper& mapper
94 fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
101 sixDoFRigidBodyDisplacementPointPatchVectorField::
102 sixDoFRigidBodyDisplacementPointPatchVectorField
104 const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
105 const DimensionedField<vector, pointMesh>& iF
108 fixedValuePointPatchField<vector>(ptf, iF),
109 motion_(ptf.motion_),
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs()
124 const polyMesh& mesh = this->dimensionedInternalField().mesh()();
125 const Time& t = mesh.time();
126 const pointPatch& ptPatch = this->patch();
128 // Patch force data is valid for the current positions, so
129 // calculate the forces on the motion object from this data, then
130 // update the positions
132 motion_.updatePosition(t.deltaT().value());
134 dictionary forcesDict;
136 forcesDict.add("patches", wordList(1, ptPatch.name()));
137 forcesDict.add("rhoInf", rhoInf_);
138 forcesDict.add("CofR", motion_.centreOfMass());
140 forces f("forces", db(), forcesDict);
142 forces::forcesMoments fm = f.calcForcesMoment();
144 // Get the forces on the patch faces at the current positions
146 vector gravity = vector::zero;
148 if (db().foundObject<uniformDimensionedVectorField>("g"))
150 uniformDimensionedVectorField g =
151 db().lookupObject<uniformDimensionedVectorField>("g");
158 fm.first().first() + fm.first().second() + gravity*motion_.mass(),
159 fm.second().first() + fm.second().second(),
163 Field<vector>::operator=(motion_.generatePositions(p0_) - p0_);
165 fixedValuePointPatchField<vector>::updateCoeffs();
169 void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const
171 pointPatchField<vector>::write(os);
173 os.writeKeyword("rhoInf")
174 << rhoInf_ << token::END_STATEMENT << nl;
175 p0_.writeEntry("p0", os);
176 writeEntry("value", os);
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 makePointPatchTypeField
184 pointPatchVectorField,
185 sixDoFRigidBodyDisplacementPointPatchVectorField
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 } // End namespace Foam
192 // ************************************************************************* //