Caribou
TractionForce.h
1 #pragma once
2 
3 #include <Eigen/Core>
4 #include <sofa/core/behavior/ForceField.h>
5 #include <SofaBaseTopology/TriangleSetTopologyContainer.h>
6 #include <SofaBaseTopology/QuadSetTopologyContainer.h>
7 #include <sofa/core/behavior/MechanicalState.h>
8 
9 namespace SofaCaribou::forcefield {
10 
11 using namespace sofa::core::objectmodel;
12 using namespace sofa::core::behavior;
13 using namespace sofa::component::topology;
14 
28 class TractionForce : public sofa::core::behavior::ForceField<sofa::defaulttype::Vec3Types>
29 {
30 public:
31  SOFA_CLASS(TractionForce, SOFA_TEMPLATE(sofa::core::behavior::ForceField, sofa::defaulttype::Vec3Types));
32 
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;
40 
41  template<int nRows, int Options=0>
42  using Vector = Eigen::Matrix<Real, nRows, 1, Options>;
43 
44  template<int nRows>
45  using MapVector = Eigen::Map<const Vector<nRows, Eigen::ColMajor>>;
46 
47  using Triange = TriangleSetTopologyContainer::Triangle;
48  using Quad = QuadSetTopologyContainer::Quad;
49 
50  using MechanicalStateLink =
51  SingleLink<TractionForce, MechanicalState<DataTypes>, BaseLink::FLAG_STRONGLINK>;
52 
53 
54  TractionForce();
55 
56  void init() override;
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* /*mparams*/, Data<VecDeriv>& /*d_df*/, const Data<VecDeriv>& /*d_dx*/) override {}
60  void addKToMatrix(sofa::defaulttype::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int & /*offset*/) 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* /*mparams*/, const Data<VecDeriv>& /* x */) const override
64  {
65  msg_error() << "Get potentialEnergy not implemented";
66  return 0.0;
67  }
68 
70  void increment_load(Deriv traction_increment_per_unit_area) ;
71 
72  // Inputs
73  Data<Deriv> d_traction;
74  Data<sofa::helper::vector<Triange> > d_triangles;
75  Data<sofa::helper::vector<Quad> > d_quads;
76  Data<Real> d_slope;
77  MechanicalStateLink d_mechanicalState;
79  Data<bool> d_draw_faces;
80 
81  // Outputs
82  Data<VecDeriv> d_nodal_forces;
83  Data<Real> d_total_load;
84 
85 private:
86 
87  bool m_traction_is_constant = false;
88  Deriv m_current_traction;
89  unsigned int m_number_of_steps_since_last_increment = 0;
90 };
91 
92 } // namespace SofaCaribou::forcefield
SofaCaribou::forcefield::TractionForce
Defines a traction (tractive force) field.
Definition: TractionForce.h:29
SofaCaribou::forcefield::TractionForce::d_number_of_steps_before_increment
Data< unsigned int > d_number_of_steps_before_increment
Number of steps to wait before a load increment. This can be used to simulate a Newton-Raphson solver...
Definition: TractionForce.h:78
SofaCaribou::forcefield::TractionForce::d_triangles
Data< sofa::helper::vector< Triange > > d_triangles
List of triangles (ex: [t1p1 t1p2 t1p3 t2p1 t2p2 t2p3 ...])
Definition: TractionForce.h:74
SofaCaribou::forcefield::TractionForce::d_draw_faces
Data< bool > d_draw_faces
Draw the faces on which the traction will be applied.
Definition: TractionForce.h:79
SofaCaribou::forcefield::TractionForce::d_total_load
Data< Real > d_total_load
Tractive force for each nodes of the surface on which we are applying the traction.
Definition: TractionForce.h:83
SofaCaribou::forcefield::TractionForce::d_mechanicalState
MechanicalStateLink d_mechanicalState
Mechanical state that contains the triangle positions.
Definition: TractionForce.h:77
SofaCaribou::forcefield::TractionForce::d_quads
Data< sofa::helper::vector< Quad > > d_quads
List of quads (ex: [q1p1 q1p2 q1p3 q1p4 q2p1 q2p2 q2p3 ...])
Definition: TractionForce.h:75
SofaCaribou::forcefield::TractionForce::d_slope
Data< Real > d_slope
Slope of force increment, the resulting traction will be p^t = p^{t-1} + p*slope. If slope = 0,...
Definition: TractionForce.h:76
SofaCaribou::forcefield::TractionForce::d_traction
Data< Deriv > d_traction
Tractive force per unit area.
Definition: TractionForce.h:73