Mass.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MASS_INL
00028 #define SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MASS_INL
00029
00030 #include <sofa/core/componentmodel/behavior/Mass.h>
00031 #include <sofa/core/componentmodel/behavior/ForceField.inl>
00032
00033 namespace sofa
00034 {
00035
00036 namespace core
00037 {
00038
00039 namespace componentmodel
00040 {
00041
00042 namespace behavior
00043 {
00044
00045 template<class DataTypes>
00046 Mass<DataTypes>::Mass(MechanicalState<DataTypes> *mm)
00047 : ForceField<DataTypes>(mm),m_gnuplotFileEnergy(NULL)
00048 {
00049 m_separateGravity = initData(&m_separateGravity , false, "separateGravity", "add separately gravity to velocity computation") ;
00050 }
00051
00052 template<class DataTypes>
00053 Mass<DataTypes>::~Mass()
00054 {
00055 }
00056
00057 template<class DataTypes>
00058 void Mass<DataTypes>::addMDx(double factor)
00059 {
00060 if (this->mstate)
00061 addMDx(*this->mstate->getF(), *this->mstate->getDx(), factor);
00062 }
00063
00064 template<class DataTypes>
00065 void Mass<DataTypes>::accFromF()
00066 {
00067 if (this->mstate)
00068 accFromF(*this->mstate->getDx(), *this->mstate->getF());
00069 }
00070
00071 template<class DataTypes>
00072 double Mass<DataTypes>::getKineticEnergy()
00073 {
00074 if (this->mstate)
00075 return getKineticEnergy(*this->mstate->getV());
00076 return 0;
00077 }
00078
00079 template<class DataTypes>
00080 void Mass<DataTypes>::addMBKdx(double mFactor, double bFactor, double kFactor)
00081 {
00082 this->ForceField<DataTypes>::addMBKdx(mFactor, bFactor, kFactor);
00083 if (mFactor != 0.0)
00084 addMDx(mFactor);
00085 }
00086
00087 template<class DataTypes>
00088 void Mass<DataTypes>::addMBKv(double mFactor, double bFactor, double kFactor)
00089 {
00090 this->ForceField<DataTypes>::addMBKv(mFactor, bFactor, kFactor);
00091 if (mFactor != 0.0)
00092 {
00093 if (this->mstate)
00094 addMDx(*this->mstate->getF(), *this->mstate->getV(), mFactor);
00095 }
00096 }
00097
00098 template<class DataTypes>
00099 void Mass<DataTypes>::addMBKToMatrix(sofa::defaulttype::BaseMatrix * matrix, double mFact, double bFact, double kFact, unsigned int &offset)
00100 {
00101 this->ForceField<DataTypes>::addMBKToMatrix(matrix, mFact, bFact, kFact, offset);
00102 if (mFact != 0.0)
00103 addMToMatrix(matrix, mFact, offset);
00104 }
00105
00106 template<class DataTypes>
00107 void Mass<DataTypes>::initGnuplot(const std::string path)
00108 {
00109 if( !this->getName().empty() ){
00110
00111 if (m_gnuplotFileEnergy != NULL) delete m_gnuplotFileEnergy;
00112 m_gnuplotFileEnergy = new std::ofstream( (path+this->getName()+"_Energy.txt").c_str() );
00113
00114 }
00115 }
00116
00117 template<class DataTypes>
00118 void Mass<DataTypes>::exportGnuplot(double time)
00119 {
00120 if( m_gnuplotFileEnergy!=NULL ){
00121 (*m_gnuplotFileEnergy) << time <<"\t"<< this->getKineticEnergy() <<"\t"<< this->getPotentialEnergy() <<"\t"<< this->getPotentialEnergy()+this->getKineticEnergy()<< std::endl;
00122 }
00123 }
00124
00125
00126 }
00127
00128 }
00129
00130 }
00131
00132 }
00133
00134 #endif