00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "sixDoFRigidBodyDisplacementPointPatchVectorField.H"
00027 #include <OpenFOAM/pointPatchFields.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 #include <OpenFOAM/Time.H>
00030 #include <finiteVolume/fvMesh.H>
00031 #include <finiteVolume/volFields.H>
00032 #include <OpenFOAM/uniformDimensionedFields.H>
00033 #include <forces/forces.H>
00034
00035
00036
00037 namespace Foam
00038 {
00039
00040
00041
00042 sixDoFRigidBodyDisplacementPointPatchVectorField::
00043 sixDoFRigidBodyDisplacementPointPatchVectorField
00044 (
00045 const pointPatch& p,
00046 const DimensionedField<vector, pointMesh>& iF
00047 )
00048 :
00049 fixedValuePointPatchField<vector>(p, iF),
00050 motion_(),
00051 initialPoints_(p.localPoints()),
00052 rhoInf_(1.0),
00053 rhoName_("rho"),
00054 lookupGravity_(-1),
00055 g_(vector::zero)
00056 {}
00057
00058
00059 sixDoFRigidBodyDisplacementPointPatchVectorField::
00060 sixDoFRigidBodyDisplacementPointPatchVectorField
00061 (
00062 const pointPatch& p,
00063 const DimensionedField<vector, pointMesh>& iF,
00064 const dictionary& dict
00065 )
00066 :
00067 fixedValuePointPatchField<vector>(p, iF, dict),
00068 motion_(dict),
00069 rhoInf_(1.0),
00070 rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
00071 lookupGravity_(-1),
00072 g_(vector::zero)
00073 {
00074 if (rhoName_ == "rhoInf")
00075 {
00076 rhoInf_ = readScalar(dict.lookup("rhoInf"));
00077 }
00078
00079 if (dict.found("g"))
00080 {
00081 lookupGravity_ = -2;
00082
00083 g_ = dict.lookup("g");
00084 }
00085
00086 if (!dict.found("value"))
00087 {
00088 updateCoeffs();
00089 }
00090
00091 if (dict.found("initialPoints"))
00092 {
00093 initialPoints_ = vectorField("initialPoints", dict , p.size());
00094 }
00095 else
00096 {
00097 initialPoints_ = p.localPoints();
00098 }
00099 }
00100
00101
00102 sixDoFRigidBodyDisplacementPointPatchVectorField::
00103 sixDoFRigidBodyDisplacementPointPatchVectorField
00104 (
00105 const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
00106 const pointPatch& p,
00107 const DimensionedField<vector, pointMesh>& iF,
00108 const pointPatchFieldMapper& mapper
00109 )
00110 :
00111 fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
00112 motion_(ptf.motion_),
00113 initialPoints_(ptf.initialPoints_, mapper),
00114 rhoInf_(ptf.rhoInf_),
00115 rhoName_(ptf.rhoName_),
00116 lookupGravity_(ptf.lookupGravity_),
00117 g_(ptf.g_)
00118 {}
00119
00120
00121 sixDoFRigidBodyDisplacementPointPatchVectorField::
00122 sixDoFRigidBodyDisplacementPointPatchVectorField
00123 (
00124 const sixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
00125 const DimensionedField<vector, pointMesh>& iF
00126 )
00127 :
00128 fixedValuePointPatchField<vector>(ptf, iF),
00129 motion_(ptf.motion_),
00130 initialPoints_(ptf.initialPoints_),
00131 rhoInf_(ptf.rhoInf_),
00132 rhoName_(ptf.rhoName_),
00133 lookupGravity_(ptf.lookupGravity_),
00134 g_(ptf.g_)
00135 {}
00136
00137
00138
00139
00140 void sixDoFRigidBodyDisplacementPointPatchVectorField::autoMap
00141 (
00142 const pointPatchFieldMapper& m
00143 )
00144 {
00145 fixedValuePointPatchField<vector>::autoMap(m);
00146
00147 initialPoints_.autoMap(m);
00148 }
00149
00150
00151 void sixDoFRigidBodyDisplacementPointPatchVectorField::rmap
00152 (
00153 const pointPatchField<vector>& ptf,
00154 const labelList& addr
00155 )
00156 {
00157 const sixDoFRigidBodyDisplacementPointPatchVectorField& sDoFptf =
00158 refCast<const sixDoFRigidBodyDisplacementPointPatchVectorField>(ptf);
00159
00160 fixedValuePointPatchField<vector>::rmap(sDoFptf, addr);
00161
00162 initialPoints_.rmap(sDoFptf.initialPoints_, addr);
00163 }
00164
00165
00166 void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs()
00167 {
00168 if (this->updated())
00169 {
00170 return;
00171 }
00172
00173 if (lookupGravity_ < 0)
00174 {
00175 if (db().foundObject<uniformDimensionedVectorField>("g"))
00176 {
00177 if (lookupGravity_ == -2)
00178 {
00179 FatalErrorIn
00180 (
00181 "void sixDoFRigidBodyDisplacementPointPatchVectorField"
00182 "::updateCoeffs()"
00183 )
00184 << "Specifying the value of g in this boundary condition "
00185 << "when g is available from the database is considered "
00186 << "a fatal error to avoid the possibility of inconsistency"
00187 << exit(FatalError);
00188 }
00189 else
00190 {
00191 lookupGravity_ = 1;
00192 }
00193 }
00194 else
00195 {
00196 lookupGravity_ = 0;
00197 }
00198 }
00199
00200 const polyMesh& mesh = this->dimensionedInternalField().mesh()();
00201 const Time& t = mesh.time();
00202 const pointPatch& ptPatch = this->patch();
00203
00204
00205
00206
00207
00208 motion_.updatePosition(t.deltaTValue(), t.deltaT0Value());
00209
00210 dictionary forcesDict;
00211
00212 forcesDict.add("patches", wordList(1, ptPatch.name()));
00213 forcesDict.add("rhoInf", rhoInf_);
00214 forcesDict.add("rhoName", rhoName_);
00215 forcesDict.add("CofR", motion_.centreOfMass());
00216
00217 forces f("forces", db(), forcesDict);
00218
00219 forces::forcesMoments fm = f.calcForcesMoment();
00220
00221
00222
00223 if (lookupGravity_ == 1)
00224 {
00225 uniformDimensionedVectorField g =
00226 db().lookupObject<uniformDimensionedVectorField>("g");
00227
00228 g_ = g.value();
00229 }
00230
00231 motion_.updateForce
00232 (
00233 fm.first().first() + fm.first().second() + g_*motion_.mass(),
00234 fm.second().first() + fm.second().second(),
00235 t.deltaTValue()
00236 );
00237
00238 Field<vector>::operator=
00239 (
00240 motion_.currentPosition(initialPoints_) - initialPoints_
00241 );
00242
00243 fixedValuePointPatchField<vector>::updateCoeffs();
00244 }
00245
00246
00247 void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const
00248 {
00249 pointPatchField<vector>::write(os);
00250
00251 os.writeKeyword("rhoInf") << rhoInf_ << token::END_STATEMENT << nl;
00252
00253 os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl;
00254
00255 if (lookupGravity_ == 0 || lookupGravity_ == -2)
00256 {
00257 os.writeKeyword("g") << g_ << token::END_STATEMENT << nl;
00258 }
00259
00260 motion_.write(os);
00261
00262 initialPoints_.writeEntry("initialPoints", os);
00263
00264 writeEntry("value", os);
00265 }
00266
00267
00268
00269
00270 makePointPatchTypeField
00271 (
00272 pointPatchVectorField,
00273 sixDoFRigidBodyDisplacementPointPatchVectorField
00274 );
00275
00276
00277
00278 }
00279
00280