4 #include <sofa/core/behavior/ForceField.h>
5 #include <SofaBaseTopology/TriangleSetTopologyContainer.h>
6 #include <SofaBaseTopology/QuadSetTopologyContainer.h>
7 #include <sofa/core/behavior/MechanicalState.h>
9 namespace SofaCaribou::forcefield {
11 using namespace sofa::core::objectmodel;
12 using namespace sofa::core::behavior;
13 using namespace sofa::component::topology;
28 class TractionForce :
public sofa::core::behavior::ForceField<sofa::defaulttype::Vec3Types>
31 SOFA_CLASS(
TractionForce, SOFA_TEMPLATE(sofa::core::behavior::ForceField, sofa::defaulttype::Vec3Types));
33 typedef sofa::defaulttype::Vec3Types DataTypes;
34 typedef typename DataTypes::VecCoord VecCoord;
35 typedef typename DataTypes::VecDeriv VecDeriv;
36 typedef typename DataTypes::Coord Coord ;
37 typedef typename DataTypes::Deriv Deriv ;
38 typedef typename Coord::value_type Real ;
39 typedef sofa::defaulttype::Mat<3,3,Real> Mat33;
41 template<
int nRows,
int Options=0>
42 using Vector = Eigen::Matrix<Real, nRows, 1, Options>;
45 using MapVector = Eigen::Map<const Vector<nRows, Eigen::ColMajor>>;
47 using Triange = TriangleSetTopologyContainer::Triangle;
48 using Quad = QuadSetTopologyContainer::Quad;
50 using MechanicalStateLink =
51 SingleLink<TractionForce, MechanicalState<DataTypes>, BaseLink::FLAG_STRONGLINK>;
57 void reset()
override;
58 void addForce(
const sofa::core::MechanicalParams* mparams, Data<VecDeriv>& d_f,
const Data<VecCoord>& d_x,
const Data<VecDeriv>& d_v)
override;
59 void addDForce(
const sofa::core::MechanicalParams* , Data<VecDeriv>& ,
const Data<VecDeriv>& )
override {}
60 void addKToMatrix(sofa::defaulttype::BaseMatrix * , SReal ,
unsigned int & )
override {}
61 void draw(
const sofa::core::visual::VisualParams* vparams)
override;
62 void handleEvent(sofa::core::objectmodel::Event* event)
override;
63 SReal getPotentialEnergy(
const sofa::core::MechanicalParams* ,
const Data<VecDeriv>& )
const override
65 msg_error() <<
"Get potentialEnergy not implemented";
70 void increment_load(Deriv traction_increment_per_unit_area) ;
75 Data<sofa::helper::vector<Quad> >
d_quads;
82 Data<VecDeriv> d_nodal_forces;
87 bool m_traction_is_constant =
false;
88 Deriv m_current_traction;
89 unsigned int m_number_of_steps_since_last_increment = 0;