PolyFEM
Loading...
Searching...
No Matches
MultiModel.cpp
Go to the documentation of this file.
1#include "MultiModel.hpp"
2
3// #include <polyfem/basis/Basis.hpp>
4// #include <polyfem/autogen/auto_elasticity_rhs.hpp>
5
6// #include <igl/Timer.h>
7
8namespace polyfem::assembler
9{
24
25 void MultiModel::add_multimaterial(const int index, const json &params, const Units &units)
26 {
27 assert(size() == 2 || size() == 3);
28
29 saint_venant_.add_multimaterial(index, params, units);
30 neo_hookean_.add_multimaterial(index, params, units);
31 linear_elasticity_.add_multimaterial(index, params, units);
32
33 hooke_.add_multimaterial(index, params, units);
34 mooney_rivlin_elasticity_.add_multimaterial(index, params, units);
37 fixed_corotational_.add_multimaterial(index, params, units);
38 }
39
40 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1>
42 {
43 assert(pt.size() == size());
44 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> res;
45 assert(false);
46
47 return res;
48 }
49
50 Eigen::VectorXd
52 {
53 const int el_id = data.vals.element_id;
54 const std::string model = multi_material_models_[el_id];
55
56 if (model == "SaintVenant")
58 else if (model == "NeoHookean")
60 else if (model == "LinearElasticity")
62 else if (model == "HookeLinearElasticity")
63 return hooke_.assemble_gradient(data);
64 else if (model == "MooneyRivlin")
66 else if (model == "MooneyRivlin3Param")
68 else if (model == "UnconstrainedOgden")
70 else if (model == "IncompressibleOgden")
72 else if (model == "FixedCorotational")
74 else
75 {
76 assert(false);
77 return Eigen::VectorXd(0, 0);
78 }
79 }
80
81 Eigen::MatrixXd
83 {
84 const int el_id = data.vals.element_id;
85 const std::string model = multi_material_models_[el_id];
86
87 if (model == "SaintVenant")
89 else if (model == "NeoHookean")
90 return neo_hookean_.assemble_hessian(data);
91 else if (model == "LinearElasticity")
93 else if (model == "HookeLinearElasticity")
94 return hooke_.assemble_hessian(data);
95 else if (model == "MooneyRivlin")
97 else if (model == "MooneyRivlin3Param")
99 else if (model == "UnconstrainedOgden")
101 else if (model == "IncompressibleOgden")
103 else if (model == "FixedCorotational")
105 else
106 {
107 assert(false);
108 return Eigen::MatrixXd(0, 0);
109 }
110 }
111
113 {
114 const int el_id = data.vals.element_id;
115 const std::string model = multi_material_models_[el_id];
116
117 if (model == "SaintVenant")
118 return saint_venant_.compute_energy(data);
119 else if (model == "NeoHookean")
120 return neo_hookean_.compute_energy(data);
121 else if (model == "LinearElasticity")
123 else if (model == "HookeLinearElasticity")
124 return hooke_.compute_energy(data);
125 else if (model == "MooneyRivlin")
127 else if (model == "MooneyRivlin3Param")
129 else if (model == "UnconstrainedOgden")
131 else if (model == "IncompressibleOgden")
133 else if (model == "FixedCorotational")
135 else
136 {
137 assert(false);
138 return 0;
139 }
140 }
141
143 const OutputData &data,
144 const int all_size,
145 const ElasticityTensorType &type,
146 Eigen::MatrixXd &all,
147 const std::function<Eigen::MatrixXd(const Eigen::MatrixXd &)> &fun) const
148 {
149 const std::string model = multi_material_models_[data.el_id];
150
151 if (model == "SaintVenant")
152 saint_venant_.assign_stress_tensor(data, all_size, type, all, fun);
153 else if (model == "NeoHookean")
154 neo_hookean_.assign_stress_tensor(data, all_size, type, all, fun);
155 else if (model == "LinearElasticity")
156 linear_elasticity_.assign_stress_tensor(data, all_size, type, all, fun);
157 else if (model == "HookeLinearElasticity")
158 return hooke_.assign_stress_tensor(data, all_size, type, all, fun);
159 else if (model == "MooneyRivlin")
160 return mooney_rivlin_elasticity_.assign_stress_tensor(data, all_size, type, all, fun);
161 else if (model == "MooneyRivlin3Param")
162 return mooney_rivlin_3_param_elasticity_.assign_stress_tensor(data, all_size, type, all, fun);
163 else if (model == "UnconstrainedOgden")
164 return unconstrained_ogden_elasticity_.assign_stress_tensor(data, all_size, type, all, fun);
165 else if (model == "IncompressibleOgden")
166 return incompressible_ogden_elasticity_.assign_stress_tensor(data, all_size, type, all, fun);
167 else if (model == "FixedCorotational")
168 return fixed_corotational_.assign_stress_tensor(data, all_size, type, all, fun);
169 else
170 {
171 assert(false);
172 }
173 }
174
175 std::map<std::string, Assembler::ParamFunc> MultiModel::parameters() const
176 {
177 std::map<std::string, ParamFunc> res;
178 // TODO
179
180 return res;
181 }
182} // namespace polyfem::assembler
virtual void set_size(const int size)
Definition Assembler.hpp:64
Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override
void add_multimaterial(const int index, const json &params, const Units &units) override
double compute_energy(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
Eigen::VectorXd assemble_gradient(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
Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override
Eigen::VectorXd assemble_gradient(const NonLinearAssemblerData &data) const override
double compute_energy(const NonLinearAssemblerData &data) const override
double compute_energy(const NonLinearAssemblerData &data) const override
void add_multimaterial(const int index, const json &params, const Units &units) override
Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override
Eigen::VectorXd assemble_gradient(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
void add_multimaterial(const int index, const json &params, const Units &units) override
void add_multimaterial(const int index, const json &params, const Units &units) override
Eigen::VectorXd assemble_gradient(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
Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override
double compute_energy(const NonLinearAssemblerData &data) const override
void add_multimaterial(const int index, const json &params, const Units &units) override
VectorNd compute_rhs(const AutodiffHessianPt &pt) const override
std::vector< std::string > multi_material_models_
UnconstrainedOgdenElasticity unconstrained_ogden_elasticity_
LinearElasticity linear_elasticity_
FixedCorotational fixed_corotational_
MooneyRivlinElasticity mooney_rivlin_elasticity_
void set_size(const int size) override
void add_multimaterial(const int index, const json &params, const Units &units) override
SaintVenantElasticity saint_venant_
Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override
Eigen::VectorXd assemble_gradient(const NonLinearAssemblerData &data) const override
double compute_energy(const NonLinearAssemblerData &data) const override
MooneyRivlin3ParamElasticity mooney_rivlin_3_param_elasticity_
std::map< std::string, ParamFunc > parameters() const override
IncompressibleOgdenElasticity incompressible_ogden_elasticity_
HookeLinearElasticity hooke_
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
NeoHookeanElasticity neo_hookean_
double compute_energy(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
void add_multimaterial(const int index, const json &params, const Units &units) override
Eigen::MatrixXd assemble_hessian(const NonLinearAssemblerData &data) const override
Eigen::VectorXd assemble_gradient(const NonLinearAssemblerData &data) const override
void add_multimaterial(const int index, const json &params, const Units &units) override
double compute_energy(const NonLinearAssemblerData &data) 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
Eigen::VectorXd assemble_gradient(const NonLinearAssemblerData &data) const override
void add_multimaterial(const int index, const json &params, const Units &units) override
Used for test only.
Eigen::Matrix< AutodiffScalarHessian, Eigen::Dynamic, 1, 0, 3, 1 > AutodiffHessianPt
nlohmann::json json
Definition Common.hpp:9