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_CORE_COMPONENTMODEL_COLLISION_LINEARSOLVERCONTACTCORRECTION_H 00026 #define SOFA_CORE_COMPONENTMODEL_COLLISION_LINEARSOLVERCONTACTCORRECTION_H 00027 00028 #include <sofa/core/componentmodel/behavior/BaseConstraintCorrection.h> 00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h> 00030 #include <sofa/core/componentmodel/behavior/OdeSolver.h> 00031 #include <sofa/core/componentmodel/behavior/LinearSolver.h> 00032 #include <sofa/defaulttype/Mat.h> 00033 #include <sofa/defaulttype/Vec.h> 00034 #include <sofa/component/linearsolver/SparseMatrix.h> 00035 #include <sofa/component/linearsolver/FullMatrix.h> 00036 00037 namespace sofa 00038 { 00039 00040 namespace component 00041 { 00042 00043 namespace constraint 00044 { 00045 00046 using namespace sofa::core; 00047 using namespace sofa::core::componentmodel; 00048 using namespace sofa::defaulttype; 00049 00050 00051 00053 extern inline behavior::OdeSolver* getOdeSolver(objectmodel::BaseContext* context) 00054 { 00055 return context->get<behavior::OdeSolver>(); 00056 } 00057 extern inline behavior::LinearSolver* getLinearSolver(objectmodel::BaseContext* context) 00058 { 00059 return context->get<behavior::LinearSolver>(); 00060 } 00061 00062 00066 template<class TDataTypes> 00067 class LinearSolverConstraintCorrection : public componentmodel::behavior::BaseConstraintCorrection 00068 { 00069 public: 00070 typedef TDataTypes DataTypes; 00071 typedef typename DataTypes::Real Real; 00072 typedef typename componentmodel::behavior::BaseConstraintCorrection Inherit; 00073 typedef typename DataTypes::VecCoord VecCoord; 00074 typedef typename DataTypes::VecDeriv VecDeriv; 00075 typedef typename DataTypes::VecConst VecConst; 00076 typedef typename DataTypes::Coord Coord; 00077 typedef typename DataTypes::Deriv Deriv; 00078 typedef typename DataTypes::SparseVecDeriv Const; 00079 00080 LinearSolverConstraintCorrection(behavior::MechanicalState<DataTypes> *mm = NULL); 00081 00082 virtual ~LinearSolverConstraintCorrection(); 00083 00084 virtual void init(); 00085 00087 behavior::MechanicalState<DataTypes>* getMState() { return mstate; } 00088 00089 virtual void getCompliance(defaulttype::BaseMatrix* W); 00090 00091 virtual void applyContactForce(const defaulttype::BaseVector *f); 00092 virtual void resetContactForce(); 00093 00096 template<class T> 00097 static bool canCreate(T*& obj, objectmodel::BaseContext* context, objectmodel::BaseObjectDescription* arg) 00098 { 00099 if (dynamic_cast<behavior::MechanicalState<DataTypes>*>(context->getMechanicalState()) == NULL) 00100 return false; 00101 if( getOdeSolver(context)==NULL ) 00102 return false; 00103 if( getLinearSolver(context)==NULL ) 00104 return false; 00105 // if (context->get<behavior::OdeSolver>() == NULL) 00106 // return false; 00107 // if (context->get<behavior::LinearSolver>() == NULL) 00108 // return false; 00109 return BaseObject::canCreate(obj, context, arg); 00110 } 00111 00112 00113 00114 virtual std::string getTemplateName() const 00115 { 00116 return templateName(this); 00117 } 00118 00119 static std::string templateName(const LinearSolverConstraintCorrection<DataTypes>* = NULL) 00120 { 00121 return DataTypes::Name(); 00122 } 00123 00124 protected: 00125 behavior::MechanicalState<DataTypes> *mstate; 00126 behavior::OdeSolver* odesolver; 00127 behavior::LinearSolver* linearsolver; 00128 00129 linearsolver::SparseMatrix<SReal> J; 00130 linearsolver::FullVector<SReal> F; 00131 linearsolver::FullMatrix<SReal> refMinv; 00132 }; 00133 00134 00135 00136 } // namespace collision 00137 00138 } // namespace component 00139 00140 } // namespace sofa 00141 00142 #endif
1.5.7.1