PolyFEM
Loading...
Searching...
No Matches
MatParams.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
6
7namespace polyfem::assembler
8{
9 inline constexpr const char *MATERIAL_ELEMENT_INDEX = "__polyfem_material_element_index";
10
12 {
13 public:
14 GenericMatParam(const std::string &param_name);
15
16 double operator()(const RowVectorNd &p, double t, int index) const;
17 double operator()(double x, double y, double z, double t, int index) const;
18
19 void add_multimaterial(const int index, const json &params, const std::string &unit_type, const std::string &root_path);
20
21 private:
22 const std::string param_name_;
23 std::vector<utils::ExpressionValue> param_;
24
25 friend class GenericMatParams;
26 };
27
29 {
30 public:
31 GenericMatParams(const std::string &param_name);
32
33 const GenericMatParam &operator[](const size_t i) const { return params_[i]; }
34 size_t size() const { return params_.size(); }
35
36 void add_multimaterial(const int index, const json &params, const std::string &unit_type, const std::string &root_path);
37
38 private:
39 const std::string param_name_;
40 std::vector<GenericMatParam> params_;
41 };
42
44 {
45 public:
46 void resize(const int size);
47
48 double operator()(int i, int j) const;
49 double &operator()(int i, int j);
50
51 void set_from_entries(const std::vector<double> &entries, const std::string &stress_unit, const std::string &root_path);
52 void set_from_lambda_mu(const double lambda, const double mu, const std::string &stress_unit, const std::string &root_path);
53 void set_from_young_poisson(const double young, const double poisson, const std::string &stress_unit, const std::string &root_path);
54
55 void set_orthotropic(
56 double Ex, double Ey, double Ez,
57 double nuXY, double nuXZ, double nuYZ,
58 double muYZ, double muZX, double muXY, const std::string &stress_unit, const std::string &root_path);
59 void set_orthotropic(double Ex, double Ey, double nuXY, double muXY, const std::string &stress_unit, const std::string &root_path);
61 double Et, double Ea,
62 double nu_t, double nu_a,
63 double Ga, const std::string &stress_units, const std::string &root_path);
64
65 template <int DIM>
66 double compute_stress(const std::array<double, DIM> &strain, const int j) const;
67
68 void rotate_stiffness(const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6> &rotation_mtx_voigt);
69 void unrotate_stiffness();
70
71 private:
72 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6> stiffness_tensor_;
73 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6> reference_stiffness_tensor_;
74 int size_;
75 };
76
78 {
79 public:
81
82 void add_multimaterial(const int index, const json &params, const bool is_volume, const std::string &stress_unit, const std::string &root_path);
83
84 void lambda_mu(double px, double py, double pz, double x, double y, double z, double t, int el_id, double &lambda, double &mu) const;
85 void lambda_mu(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id, double &lambda, double &mu) const
86 {
87 assert(param.size() == 2 || param.size() == 3);
88 assert(param.size() == p.size());
90 param(0), param(1), param.size() == 3 ? param(2) : 0.0,
91 p(0), p(1), p.size() == 3 ? p(2) : 0.0,
92 t,
93 el_id, lambda, mu);
94 }
95
96 Eigen::MatrixXd lambda_mat_, mu_mat_;
97
98 private:
99 void set_e_nu(const int index, const json &E, const json &nu, const std::string &stress_unit, const std::string &root_path);
100
101 int size_;
102 std::vector<utils::ExpressionValue> lambda_or_E_, mu_or_nu_;
104 };
105
107 {
108 public:
109 Density();
110 virtual ~Density() = default;
111
112 virtual void add_multimaterial(const int index, const json &params, const std::string &density_unit, const std::string &root_path);
113
114 virtual double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const;
115 virtual double operator()(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id) const
116 {
117 assert(param.size() == 2 || param.size() == 3);
118 assert(param.size() == p.size());
119 return (*this)(param(0), param(1), param.size() == 3 ? param(2) : 0.0,
120 p(0), p(1), p.size() == 3 ? p(2) : 0.0,
121 t, el_id);
122 }
123
124 private:
125 void set_rho(const json &rho);
126
127 std::vector<utils::ExpressionValue> rho_;
128 };
129
130 class NoDensity : public Density
131 {
132 public:
133 using Density::operator();
134
136
137 void add_multimaterial(const int index, const json &params, const std::string &density_unit, const std::string &root_path) override
138 {
139 throw std::runtime_error("NoDensity does not support multimaterial");
140 }
141
142 double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const override
143 {
144 return 1.0;
145 }
146 };
147
149 {
150 public:
151 using Density::operator();
152
154
155 void add_multimaterial(const int index, const json &params, const std::string &density_unit, const std::string &root_path) override;
156 void add_multimaterial(const int index, const json &params, const std::string &density_unit, const std::string &heat_capacity_unit, const std::string &root_path);
157
158 double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const override;
159 double rho(const RowVectorNd &p, double t, int el_id) const;
160 double heat_capacity(const RowVectorNd &p, double t, int el_id) const;
161
162 private:
165 };
166
168 {
169 public:
171 virtual ~FiberDirection() = default;
172
173 void resize(const int size);
174
175 void add_multimaterial(const int index, const json &params, const std::string &unit, const std::string &root_path);
176
177 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3> operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const;
178
179 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3> operator()(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id) const
180 {
181 assert(param.size() == 2 || param.size() == 3);
182 assert(param.size() == p.size());
183 return (*this)(param(0), param(1), param.size() == 3 ? param(2) : 0.0,
184 p(0), p(1), p.size() == 3 ? p(2) : 0.0,
185 t, el_id);
186 }
187
188 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6> stiffness_rotation_voigt(double px, double py, double pz, double x, double y, double z, double t, int el_id) const;
189
190 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6> stiffness_rotation_voigt(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id) const
191 {
192 assert(param.size() == 2 || param.size() == 3);
193 assert(param.size() == p.size());
194 return this->stiffness_rotation_voigt(param(0), param(1), param.size() == 3 ? param(2) : 0.0,
195 p(0), p(1), p.size() == 3 ? p(2) : 0.0,
196 t, el_id);
197 }
198
199 bool has_rotation() const { return has_rotation_; }
200
201 private:
202 std::vector<Eigen::Matrix<utils::ExpressionValue, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3>> dir_;
203 int size_;
205
206 // Per-element fiber file branch: global el_id -> unit a0.
207 // Populated only when "fiber_direction" uses the per_element_file object
208 // form; operator() then short-circuits to per_el_fibers_[el_id] and dir_
209 // is left empty. See FiberDirection::add_multimaterial in MatParams.cpp.
210 std::vector<Eigen::Vector3d> per_el_fibers_;
212 };
213
214} // namespace polyfem::assembler
std::vector< Eigen::Triplet< double > > entries
int y
int z
int x
std::vector< utils::ExpressionValue > rho_
virtual double operator()(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id) const
virtual double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const
virtual ~Density()=default
void set_rho(const json &rho)
virtual void add_multimaterial(const int index, const json &params, const std::string &density_unit, const std::string &root_path)
double operator()(int i, int j) const
void set_from_young_poisson(const double young, const double poisson, const std::string &stress_unit, const std::string &root_path)
void rotate_stiffness(const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6 > &rotation_mtx_voigt)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6 > stiffness_tensor_
Definition MatParams.hpp:72
void set_transversely_isotropic(double Et, double Ea, double nu_t, double nu_a, double Ga, const std::string &stress_units, const std::string &root_path)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6 > reference_stiffness_tensor_
Definition MatParams.hpp:73
void set_orthotropic(double Ex, double Ey, double Ez, double nuXY, double nuXZ, double nuYZ, double muYZ, double muZX, double muXY, const std::string &stress_unit, const std::string &root_path)
double compute_stress(const std::array< double, DIM > &strain, const int j) const
void set_from_entries(const std::vector< double > &entries, const std::string &stress_unit, const std::string &root_path)
void set_from_lambda_mu(const double lambda, const double mu, const std::string &stress_unit, const std::string &root_path)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6 > stiffness_rotation_voigt(double px, double py, double pz, double x, double y, double z, double t, int el_id) const
std::vector< Eigen::Matrix< utils::ExpressionValue, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3 > > dir_
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3 > operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const
void add_multimaterial(const int index, const json &params, const std::string &unit, const std::string &root_path)
std::vector< Eigen::Vector3d > per_el_fibers_
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 1, 3, 3 > operator()(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id) const
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 1, 6, 6 > stiffness_rotation_voigt(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id) const
double operator()(const RowVectorNd &p, double t, int index) const
Definition MatParams.cpp:97
void add_multimaterial(const int index, const json &params, const std::string &unit_type, const std::string &root_path)
Definition MatParams.cpp:81
std::vector< utils::ExpressionValue > param_
Definition MatParams.hpp:23
const GenericMatParam & operator[](const size_t i) const
Definition MatParams.hpp:33
std::vector< GenericMatParam > params_
Definition MatParams.hpp:40
void add_multimaterial(const int index, const json &params, const std::string &unit_type, const std::string &root_path)
std::vector< utils::ExpressionValue > mu_or_nu_
void lambda_mu(double px, double py, double pz, double x, double y, double z, double t, int el_id, double &lambda, double &mu) const
std::vector< utils::ExpressionValue > lambda_or_E_
void set_e_nu(const int index, const json &E, const json &nu, const std::string &stress_unit, const std::string &root_path)
void lambda_mu(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id, double &lambda, double &mu) const
Definition MatParams.hpp:85
void add_multimaterial(const int index, const json &params, const bool is_volume, const std::string &stress_unit, const std::string &root_path)
void add_multimaterial(const int index, const json &params, const std::string &density_unit, const std::string &root_path) override
double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const override
double rho(const RowVectorNd &p, double t, int el_id) const
double heat_capacity(const RowVectorNd &p, double t, int el_id) const
double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const override
void add_multimaterial(const int index, const json &params, const std::string &density_unit, const std::string &root_path) override
Used for test only.
constexpr const char * MATERIAL_ELEMENT_INDEX
Definition MatParams.hpp:9
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13