1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 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
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
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"
31 #include "volFields.H"
32 #include "uniformDimensionedFields.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 sixDoFRigidBodyDisplacementPointPatchVectorField::
43 sixDoFRigidBodyDisplacementPointPatchVectorField
46 const DimensionedField<vector, pointMesh>& iF
49 fixedValuePointPatchField<vector>(p, iF),
51 initialPoints_(p.localPoints()),
59 sixDoFRigidBodyDisplacementPointPatchVectorField::
60 sixDoFRigidBodyDisplacementPointPatchVectorField
63 const DimensionedField<vector, pointMesh>& iF,
64 const dictionary& dict
67 fixedValuePointPatchField<vector>(p, iF, dict),
70 rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
74 if (rhoName_ == "rhoInf")
76 rhoInf_ = readScalar(dict.lookup("rhoInf"));
79 if (dict.readIfPresent("g", g_))
84 if (!dict.found("value"))
89 if (dict.found("initialPoints"))
91 initialPoints_ = vectorField("initialPoints", dict , p.size());
95 initialPoints_ = p.localPoints();
100 sixDoFRigidBodyDisplacementPointPatchVectorField::
101 sixDoFRigidBodyDisplacementPointPatchVectorField
103 const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
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_),
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_),
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()
171 if (lookupGravity_ < 0)
173 if (db().foundObject<uniformDimensionedVectorField>("g"))
175 if (lookupGravity_ == -2)
179 "void sixDoFRigidBodyDisplacementPointPatchVectorField"
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"
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)
223 uniformDimensionedVectorField g =
224 db().lookupObject<uniformDimensionedVectorField>("g");
231 fm.first().first() + fm.first().second() + g_*motion_.mass(),
232 fm.second().first() + fm.second().second(),
236 Field<vector>::operator=
238 motion_.currentPosition(initialPoints_) - initialPoints_
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")
253 os.writeKeyword("rhoInf") << rhoInf_ << 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 // ************************************************************************* //