PolyFEM
Loading...
Searching...
No Matches
AMIPSEnergy.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <polyfem/Common.hpp>
9
10#include <Eigen/Dense>
11
12#include <functional>
13#include <iostream>
14#include <vector>
15
16namespace polyfem::assembler
17{
18 class AMIPSEnergy : public GenericElastic<AMIPSEnergy>
19 {
20 public:
25
26 // sets material params
27 void add_multimaterial(const int index, const json &params, const Units &units) override;
28
29 std::string name() const override { return "AMIPS"; }
30 std::map<std::string, ParamFunc> parameters() const override { return std::map<std::string, ParamFunc>(); }
31
32 bool allow_inversion() const override { return false; }
33
34 bool real_def_grad() const override { return use_rest_pose_; }
35
36 template <typename T>
38 const RowVectorNd &p,
39 const double t,
40 const int el_id,
41 DefGradMatrix<T> &def_grad) const
42 {
43 typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> AutoDiffGradMat;
44
45 double power = -1;
47 power = size() == 2 ? 1. : (2. / 3.);
48 else
49 power = size() == 2 ? 2. : 5. / 3.;
50
51 AutoDiffGradMat standard;
52
53 if (size() == 2)
54 standard = get_standard<2, T>(size(), use_rest_pose_);
55 else
56 standard = get_standard<3, T>(size(), use_rest_pose_);
57
58 if (!use_rest_pose_)
59 def_grad = def_grad * standard;
60
61 const T det = polyfem::utils::determinant(def_grad);
62 if (det <= 0)
63 {
64 return T(std::nan(""));
65 }
66
67 const T powJ = pow(det, power);
68 return (def_grad.transpose() * def_grad).trace() / powJ; //+ barrier<T>::value(det);
69 }
70
71 private:
72 bool use_rest_pose_ = false;
73
74 template <int dimt, class T>
75 static Eigen::Matrix<T, dimt, dimt> get_standard(const int dim, const bool use_rest_pose)
76 {
77 Eigen::Matrix<double, dimt, dimt> standard(dim, dim);
78 if (use_rest_pose)
79 {
80 standard.setIdentity();
81 }
82 else
83 {
84 if (dim == 2)
85 standard << 1, 0,
86 0.5, std::sqrt(3) / 2;
87 else
88 standard << 1, 0, 0,
89 0.5, std::sqrt(3) / 2., 0,
90 0.5, 0.5 / std::sqrt(3), std::sqrt(3) / 2.;
91 standard = standard.inverse().transpose().eval();
92 }
93
94 Eigen::Matrix<T, dimt, dimt> res(dim, dim);
95 for (int i = 0; i < dim; ++i)
96 {
97 for (int j = 0; j < dim; ++j)
98 {
99 res(i, j) = T(standard(i, j));
100 }
101 }
102
103 return res;
104 }
105
106 public:
107 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> gradient(
108 const RowVectorNd &p,
109 const double t,
110 const int el_id,
111 const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> &F) const override;
112
113 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 9, 9> hessian(
114 const RowVectorNd &p,
115 const double t,
116 const int el_id,
117 const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> &F) const override;
118 };
119
120} // namespace polyfem::assembler
static Eigen::Matrix< T, dimt, dimt > get_standard(const int dim, const bool use_rest_pose)
std::string name() const override
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > gradient(const RowVectorNd &p, const double t, const int el_id, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > &F) const override
void add_multimaterial(const int index, const json &params, const Units &units) override
bool allow_inversion() const override
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 9, 9 > hessian(const RowVectorNd &p, const double t, const int el_id, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > &F) const override
std::map< std::string, ParamFunc > parameters() const override
T elastic_energy(const RowVectorNd &p, const double t, const int el_id, DefGradMatrix< T > &def_grad) const
bool real_def_grad() const override
Used for test only.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > DefGradMatrix
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > AutoDiffGradMat
T determinant(const Eigen::Matrix< T, rows, cols, option, maxRow, maxCol > &mat)
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13