smallPoolFire2D fireFoam tutorial: improved stability of the BCs.
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyDisplacement / sixDoFRigidBodyDisplacementPointPatchVectorField.C
blobf2a7adb5b6e6efd896e0fe4d3714ad1017703b93
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     p0_(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("p0"))
75     {
76         p0_ = vectorField("p0", dict , p.size());
77     }
78     else
79     {
80         p0_ = 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     p0_(ptf.p0_),
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     p0_(ptf.p0_),
111     rhoInf_(ptf.rhoInf_)
115 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
117 void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs()
119     if (this->updated())
120     {
121         return;
122     }
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"))
149     {
150         uniformDimensionedVectorField g =
151             db().lookupObject<uniformDimensionedVectorField>("g");
153         gravity = g.value();
154     }
156     motion_.updateForce
157     (
158         fm.first().first() + fm.first().second() + gravity*motion_.mass(),
159         fm.second().first() + fm.second().second(),
160         t.deltaT().value()
161     );
163     Field<vector>::operator=(motion_.generatePositions(p0_) - p0_);
165     fixedValuePointPatchField<vector>::updateCoeffs();
169 void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const
171     pointPatchField<vector>::write(os);
172     motion_.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 // ************************************************************************* //