StaticSolver.cpp
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
00028 #include <sofa/component/odesolver/StaticSolver.h>
00029 #include <sofa/core/ObjectFactory.h>
00030 #include <math.h>
00031 #include <iostream>
00032
00033 using std::cout;
00034 using std::cerr;
00035 using std::endl;
00036
00037 namespace sofa
00038 {
00039
00040 namespace component
00041 {
00042
00043 namespace odesolver
00044 {
00045
00046 using namespace sofa::defaulttype;
00047 using namespace core::componentmodel::behavior;
00048
00049 StaticSolver::StaticSolver()
00050 : massCoef( initData(&massCoef,(double)0.0,"massCoef","coefficient associated with the mass matrix in the equation system") )
00051 , dampingCoef( initData(&dampingCoef,(double)0.0,"dampingCoef","coefficient associated with the mass matrix in the equation system") )
00052 , stiffnessCoef( initData(&stiffnessCoef,(double)1.0,"stiffnessCoef","coefficient associated with the mass matrix in the equation system") )
00053 {
00054 }
00055
00056 void StaticSolver::solve(double dt)
00057 {
00058 MultiVector b(this, VecId::V_DERIV);
00059 MultiVector x(this, VecId::V_DERIV);
00060 MultiVector pos(this, VecId::position());
00061
00062 addSeparateGravity(dt);
00063
00064
00065 this->computeForce(b);
00066 this->projectResponse(b);
00067 b.teq(-1);
00068
00069 if( f_printLog.getValue() )
00070 cerr<<"StaticSolver, f0 = "<< b <<endl;
00071 MultiMatrix matrix(this);
00072
00073 matrix = MechanicalMatrix(massCoef.getValue(),dampingCoef.getValue(),stiffnessCoef.getValue());
00074
00075 if( f_printLog.getValue() )
00076 cerr<<"StaticSolver, matrix = "<< (MechanicalMatrix::K) << " = " << matrix <<endl;
00077
00078 matrix.solve(x,b);
00079
00080
00081
00082
00083
00084
00085 if( f_printLog.getValue() )
00086 cerr<<"StaticSolver, solution = "<< x <<endl;
00087 pos.peq( x );
00088
00089 }
00090
00091 int StaticSolverClass = core::RegisterObject("A solver which seeks the static equilibrium of the scene it monitors")
00092 .add< StaticSolver >();
00093
00094 SOFA_DECL_CLASS(StaticSolver)
00095
00096
00097 }
00098
00099 }
00100
00101 }
00102