FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.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 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00040 
00041 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::
00042 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField
00043 (
00044     const pointPatch& p,
00045     const DimensionedField<vector, pointMesh>& iF
00046 )
00047 :
00048     fixedValuePointPatchField<vector>(p, iF),
00049     motion_(),
00050     initialPoints_(p.localPoints())
00051 {}
00052 
00053 
00054 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::
00055 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField
00056 (
00057     const pointPatch& p,
00058     const DimensionedField<vector, pointMesh>& iF,
00059     const dictionary& dict
00060 )
00061 :
00062     fixedValuePointPatchField<vector>(p, iF, dict),
00063     motion_(dict)
00064 {
00065     if (!dict.found("value"))
00066     {
00067         updateCoeffs();
00068     }
00069 
00070     if (dict.found("initialPoints"))
00071     {
00072         initialPoints_ = vectorField("initialPoints", dict , p.size());
00073     }
00074     else
00075     {
00076         initialPoints_ = p.localPoints();
00077     }
00078 }
00079 
00080 
00081 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::
00082 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField
00083 (
00084     const uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
00085     const pointPatch& p,
00086     const DimensionedField<vector, pointMesh>& iF,
00087     const pointPatchFieldMapper& mapper
00088 )
00089 :
00090     fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
00091     motion_(ptf.motion_),
00092     initialPoints_(ptf.initialPoints_, mapper)
00093 {}
00094 
00095 
00096 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::
00097 uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField
00098 (
00099     const uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField& ptf,
00100     const DimensionedField<vector, pointMesh>& iF
00101 )
00102 :
00103     fixedValuePointPatchField<vector>(ptf, iF),
00104     motion_(ptf.motion_),
00105     initialPoints_(ptf.initialPoints_)
00106 {}
00107 
00108 
00109 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00110 
00111 void uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::autoMap
00112 (
00113     const pointPatchFieldMapper& m
00114 )
00115 {
00116     fixedValuePointPatchField<vector>::autoMap(m);
00117 
00118     initialPoints_.autoMap(m);
00119 }
00120 
00121 
00122 void uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::rmap
00123 (
00124     const pointPatchField<vector>& ptf,
00125     const labelList& addr
00126 )
00127 {
00128     const uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField& uSDoFptf =
00129     refCast
00130     <
00131         const uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField
00132     >(ptf);
00133 
00134     fixedValuePointPatchField<vector>::rmap(uSDoFptf, addr);
00135 
00136     initialPoints_.rmap(uSDoFptf.initialPoints_, addr);
00137 }
00138 
00139 
00140 void uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs()
00141 {
00142     if (this->updated())
00143     {
00144         return;
00145     }
00146 
00147     const polyMesh& mesh = this->dimensionedInternalField().mesh()();
00148     const Time& t = mesh.time();
00149 
00150     motion_.updatePosition(t.deltaTValue(), t.deltaT0Value());
00151 
00152     vector gravity = vector::zero;
00153 
00154     if (db().foundObject<uniformDimensionedVectorField>("g"))
00155     {
00156         uniformDimensionedVectorField g =
00157         db().lookupObject<uniformDimensionedVectorField>("g");
00158 
00159         gravity = g.value();
00160     }
00161 
00162     // Do not modify the accelerations, except with gravity, where available
00163     motion_.updateForce(gravity*motion_.mass(), vector::zero, t.deltaTValue());
00164 
00165     Field<vector>::operator=
00166     (
00167         motion_.currentPosition(initialPoints_) - initialPoints_
00168     );
00169 
00170     fixedValuePointPatchField<vector>::updateCoeffs();
00171 }
00172 
00173 
00174 void uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::write
00175 (
00176     Ostream& os
00177 ) const
00178 {
00179     pointPatchField<vector>::write(os);
00180     motion_.write(os);
00181     initialPoints_.writeEntry("initialPoints", os);
00182     writeEntry("value", os);
00183 }
00184 
00185 
00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00187 
00188 makePointPatchTypeField
00189 (
00190     pointPatchVectorField,
00191     uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField
00192 );
00193 
00194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00195 
00196 } // End namespace Foam
00197 
00198 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines