MixedInteractionForceField.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 :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MIXEDINTERACTIONFORCEFIELD_H
00028 #define SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MIXEDINTERACTIONFORCEFIELD_H
00029 
00030 #include <sofa/core/componentmodel/behavior/InteractionForceField.h>
00031 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00032 #include <sofa/defaulttype/Vec.h>
00033 
00034 namespace sofa
00035 {
00036 
00037 namespace core
00038 {
00039 
00040 namespace componentmodel
00041 {
00042 
00043 namespace behavior
00044 {
00045 
00052 template<class TDataTypes1, class TDataTypes2>
00053 class MixedInteractionForceField : public InteractionForceField
00054 {
00055 public:
00056     typedef TDataTypes1 DataTypes1;
00057     typedef typename DataTypes1::VecCoord VecCoord1;
00058     typedef typename DataTypes1::VecDeriv VecDeriv1;
00059     typedef typename DataTypes1::Coord Coord1;
00060     typedef typename DataTypes1::Deriv Deriv1;
00061     typedef TDataTypes2 DataTypes2;
00062     typedef typename DataTypes2::VecCoord VecCoord2;
00063     typedef typename DataTypes2::VecDeriv VecDeriv2;
00064     typedef typename DataTypes2::Coord Coord2;
00065     typedef typename DataTypes2::Deriv Deriv2;
00066     
00067     MixedInteractionForceField(MechanicalState<DataTypes1> *mm1 = NULL, MechanicalState<DataTypes2> *mm2 = NULL);
00068 
00069     virtual ~MixedInteractionForceField();
00070 
00071     virtual void init();
00072 
00074     MechanicalState<DataTypes1>* getMState1() { return mstate1; }
00075     BaseMechanicalState* getMechModel1() { return mstate1; }
00077     MechanicalState<DataTypes2>* getMState2() { return mstate2; }
00078     BaseMechanicalState* getMechModel2() { return mstate2; }
00079 
00082 
00093     virtual void addForce();
00094 
00108     virtual void addDForce(double kFactor, double bFactor);
00109 
00118     virtual void addDForceV(double kFactor, double bFactor);
00119 
00128     virtual double getPotentialEnergy();
00129 
00139     virtual void addForce(VecDeriv1& f1, VecDeriv2& f2, const VecCoord1& x1, const VecCoord2& x2, const VecDeriv1& v1, const VecDeriv2& v2) = 0;
00140 
00157     virtual void addDForce(VecDeriv1& df1, VecDeriv2& df2, const VecDeriv1& dx1, const VecDeriv2& dx2);
00158 
00175     virtual void addDForce(VecDeriv1& df1, VecDeriv2& df2, const VecDeriv1& dx1, const VecDeriv2& dx2, double kFactor, double bFactor);
00176 
00184     virtual double getPotentialEnergy(const VecCoord1& x1, const VecCoord2& x2) =0;
00185 
00187 
00190     template<class T>
00191     static bool canCreate(T*& obj, objectmodel::BaseContext* context, objectmodel::BaseObjectDescription* arg)
00192     {
00193         if (arg->getAttribute("object1") || arg->getAttribute("object2"))
00194         {
00195             if (dynamic_cast<MechanicalState<DataTypes1>*>(arg->findObject(arg->getAttribute("object1",".."))) == NULL)
00196                 return false;
00197             if (dynamic_cast<MechanicalState<DataTypes2>*>(arg->findObject(arg->getAttribute("object2",".."))) == NULL)
00198                 return false;
00199         }
00200         return InteractionForceField::canCreate(obj, context, arg);
00201     }
00202 
00204     template<class T>
00205     static void create(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00206     {
00207         core::componentmodel::behavior::InteractionForceField::create(obj, context, arg);
00208         if (arg && (arg->getAttribute("object1") || arg->getAttribute("object2")))
00209         {
00210             obj->mstate1 = dynamic_cast<MechanicalState<DataTypes1>*>(arg->findObject(arg->getAttribute("object1","..")));
00211             obj->mstate2 = dynamic_cast<MechanicalState<DataTypes2>*>(arg->findObject(arg->getAttribute("object2","..")));
00212         }
00213     }
00214 
00215     virtual std::string getTemplateName() const
00216     {
00217         return templateName(this);
00218     }
00219 
00220     static std::string templateName(const MixedInteractionForceField<DataTypes1,DataTypes2>* = NULL)
00221     {
00222         return DataTypes1::Name()+std::string(",")+DataTypes2::Name();
00223     }
00224 
00225 protected:
00226     MechanicalState<DataTypes1> *mstate1;
00227     MechanicalState<DataTypes2> *mstate2;
00228 };
00229 
00230 } // namespace behavior
00231 
00232 } // namespace componentmodel
00233 
00234 } // namespace core
00235 
00236 } // namespace sofa
00237 
00238 #endif

Generated on Sun Nov 23 02:29:12 2008 for Sofa by  doxygen 1.5.7.1