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{
10 {
11 public:
12 GenericMatParam(const std::string &param_name);
13
14 double operator()(const RowVectorNd &p, double t, int index) const;
15 double operator()(double x, double y, double z, double t, int index) const;
16
17 void add_multimaterial(const int index, const json &params, const std::string &unit_type);
18
19 private:
20 const std::string param_name_;
21 std::vector<utils::ExpressionValue> param_;
22
23 friend class GenericMatParams;
24 };
25
27 {
28 public:
29 GenericMatParams(const std::string &param_name);
30
31 const GenericMatParam &operator[](const size_t i) const { return params_[i]; }
32 size_t size() const { return params_.size(); }
33
34 void add_multimaterial(const int index, const json &params, const std::string &unit_type);
35
36 private:
37 const std::string param_name_;
38 std::vector<GenericMatParam> params_;
39 };
40
42 {
43 public:
44 void resize(const int size);
45
46 double operator()(int i, int j) const;
47 double &operator()(int i, int j);
48
49 void set_from_entries(const std::vector<double> &entries, const std::string &stress_unit);
50 void set_from_lambda_mu(const double lambda, const double mu, const std::string &stress_unit);
51 void set_from_young_poisson(const double young, const double poisson, const std::string &stress_unit);
52
53 void set_orthotropic(
54 double Ex, double Ey, double Ez,
55 double nuXY, double nuXZ, double nuYZ,
56 double muYZ, double muZX, double muXY, const std::string &stress_unit);
57 void set_orthotropic(double Ex, double Ey, double nuXY, double muXY, const std::string &stress_unit);
58
59 template <int DIM>
60 double compute_stress(const std::array<double, DIM> &strain, const int j) const;
61
62 private:
63 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6> stifness_tensor_;
64 int size_;
65 };
66
68 {
69 public:
71
72 void add_multimaterial(const int index, const json &params, const bool is_volume, const std::string &stress_unit);
73
74 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;
75 void lambda_mu(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id, double &lambda, double &mu) const
76 {
77 assert(param.size() == 2 || param.size() == 3);
78 assert(param.size() == p.size());
80 param(0), param(1), param.size() == 3 ? param(2) : 0.0,
81 p(0), p(1), p.size() == 3 ? p(2) : 0.0,
82 t,
83 el_id, lambda, mu);
84 }
85
86 Eigen::MatrixXd lambda_mat_, mu_mat_;
87
88 private:
89 void set_e_nu(const int index, const json &E, const json &nu, const std::string &stress_unit);
90
91 int size_;
92 std::vector<utils::ExpressionValue> lambda_or_E_, mu_or_nu_;
94 };
95
96 class Density
97 {
98 public:
99 Density();
100 virtual ~Density() = default;
101
102 virtual void add_multimaterial(const int index, const json &params, const std::string &density_unit);
103
104 virtual double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const;
105 double operator()(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id) const
106 {
107 assert(param.size() == 2 || param.size() == 3);
108 assert(param.size() == p.size());
109 return (*this)(param(0), param(1), param.size() == 3 ? param(2) : 0.0,
110 p(0), p(1), p.size() == 3 ? p(2) : 0.0,
111 t, el_id);
112 }
113
114 private:
115 void set_rho(const json &rho);
116
117 std::vector<utils::ExpressionValue> rho_;
118 };
119
120 class NoDensity : public Density
121 {
122 public:
124
125 void add_multimaterial(const int index, const json &params, const std::string &density_unit) override
126 {
127 throw std::runtime_error("NoDensity does not support multimaterial");
128 }
129
130 double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const override
131 {
132 return 1.0;
133 }
134 };
135} // namespace polyfem::assembler
std::vector< Eigen::Triplet< double > > entries
int y
int z
int x
std::vector< utils::ExpressionValue > rho_
virtual void add_multimaterial(const int index, const json &params, const std::string &density_unit)
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)
double operator()(int i, int j) const
void set_from_entries(const std::vector< double > &entries, const std::string &stress_unit)
void set_from_young_poisson(const double young, const double poisson, const std::string &stress_unit)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 6, 6 > stifness_tensor_
Definition MatParams.hpp:63
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)
double compute_stress(const std::array< double, DIM > &strain, const int j) const
void set_from_lambda_mu(const double lambda, const double mu, const std::string &stress_unit)
void add_multimaterial(const int index, const json &params, const std::string &unit_type)
Definition MatParams.cpp:28
double operator()(const RowVectorNd &p, double t, int index) const
Definition MatParams.cpp:42
std::vector< utils::ExpressionValue > param_
Definition MatParams.hpp:21
const GenericMatParam & operator[](const size_t i) const
Definition MatParams.hpp:31
void add_multimaterial(const int index, const json &params, const std::string &unit_type)
Definition MatParams.cpp:65
std::vector< GenericMatParam > params_
Definition MatParams.hpp:38
std::vector< utils::ExpressionValue > mu_or_nu_
Definition MatParams.hpp:92
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
void set_e_nu(const int index, const json &E, const json &nu, const std::string &stress_unit)
std::vector< utils::ExpressionValue > lambda_or_E_
Definition MatParams.hpp:92
void add_multimaterial(const int index, const json &params, const bool is_volume, const std::string &stress_unit)
void lambda_mu(const Eigen::MatrixXd &param, const Eigen::MatrixXd &p, double t, int el_id, double &lambda, double &mu) const
Definition MatParams.hpp:75
void add_multimaterial(const int index, const json &params, const std::string &density_unit) override
double operator()(double px, double py, double pz, double x, double y, double z, double t, int el_id) const override
Used for test only.
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13