BeamFEMForceField.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #ifndef SOFA_COMPONENT_FORCEFIELD_BEAMFEMFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_BEAMFEMFORCEFIELD_H
00027 
00028 #include <sofa/component/topology/EdgeData.inl>
00029 #include <sofa/core/componentmodel/behavior/ForceField.h>
00030 #include <sofa/component/MechanicalObject.h>
00031 #include <sofa/helper/vector.h>
00032 #include <sofa/defaulttype/Vec.h>
00033 #include <sofa/defaulttype/Mat.h>
00034 #include <sofa/component/StiffnessContainer.h>
00035 #include <sofa/component/PoissonContainer.h>
00036 #include <sofa/component/LengthContainer.h>
00037 #include <sofa/component/RadiusContainer.h>
00038 #include <newmat/newmat.h>
00039 
00040 
00041 
00042 namespace sofa
00043 {
00044 
00045 namespace component
00046 {
00047 
00048 namespace forcefield
00049 {
00050 
00051 using namespace sofa::defaulttype;
00052 using sofa::helper::vector;
00053 
00056 template<class DataTypes>
00057 class BeamFEMForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00058 {
00059 public:
00060     typedef typename DataTypes::VecCoord VecCoord;
00061     typedef typename DataTypes::VecDeriv VecDeriv;
00062     typedef typename DataTypes::VecReal VecReal;
00063     typedef VecCoord Vector;
00064     typedef typename DataTypes::Coord Coord;
00065     typedef typename DataTypes::Deriv Deriv;
00066     typedef typename Coord::value_type Real;
00067 
00068     typedef unsigned int Index;
00069     typedef topology::Edge Element;
00070     typedef sofa::helper::vector<topology::Edge> VecElement;
00071 
00072     
00073 protected:
00074     //component::MechanicalObject<DataTypes>* object;
00075 
00076     typedef Vec<12, Real> Displacement;        
00077     
00078     //typedef Mat<6, 6, Real> MaterialStiffness;    ///< the matrix of material stiffness
00079     //typedef vector<MaterialStiffness> VecMaterialStiffness;         ///< a vector of material stiffness matrices
00080     //VecMaterialStiffness _materialsStiffnesses;                    ///< the material stiffness matrices vector
00081     
00082     //typedef Mat<12, 6, Real> StrainDisplacement;    ///< the strain-displacement matrix
00083     //typedef vector<StrainDisplacement> VecStrainDisplacement;        ///< a vector of strain-displacement matrices
00084     //VecStrainDisplacement _strainDisplacements;                       ///< the strain-displacement matrices vector
00085     
00086      typedef Mat<3, 3, Real> Transformation; 
00087     
00088 
00089     typedef Mat<12, 12, Real> StiffnessMatrix;
00090     //typedef topology::EdgeData<StiffnessMatrix> VecStiffnessMatrices;         ///< a vector of stiffness matrices
00091     //VecStiffnessMatrices _stiffnessMatrices;                    ///< the material stiffness matrices vector
00092     
00093     struct BeamInfo {
00094         //  static const double FLEXIBILITY=1.00000; // was 1.00001
00095     double _E0,_E; //Young
00096     double _nu;//Poisson
00097     double _L; //length
00098     double _r; //radius of the section
00099     double _G; //shear modulus
00100     double _Iy;
00101     double _Iz; //Iz is the cross-section moment of inertia (assuming mass ratio = 1) about the z axis;
00102     double _J;  //Polar moment of inertia (J = Iy + Iz)
00103     double _A; // A is the cross-sectional area;
00104     double _Asy; //_Asy is the y-direction effective shear area =  10/9 (for solid circular section) or 0 for a non-Timoshenko beam
00105     double _Asz; //_Asz is the z-direction effective shear area;
00106         StiffnessMatrix _k_loc;
00107     //new: k_loc is the stiffness in the local frame... to compute Ke we only change lambda
00108     //NewMAT::Matrix  _k_loc;
00109         
00110     // _eigenvalue_loc are 4 diagonal matrices (6x6) representing the eigenvalues of each
00111     // 6x6 block of _k_loc. _eigenvalue_loc[1] = _eigenvalue_loc[2] since _k_loc[1] = _k_loc[2]
00112     //NewMAT::DiagonalMatrix  _eigenvalue_loc[4], _inv_eigenvalue_loc[4];
00113     // k_flex is the stiffness matrix + reinforcement of diagonal (used in gauss-seidel process)
00114     //NewMAT::Matrix  _k_flex;
00115     //lambda is a matrix that contains the direction of the local frame in the global frame
00116     //NewMAT::Matrix  _lambda;
00117     //non-linear value of the internal forces (computed with previous time step positions) (based on k_loc)
00118     //NewMAT::ColumnVector  _f_k;
00119     //initial deformation of the beam (gives the curvature) on the local frame
00120     //NewMAT::ColumnVector _u_init;
00121     //actual deformation of the beam on the local frame
00122     //NewMAT::ColumnVector _u_actual;
00123     
00124     //NewMAT::Matrix _Ke;
00125 
00126     Quat quat;
00127         
00128     //void localStiffness();
00129     void init(double E, double L, double nu, double r);
00130     };
00131         
00132     //just for draw forces
00133     VecDeriv _forces;
00134     
00135     topology::EdgeData<BeamInfo> beamsData;
00136 
00137     const VecElement *_indexedElements;
00138     Data< VecCoord > _initialPoints; 
00139     int _method; 
00140     Data<Real> _poissonRatio;
00141     Data<Real> _youngModulus;
00142     Data<bool> _timoshenko;
00143     Data<Real> _radius;
00144     bool _updateStiffnessMatrix; 
00145     bool _assembling; 
00146     
00147     StiffnessContainer* stiffnessContainer;
00148     LengthContainer* lengthContainer;
00149     PoissonContainer* poissonContainer;
00150     RadiusContainer* radiusContainer;
00151 
00152     Quat& beamQuat(int i) { return beamsData[i].quat; }
00153 
00154     sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00155 
00156 public:
00157     BeamFEMForceField()
00158     : _indexedElements(NULL)
00159     , _initialPoints(initData(&_initialPoints, "initialPoints", "Initial Position"))
00160     , _method(0)
00161     , _poissonRatio(initData(&_poissonRatio,(Real)0.49f,"poissonRatio","Potion Ratio"))
00162     , _youngModulus(initData(&_youngModulus,(Real)5000,"youngModulus","Young Modulus"))
00163     , _timoshenko(initData(&_timoshenko,true,"timoshenko","use Timoshenko beam (non-null section shear area)"))
00164     , _radius(initData(&_radius,(Real)0.1,"radius","radius of the section"))
00165     , _updateStiffnessMatrix(true)
00166     , _assembling(false)
00167     {
00168     
00169     }
00170 
00171     void setUpdateStiffnessMatrix(bool val) { this->_updateStiffnessMatrix = val; }
00172 
00173     void setComputeGlobalMatrix(bool val) { this->_assembling= val; }
00174     
00175 //    component::MechanicalObject<DataTypes>* getObject() { return object; }
00176 
00177     virtual void init();
00178     virtual void reinit();
00179     virtual void reinitBeam(unsigned int i);
00180     virtual void handleTopologyChange();
00181     
00182     virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00183     
00184     virtual void addDForce (VecDeriv& df, const VecDeriv& dx);
00185     
00186     virtual double getPotentialEnergy(const VecCoord&) { return 0; }
00187 
00188     void addKToMatrix(sofa::defaulttype::BaseMatrix *mat, SReal k, unsigned int &offset);
00189     
00190     void draw();
00191 
00192     void setBeam(unsigned int i, double E, double L, double nu, double r);
00193     void initBeams(unsigned int size);
00194 
00195 protected:
00196     
00197     //void computeStrainDisplacement( StrainDisplacement &J, Coord a, Coord b, Coord c, Coord d );
00198     Real peudo_determinant_for_coef ( const Mat<2, 3, Real>&  M );
00199     
00200     //void computeStiffnessMatrix( StiffnessMatrix& S,StiffnessMatrix& SR,const MaterialStiffness &K, const StrainDisplacement &J, const Transformation& Rot );
00201     
00202     //void computeMaterialStiffness(int i, Index&a, Index&b);
00203     void computeStiffness(int i, Index a, Index b);
00204     
00205     //void computeForce( Displacement &F, const Displacement &Depl, const MaterialStiffness &K, const StrainDisplacement &J );
00206     
00208     //vector<fixed_array<Coord,4> > _rotatedInitialElements;   ///< The initials positions in its frame
00209     //VecReal _initialLength;
00210     vector<Transformation> _nodeRotations;
00211     //vector<Quat> _beamQuat;
00212     void initLarge(int i, Index a, Index b);
00213     //void computeRotationLarge( Transformation &r, const Vector &p, Index a, Index b);
00214     void accumulateForceLarge( VecDeriv& f, const VecCoord& x, int i, Index a, Index b);
00215     //void accumulateDampingLarge( Vector& f, Index elementIndex );
00216     void applyStiffnessLarge( VecDeriv& f, const VecDeriv& x, int i, Index a, Index b );
00217 
00218     //sofa::helper::vector< sofa::helper::vector <Real> > subMatrix(unsigned int fr, unsigned int lr, unsigned int fc, unsigned int lc);
00219     
00220     static void BeamFEMEdgeCreationFunction(int edgeIndex, void* param, BeamInfo &ei,
00221                                             const topology::Edge& ,  const sofa::helper::vector< unsigned int > &,
00222                                             const sofa::helper::vector< double >&);
00223     
00224 };
00225 
00226 } // namespace forcefield
00227 
00228 } // namespace component
00229 
00230 } // namespace sofa
00231 
00232 #endif

Generated on Sun Nov 23 02:51:17 2008 for Sofa by  doxygen 1.5.7.1