PolyFEM
Loading...
Searching...
No Matches
MooneyRivlin3ParamSymbolic.hpp
Go to the documentation of this file.
1#pragma once
2
7
8// non linear NeoHookean material model
9namespace polyfem::assembler
10{
11 template <typename T>
12 using AutoDiffGradMat = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3>;
13 template <typename T>
14 using AutoDiffVect = Eigen::Matrix<T, Eigen::Dynamic, 1>;
15
17 {
18 public:
20
24
25 const GenericMatParam &c1() const { return c1_; }
26 const GenericMatParam &c2() const { return c2_; }
27 const GenericMatParam &c3() const { return c3_; }
28 const GenericMatParam &d1() const { return d1_; }
29
30 // energy, gradient, and hessian used in newton method
31 double compute_energy(const NonLinearAssemblerData &data) const override;
32 Eigen::VectorXd assemble_gradient(const NonLinearAssemblerData &data) const override;
33 Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override;
34
35 // sets material params
36 void add_multimaterial(const int index, const json &params, const Units &units) override;
37
38 std::string name() const override { return "MooneyRivlin3ParamSymbolic"; }
39 bool allow_inversion() const override { return false; }
40 std::map<std::string, ParamFunc> parameters() const override;
41
42 void assign_stress_tensor(const OutputData &data,
43 const int all_size,
44 const ElasticityTensorType &type,
45 Eigen::MatrixXd &all,
46 const std::function<Eigen::MatrixXd(const Eigen::MatrixXd &)> &fun) const override;
47
49 const Eigen::MatrixXd &mat,
50 Eigen::MatrixXd &stress,
51 Eigen::MatrixXd &result) const override;
52
54 Eigen::MatrixXd &stress,
55 Eigen::MatrixXd &result) const override;
56
58 const Eigen::MatrixXd &vect,
59 Eigen::MatrixXd &stress,
60 Eigen::MatrixXd &result) const override;
61
62 private:
67
68 // utility function that computes energy, the template is used for double, DScalar1, and DScalar2 in energy, gradient and hessian
69 template <typename T>
70 T compute_energy_aux(const NonLinearAssemblerData &data) const;
71 template <int n_basis, int dim>
72 void compute_energy_hessian_aux_fast(const NonLinearAssemblerData &data, Eigen::MatrixXd &H) const;
73 template <int n_basis, int dim>
74 void compute_energy_aux_gradient_fast(const NonLinearAssemblerData &data, Eigen::VectorXd &G_flattened) const;
75
76 template <typename T>
77 T elastic_energy(const RowVectorNd &p, const int el_id, const AutoDiffGradMat<T> &def_grad) const;
78
79 void get_grad_hess_symbolic(const double c1, const double c2, const double c3, const double d1, const Eigen::MatrixXd &def_grad, Eigen::MatrixXd &grad, Eigen::MatrixXd &hess) const;
80 void get_grad_hess_autodiff(const double c1, const double c2, const double c3, const double d1, const Eigen::MatrixXd &global_pts, const int el_id, const Eigen::MatrixXd &F, Eigen::MatrixXd &grad, Eigen::MatrixXd &hess) const;
81 };
82} // namespace polyfem::assembler
void compute_stress_grad_multiply_stress(const OptAssemblerData &data, Eigen::MatrixXd &stress, Eigen::MatrixXd &result) const override
T compute_energy_aux(const NonLinearAssemblerData &data) const
T elastic_energy(const RowVectorNd &p, const int el_id, const AutoDiffGradMat< T > &def_grad) const
double compute_energy(const NonLinearAssemblerData &data) const override
void get_grad_hess_symbolic(const double c1, const double c2, const double c3, const double d1, const Eigen::MatrixXd &def_grad, Eigen::MatrixXd &grad, Eigen::MatrixXd &hess) const
Eigen::VectorXd assemble_gradient(const NonLinearAssemblerData &data) const override
void compute_energy_aux_gradient_fast(const NonLinearAssemblerData &data, Eigen::VectorXd &G_flattened) const
std::map< std::string, ParamFunc > parameters() const override
void compute_stress_grad_multiply_vect(const OptAssemblerData &data, const Eigen::MatrixXd &vect, Eigen::MatrixXd &stress, Eigen::MatrixXd &result) const override
void add_multimaterial(const int index, const json &params, const Units &units) override
void get_grad_hess_autodiff(const double c1, const double c2, const double c3, const double d1, const Eigen::MatrixXd &global_pts, const int el_id, const Eigen::MatrixXd &F, Eigen::MatrixXd &grad, Eigen::MatrixXd &hess) const
void compute_energy_hessian_aux_fast(const NonLinearAssemblerData &data, Eigen::MatrixXd &H) const
void compute_stress_grad_multiply_mat(const OptAssemblerData &data, const Eigen::MatrixXd &mat, Eigen::MatrixXd &stress, Eigen::MatrixXd &result) const override
Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override
void assign_stress_tensor(const OutputData &data, const int all_size, const ElasticityTensorType &type, Eigen::MatrixXd &all, const std::function< Eigen::MatrixXd(const Eigen::MatrixXd &)> &fun) const override
double assemble_energy(const bool is_volume, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const AssemblyValsCache &cache, const double t, const double dt, const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &displacement_prev) const override
void assemble_gradient(const bool is_volume, const int n_basis, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const AssemblyValsCache &cache, const double t, const double dt, const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &displacement_prev, Eigen::MatrixXd &rhs) const override
void assemble_hessian(const bool is_volume, const int n_basis, const bool project_to_psd, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const AssemblyValsCache &cache, const double t, const double dt, const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &displacement_prev, utils::MatrixCache &mat_cache, StiffnessMatrix &grad) const override
Used for test only.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > AutoDiffGradMat
Eigen::Matrix< T, Eigen::Dynamic, 1 > AutoDiffVect
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13