StaticSolver.cpp

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 // Author: François Faure, INRIA-UJF, (C) 2006
00026 //
00027 // Copyright: See COPYING file that comes with this distribution
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); // v += dt*g . Used if mass wants to added G separately from the other forces to v.
00063 
00064     // compute the right-hand term of the equation system
00065     this->computeForce(b);             // b = f0
00066     this->projectResponse(b);         // b is projected to the constrained space
00067     b.teq(-1);
00068 
00069     if( f_printLog.getValue() )
00070         cerr<<"StaticSolver, f0 = "<< b <<endl;
00071     MultiMatrix matrix(this);
00072     //matrix = MechanicalMatrix::K;
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     // x is the solution of the system
00080     
00081     // apply the solution
00082     /*    cerr<<"StaticSolver::solve, nb iter = "<<nb_iter<<endl;
00083      cerr<<"StaticSolver::solve, solution = "<<x<<endl;*/
00084 
00085     if( f_printLog.getValue() )
00086         cerr<<"StaticSolver, solution = "<< x <<endl;
00087     pos.peq( x );
00088     /*    cerr<<"StaticSolver::solve, new pos = "<<pos<<endl;*/
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 } // namespace odesolver
00098 
00099 } // namespace component
00100 
00101 } // namespace sofa
00102 

Generated on Sun Nov 23 03:42:46 2008 for Sofa by  doxygen 1.5.7.1