OdeSolverImpl.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_SIMULATION_ODESOLVERIMPL_H
00026 #define SOFA_SIMULATION_ODESOLVERIMPL_H
00027 
00028 #include <sofa/core/componentmodel/behavior/OdeSolver.h>
00029 #include <sofa/core/componentmodel/behavior/LinearSolver.h>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace simulation
00035 {
00036 
00037 
00042 class SolverImpl : public virtual sofa::core::objectmodel::BaseObject
00043 {
00044 public:
00045     typedef sofa::core::componentmodel::behavior::BaseMechanicalState::VecId VecId;
00046 
00047     SolverImpl();
00048 
00049     virtual ~SolverImpl();
00050 
00055 
00059 
00063     virtual double finish();
00064 
00066     virtual VecId v_alloc(VecId::Type t);
00068     virtual void v_free(VecId v);
00069 
00070     virtual void v_clear(VecId v); 
00071     virtual void v_eq(VecId v, VecId a); 
00072     virtual void v_peq(VecId v, VecId a, double f=1.0); 
00073     virtual void v_teq(VecId v, double f); 
00074     virtual void v_op(VecId v, VecId a, VecId b, double f=1.0); 
00075     virtual void v_dot(VecId a, VecId b); 
00076     virtual void v_threshold(VecId a, double threshold); 
00077 
00078     virtual void propagateDx(VecId dx);
00080     virtual void propagateDxAndResetDf(VecId dx, VecId df);
00082     virtual void projectResponse(VecId dx, double **W=NULL);
00083     virtual void addMdx(VecId res, VecId dx=VecId(), double factor = 1.0); 
00084     virtual void integrateVelocity(VecId res, VecId x, VecId v, double dt); 
00085     virtual void accFromF(VecId a, VecId f); 
00086 
00088     virtual void computeForce(VecId result, bool clear = true, bool accumulate = true);
00090     virtual void computeDf(VecId df, bool clear = true, bool accumulate = true);
00092     virtual void computeDfV(VecId df, bool clear = true, bool accumulate = true);
00094     virtual void addMBKdx(VecId df, double m, double b, double k, bool clear = true, bool accumulate = true);
00096     virtual void addMBKv(VecId df, double m, double b, double k, bool clear = true, bool accumulate = true);
00098     virtual void addSeparateGravity(double dt);
00099 
00100     virtual void computeContactForce(VecId result);
00101     virtual void computeContactDf(VecId df);
00102 
00103 
00105 
00108 
00109     // BaseMatrix & BaseVector Computations
00110     virtual void addMBK_ToMatrix(defaulttype::BaseMatrix *A, double mFact=1.0, double bFact=1.0, double kFact=1.0, unsigned int offset=0);
00111     //virtual void addMBKdx_ToVector(defaulttype::BaseVector *V, VecId dx, double mFact=1.0, double bFact=1.0, double kFact=1.0, unsigned int offset=0);
00112     virtual void getMatrixDimension(unsigned int * const, unsigned int * const);
00113     virtual void multiVector2BaseVector(VecId src, defaulttype::BaseVector *dest=NULL, unsigned int offset=0);
00114     virtual void multiVectorPeqBaseVector(VecId dest, defaulttype::BaseVector *src=NULL, unsigned int offset=0);
00115 
00117 
00120 
00122     virtual void print( VecId v, std::ostream& out );
00123     virtual void printWithElapsedTime( VecId v,  unsigned time, std::ostream& out=std::cerr );
00124 
00126 
00128 
00129 protected:
00130 
00132     double result;
00133 
00134 };
00135 
00136 class OdeSolverImpl : public sofa::core::componentmodel::behavior::OdeSolver, public SolverImpl
00137 {
00138 public:
00139     typedef sofa::core::componentmodel::behavior::BaseMechanicalState::VecId VecId;
00140     typedef sofa::core::componentmodel::behavior::MultiVector<OdeSolverImpl> MultiVector;
00141     typedef sofa::core::componentmodel::behavior::MultiMatrix<OdeSolverImpl> MultiMatrix;
00142     typedef sofa::core::componentmodel::behavior::MechanicalMatrix MechanicalMatrix;
00143 
00145     virtual void propagatePositionAndVelocity(double t, VecId x, VecId v);
00147     virtual void computeAcc(double t, VecId a, VecId x, VecId v);
00148     virtual void computeContactAcc(double t, VecId a, VecId x, VecId v);
00149     
00152     
00153     virtual void m_resetSystem();
00154     virtual void m_setSystemMBKMatrix(double mFact, double bFact, double kFact);
00155     virtual void m_setSystemRHVector(VecId v);
00156     virtual void m_setSystemLHVector(VecId v);
00157     virtual void m_solveSystem();
00158     virtual void m_print( std::ostream& out );
00159     
00161 };
00162 
00163 } // namespace simulation
00164 
00165 } // namespace sofa
00166 
00167 #endif

Generated on Sun Nov 23 04:05:47 2008 for Sofa by  doxygen 1.5.7.1