Caribou
HyperelasticMaterial.h
1 #pragma once
2 
3 #include <Caribou/config.h>
4 #include <sofa/core/objectmodel/BaseObject.h>
5 #include <sofa/core/behavior/MechanicalState.h>
6 #include <Eigen/Eigen>
7 
8 namespace SofaCaribou::material {
9 
10 template<class DataTypes>
11 class HyperelasticMaterial : public sofa::core::objectmodel::BaseObject {
12  static constexpr auto Dimension = DataTypes::spatial_dimensions;
13  using Coord = typename DataTypes::Coord;
14  using Real = typename Coord::value_type;
15 public:
16 
17  SOFA_CLASS(SOFA_TEMPLATE(HyperelasticMaterial, DataTypes), sofa::core::objectmodel::BaseObject);
18 
24  virtual void
26 
30  virtual Real
31  strain_energy_density(const Real & J, const Eigen::Matrix<Real, Dimension, Dimension> & C) const = 0;
32 
41  virtual Eigen::Matrix<Real, Dimension, Dimension>
42  PK2_stress(const Real & J, const Eigen::Matrix<Real, Dimension, Dimension> & C) const = 0;
43 
52  virtual Eigen::Matrix<Real, 6, 6>
53  PK2_stress_jacobian(const Real & J, const Eigen::Matrix<Real, Dimension, Dimension> & C) const = 0;
54 
55 
56  // Sofa's scene methods
57 
59  static std::string templateName(const HyperelasticMaterial<DataTypes>* = nullptr) {
60  return DataTypes::Name();
61  }
62 
70  static bool canCreate(HyperelasticMaterial<DataTypes>* o, sofa::core::objectmodel::BaseContext* context, sofa::core::objectmodel::BaseObjectDescription* arg) {
71  std::string requested_data_type = arg->getAttribute( "template", "");
72  std::string this_data_type = templateName(o);
73 
74  if (requested_data_type == this_data_type) {
75  return true;
76  }
77 
78  if (not requested_data_type.empty()) {
79  arg->logError("Requested data type ('" +requested_data_type + "') is not '"+this_data_type+"'.");
80  return false;
81  }
82 
83  if (dynamic_cast<sofa::core::behavior::MechanicalState<DataTypes>*>(context->getMechanicalState()) != nullptr) {
84  return true;
85  }
86 
87  arg->logError("Cannot deduce the data type from the current context. Set the argument 'template=\""+this_data_type+"\"' to correct this.");
88  return false;
89  }
90 
91 };
92 
93 } // namespace SofaCaribou::material
SofaCaribou::material::HyperelasticMaterial
Definition: HyperelasticMaterial.h:11
SofaCaribou::material::HyperelasticMaterial::templateName
static std::string templateName(const HyperelasticMaterial< DataTypes > *=nullptr)
Return the data type (ex.
Definition: HyperelasticMaterial.h:59
SofaCaribou::material::HyperelasticMaterial::before_update
virtual void before_update()
This is called just before the material is updated on every points (usually just before a Newton step...
Definition: HyperelasticMaterial.h:25
SofaCaribou::material::HyperelasticMaterial::PK2_stress
virtual Eigen::Matrix< Real, Dimension, Dimension > PK2_stress(const Real &J, const Eigen::Matrix< Real, Dimension, Dimension > &C) const =0
Get the second Piola-Kirchhoff stress tensor from the right Cauchy-Green strain tensor C.
SofaCaribou::material::HyperelasticMaterial::canCreate
static bool canCreate(HyperelasticMaterial< DataTypes > *o, sofa::core::objectmodel::BaseContext *context, sofa::core::objectmodel::BaseObjectDescription *arg)
Check if we can create a HyperelasticMaterial<DataTypes> with the given template argument (from the s...
Definition: HyperelasticMaterial.h:70
SofaCaribou::material::HyperelasticMaterial::PK2_stress_jacobian
virtual Eigen::Matrix< Real, 6, 6 > PK2_stress_jacobian(const Real &J, const Eigen::Matrix< Real, Dimension, Dimension > &C) const =0
Get the jacobian of the second Piola-Kirchhoff stress tensor w.r.t the right Cauchy-Green strain tens...
SofaCaribou::material::HyperelasticMaterial::strain_energy_density
virtual Real strain_energy_density(const Real &J, const Eigen::Matrix< Real, Dimension, Dimension > &C) const =0
Get the strain energy density Psi from the right Cauchy-Green strain tensor C.