TriangleFEMForceField.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_TRIANGLEFEMFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGLEFEMFORCEFIELD_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 
00037 
00038 // corotational triangle from
00039 // @InProceedings{NPF05,
00040 //   author       = "Nesme, Matthieu and Payan, Yohan and Faure, Fran\c{c}ois",
00041 //   title        = "Efficient, Physically Plausible Finite Elements",
00042 //   booktitle    = "Eurographics (short papers)",
00043 //   month        = "august",
00044 //   year         = "2005",
00045 //   editor       = "J. Dingliana and F. Ganovelli",
00046 //   keywords     = "animation, physical model, elasticity, finite elements",
00047 //   url          = "http://www-evasion.imag.fr/Publications/2005/NPF05"
00048 // }
00049 
00050 
00051 
00052 namespace sofa
00053 {
00054 
00055 namespace component
00056 {
00057 
00058 namespace forcefield
00059 {
00060 
00061 using namespace sofa::defaulttype;
00062 
00063 
00064 template<class DataTypes>
00065 class TriangleFEMForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00066 {
00067 public:
00068   typedef core::componentmodel::behavior::ForceField<DataTypes> Inherited;
00069     typedef typename DataTypes::VecCoord VecCoord;
00070     typedef typename DataTypes::VecDeriv VecDeriv;
00071     typedef typename DataTypes::Coord    Coord   ;
00072     typedef typename DataTypes::Deriv    Deriv   ;
00073     typedef typename Coord::value_type   Real    ;
00074 
00075     typedef sofa::core::componentmodel::topology::BaseMeshTopology::index_type Index;
00076     typedef sofa::core::componentmodel::topology::BaseMeshTopology::Triangle Element;
00077     typedef sofa::core::componentmodel::topology::BaseMeshTopology::SeqTriangles VecElement;
00078 
00079     static const int SMALL = 1;                                     
00080     static const int LARGE = 0;                                     
00081 
00082 protected:
00083 //    component::MechanicalObject<DataTypes>* _object;
00084 
00085     typedef Vec<6, Real> Displacement;                              
00086 
00087     typedef Mat<3, 3, Real> MaterialStiffness;                      
00088     typedef sofa::helper::vector<MaterialStiffness> VecMaterialStiffness;    
00089     VecMaterialStiffness _materialsStiffnesses;                     
00090 
00091     typedef Mat<6, 3, Real> StrainDisplacement;                     
00092     typedef sofa::helper::vector<StrainDisplacement> VecStrainDisplacement; 
00093     VecStrainDisplacement _strainDisplacements;                     
00094 
00095     typedef Mat<3, 3, Real > Transformation;                        
00096 
00097 
00098     sofa::core::componentmodel::topology::BaseMeshTopology* _mesh;
00099     const VecElement *_indexedElements;
00100     Data< VecCoord > _initialPoints; 
00101 //     int _method; ///< the computation method of the displacements
00102 //     Real _poissonRatio;
00103 //     Real _youngModulus;
00104 //     Real _dampingRatio;
00105 
00106 public:
00107 
00108     TriangleFEMForceField();
00109 
00110     //virtual const char* getTypeName() const { return "TriangleFEMForceField"; }
00111 
00112     virtual ~TriangleFEMForceField();
00113 
00114 
00115     virtual void init();
00116     virtual void reinit();
00117     virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00118     
00119     virtual void addDForce (VecDeriv& df, const VecDeriv& dx);
00120         
00121     virtual double getPotentialEnergy(const VecCoord& x);
00122 
00123 
00124     void draw();
00125 
00126     int method;
00127     Data<std::string> f_method;
00128     Data<Real> f_poisson;
00129     Data<Real> f_young;
00130     Data<Real> f_damping;
00131 
00132     Real getPoisson() { return f_poisson.getValue(); }
00133     void setPoisson(Real val) { f_poisson.setValue(val); }
00134     Real getYoung() { return f_young.getValue(); }
00135     void setYoung(Real val) { f_young.setValue(val); }
00136     Real getDamping() { return f_damping.getValue(); }
00137     void setDamping(Real val) { f_damping.setValue(val); }
00138     int  getMethod() { return method; }
00139     void setMethod(int val) { method = val; }
00140 
00141 //     component::MechanicalObject<DataTypes>* getObject()
00142 //     {
00143 //         return _object;
00144 //     }
00145 
00146 protected :
00147 
00149     virtual void applyStiffness( VecCoord& f, Real h, const VecCoord& x );
00150     void computeStrainDisplacement( StrainDisplacement &J, Coord a, Coord b, Coord c);
00151     void computeMaterialStiffnesses();
00152     void computeForce( Displacement &F, const Displacement &Depl, const MaterialStiffness &K, const StrainDisplacement &J );
00153 
00155     void initSmall();
00156     void accumulateForceSmall( VecCoord& f, const VecCoord & p, Index elementIndex, bool implicit = false );
00157     void accumulateDampingSmall( VecCoord& f, Index elementIndex );
00158     void applyStiffnessSmall( VecCoord& f, Real h, const VecCoord& x );
00159 
00161     sofa::helper::vector< helper::fixed_array <Coord, 3> > _rotatedInitialElements;   
00162     sofa::helper::vector< Transformation > _rotations;
00163     void initLarge();
00164     void computeRotationLarge( Transformation &r, const VecCoord &p, const Index &a, const Index &b, const Index &c);
00165     void accumulateForceLarge( VecCoord& f, const VecCoord & p, Index elementIndex, bool implicit=false );
00166     void accumulateDampingLarge( VecCoord& f, Index elementIndex );
00167     void applyStiffnessLarge( VecCoord& f, Real h, const VecCoord& x );
00168 };
00169 
00170 
00171 } // namespace forcefield
00172 
00173 } // namespace component
00174 
00175 } // namespace sofa
00176 
00177 #endif

Generated on Sun Nov 23 03:14:59 2008 for Sofa by  doxygen 1.5.7.1