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 #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
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
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 }
00164
00165 }
00166
00167 #endif