TriangularFEMForceField.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_TRIANGULARFEMFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGULARFEMFORCEFIELD_H
00027 
00028 #if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
00029 #pragma once
00030 #endif
00031 
00032 #include <sofa/core/componentmodel/behavior/ForceField.h>
00033 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00034 #include <sofa/defaulttype/Vec.h>
00035 #include <sofa/defaulttype/Mat.h>
00036 #include <sofa/component/topology/TriangleData.h>
00037 #include <sofa/component/topology/EdgeData.h>
00038 #include <sofa/component/topology/PointData.h>
00039 #include <newmat/newmat.h>
00040 #include <newmat/newmatap.h>
00041 
00042 
00043 
00044 namespace sofa
00045 {
00046 
00047 namespace component
00048 {
00049 
00050 namespace forcefield
00051 {
00052 
00053 using namespace sofa::defaulttype;
00054 using sofa::helper::vector;
00055 using namespace sofa::component::topology;
00056 
00057 
00070 template<class DataTypes>
00071 class TriangularFEMForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00072 {
00073 public:
00074   typedef core::componentmodel::behavior::ForceField<DataTypes> Inherited;
00075     typedef typename DataTypes::VecCoord VecCoord;
00076     typedef typename DataTypes::VecDeriv VecDeriv;
00077     typedef typename DataTypes::VecReal VecReal;
00078     typedef VecCoord Vector;
00079     typedef typename DataTypes::Coord    Coord   ;
00080     typedef typename DataTypes::Deriv    Deriv   ;
00081     typedef typename Coord::value_type   Real    ;
00082 
00083     typedef sofa::core::componentmodel::topology::BaseMeshTopology::index_type Index;
00084     typedef sofa::core::componentmodel::topology::BaseMeshTopology::Triangle Element;
00085     typedef sofa::core::componentmodel::topology::BaseMeshTopology::SeqTriangles VecElement;
00086 
00087     static const int SMALL = 1;                                     
00088     static const int LARGE = 0;                                     
00089 
00090     
00091 protected:
00092 //    component::MechanicalObject<DataTypes>* _object;
00093 
00094     typedef Vec<6, Real> Displacement;                              
00095     typedef Mat<3, 3, Real> MaterialStiffness;                      
00096     typedef sofa::helper::vector<MaterialStiffness> VecMaterialStiffness;    
00097     typedef Mat<6, 3, Real> StrainDisplacement;                     
00098     typedef sofa::helper::vector<StrainDisplacement> VecStrainDisplacement; 
00099     typedef Mat<3, 3, Real > Transformation;                        
00100 
00101    class TriangleInformation
00102     {
00103     public:
00105         MaterialStiffness materialMatrix;
00107         StrainDisplacement strainDisplacementMatrix;
00108         // large displacement method
00109         helper::fixed_array<Coord,3> rotatedInitialElements;
00110         Transformation rotation;
00112         Transformation initialTransformation;
00113         
00114         Coord principalStrainDirection;
00115         double eigenValue;
00116 
00117         TriangleInformation() {
00118         }
00119     };
00120 
00121    class EdgeInformation
00122    {
00123    public:
00124        EdgeInformation()
00125            :fracturable(false){};
00126 
00127        bool fracturable;
00128    };
00129 
00130    class VertexInformation
00131    {
00132    public:
00133         VertexInformation()
00134             :sumEigenValues(0.0){};
00135 
00136        Coord meanStrainDirection;
00137        double sumEigenValues;
00138    };
00139     
00140     TriangleData<TriangleInformation> triangleInfo;
00141     PointData<VertexInformation> vertexInfo;
00142     EdgeData<EdgeInformation> edgeInfo;
00143 
00144     sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00145     //const VecElement *_indexedElements;
00146     //Data< VecCoord > _initialPoints; ///< the intial positions of the points
00147     VecCoord* _initialPoints;
00148 //     int _method; ///< the computation method of the displacements
00149 //     Real _poissonRatio;
00150 //     Real _youngModulus;
00151 //     Real _dampingRatio;
00152 
00153     bool updateMatrix;
00154     int lastFracturedEdgeIndex;
00155 
00156 public:
00157 
00158     TriangularFEMForceField();
00159 
00160     //virtual const char* getTypeName() const { return "TriangularFEMForceField"; }
00161 
00162     virtual ~TriangularFEMForceField();
00163     virtual void init();
00164     virtual void reinit();
00165     virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00166     virtual void addDForce (VecDeriv& df, const VecDeriv& dx);
00167     virtual double getPotentialEnergy(const VecCoord& x);
00168     virtual void handleTopologyChange();
00169 
00170     void draw();
00171 
00172     int method;
00173     Data<std::string> f_method;
00174     Data<Real> f_poisson;
00175     Data<Real> f_young;
00176     Data<Real> f_damping;
00177     Data<bool> f_fracturable;
00178 
00179     Data<bool> showStressValue;
00180     Data<bool> showStressVector;
00181 
00182     Real getPoisson() { return f_poisson.getValue(); }
00183     void setPoisson(Real val) { f_poisson.setValue(val); }
00184     Real getYoung() { return f_young.getValue(); }
00185     void setYoung(Real val) { f_young.setValue(val); }
00186     Real getDamping() { return f_damping.getValue(); }
00187     void setDamping(Real val) { f_damping.setValue(val); }
00188     int  getMethod() { return method; }
00189     void setMethod(int val) { method = val; }
00190     int getFracturedEdge();
00191 
00192 protected :
00193 
00194     void computeEigenStrain( Coord &v, StrainDisplacement &J, Displacement &Depl , double &maxEigenValue);
00195 
00196     //EdgeData<EdgeInformation> &getEdgeInfo() {return edgeInfo;}
00197 
00198 /*  
00199     static void TRQSEdgeCreationFunction(int edgeIndex, void* param, EdgeInformation &ei,
00200                                          const Edge& ,  const sofa::helper::vector< unsigned int > &,
00201                                          const sofa::helper::vector< double >&);
00202 */  
00203     static void TRQSTriangleCreationFunction (int , void* , 
00204                             TriangleInformation &,
00205                             const Triangle& , const sofa::helper::vector< unsigned int > &, const sofa::helper::vector< double >&);
00206                                     
00207 
00208     //static void TRQSTriangleDestroyFunction ( int , void* , TriangleInformation &);
00209 
00211     virtual void applyStiffness( VecCoord& f, Real h, const VecCoord& x );
00212     virtual void computeMaterialStiffness(int i, Index& a, Index& b, Index& c);
00213     void computeStrainDisplacement( StrainDisplacement &J, Coord a, Coord b, Coord c);
00214     void computeForce( Displacement &F, const Displacement &Depl, const MaterialStiffness &K, const StrainDisplacement &J );
00215 
00217     void initSmall(void);
00218     void accumulateForceSmall( VecCoord& f, const VecCoord & p, Index elementIndex, bool implicit = false );
00219     void accumulateDampingSmall( VecCoord& f, Index elementIndex );
00220     void applyStiffnessSmall( VecCoord& f, Real h, const VecCoord& x );
00221 
00223     //sofa::helper::vector< helper::fixed_array <Coord, 3> > _rotatedInitialElements;   ///< The initials positions in its frame
00224     //sofa::helper::vector< Transformation > _rotations;
00225     void initLarge(int i, Index&a, Index&b, Index&c);
00226     void computeRotationLarge( Transformation &r, const VecCoord &p, const Index &a, const Index &b, const Index &c);
00227     void accumulateForceLarge( VecCoord& f, const VecCoord & p, Index elementIndex, bool implicit=false );
00228     void accumulateDampingLarge( VecCoord& f, Index elementIndex );
00229     void applyStiffnessLarge( VecCoord& f, Real h, const VecCoord& x );
00230 };
00231 
00232 
00233 } // namespace forcefield
00234 
00235 } // namespace component
00236 
00237 } // namespace sofa
00238 
00239 #endif

Generated on Sun Nov 23 03:18:53 2008 for Sofa by  doxygen 1.5.7.1