TensorForceField.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_TENSORFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TENSORFORCEFIELD_H
00027 
00028 
00029 #include <sofa/core/componentmodel/behavior/ForceField.h>
00030 #include <sofa/component/MechanicalObject.h>
00031 
00032 
00033 namespace sofa
00034 {
00035 
00036 namespace component
00037 {
00038 
00039 namespace forcefield
00040 {
00041 
00050 template <class DataTypes>
00051 class TensorForceField : public core::componentmodel::behavior::BaseForceField
00052 {
00053 public:
00054 
00055   TensorForceField (const char *filename);
00056 
00057     
00058   TensorForceField (component::MechanicalObject<DataTypes>* object,
00059                         const char* filename);
00060 
00061    
00062   virtual void addForce ();
00063 
00064   
00065   virtual void addDForce();
00066   
00067   virtual double getPotentialEnergy();
00068 
00069   void draw();
00070 
00071 
00072 public:
00073   typedef typename DataTypes::VecCoord VecCoord;
00074   typedef typename DataTypes::VecDeriv VecDeriv;
00075   typedef typename DataTypes::Coord    Coord   ;
00076   typedef typename DataTypes::Deriv    Deriv   ;
00077   typedef typename Coord::value_type   Real    ;
00078     class VertexTensor {
00079     public:
00080       Real tensor[3][3];
00081         
00082       void resetToNull() {
00083           for (int i = 0; i < 3; ++i) {
00084             for (int j = 0; j < 3; ++j) {
00085               tensor[i][j] = 0.0;
00086             }
00087           }
00088       }
00089 
00090     }; //class VertexTensor
00091 
00092 
00093 
00094     class Edge {
00095     public:
00096         int index;
00097       
00098         int vertex[2];
00099       
00100     }; // class Edge
00101 
00102 
00103 
00104     class EdgeTensor {
00105     public:
00106       Real tensor[3][3];
00107       
00108       void resetToNull() {
00109           for (int i = 0; i < 3; ++i) {
00110             for (int j = 0; j < 3; ++j) {
00111               tensor[i][j] = 0.0;
00112             }
00113           }
00114       }
00115 
00116     }; // class EdgeTensor
00117 
00118 
00119 
00120     class Triangle {
00121     public:
00122         int index;
00123       
00124         int vertex[3];
00125       
00126       double shapeVector[3];
00127       double squareRestArea;
00128       
00129     }; // class Triangle
00130 
00131 
00132 
00133     class Tetrahedron {
00134     public:
00135         int index;
00136       
00137         int vertex  [4];
00138         int edge    [6];
00139         int triangle[4];
00140 
00141       Real triangleShapeVector[4][3];
00142         Real restVolume;
00143       
00144     }; // class Tetrahedron
00145 
00146 
00147 private: 
00148     // Mechanical Object containing this Force Field
00149     component::MechanicalObject<DataTypes>* object_;
00150     // damping factor
00151     Real alpha_;
00152     // Lame coefficient
00153     Real lambda_, mu_;
00154     sofa::helper::vector< Coord >    vertex_      ;
00155     sofa::helper::vector< Edge >         edge_        ;
00156     sofa::helper::vector< Triangle >     triangle_    ;
00157     sofa::helper::vector< Tetrahedron >  tetrahedron_ ;
00158     sofa::helper::vector< VertexTensor > vertexTensor_;
00159     sofa::helper::vector< EdgeTensor >   edgeTensor_  ;
00160 
00161 private:
00162     // load the topological informations from a file.
00163     void load(const char *filename);
00164     
00165     // initialize the tensors
00166     void initialize();
00167     
00168     // search for the edge connecting the given vertices, create it if not found
00169     int getEdge(const int v0, const int v1);
00170     
00171     // search for the triangle connecting the given vertices, create it if not found
00172     int getTriangle(const int v0, const int v1, const int v2);
00173     
00174     // add the elastic tensors for this tetrahedron
00175     void addElasticTensors(Tetrahedron& tetra);
00176     
00177 }; // class TensorForceField
00178 
00179 
00180 
00181 } // namespace forcefield
00182 
00183 } // namespace component
00184 
00185 } // namespace sofa
00186 
00187 #endif /* _TENSORMASSFORCEFIELD_H_ */

Generated on Sun Nov 23 03:12:38 2008 for Sofa by  doxygen 1.5.7.1