Mass.inl

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 :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
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 } // namespace behavior
00127 
00128 } // namespace componentmodel
00129 
00130 } // namespace core
00131 
00132 } // namespace sofa
00133 
00134 #endif

Generated on Sun Nov 23 02:28:59 2008 for Sofa by  doxygen 1.5.7.1