PolyFEM
Loading...
Searching...
No Matches
IncompressibleLinElast.cpp
Go to the documentation of this file.
2
3namespace polyfem::assembler
4{
5 using namespace basis;
6
7 void IncompressibleLinearElasticityDispacement::add_multimaterial(const int index, const json &params, const Units &units, const io::ResourceIO &resources)
8 {
9 assert(size() == 2 || size() == 3);
10
11 params_.add_multimaterial(index, params, size() == 3, units.stress(), resources);
12 }
13
14 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1>
16 {
17 // 2mu (epsi : epsj)
18 assert(size() == 2 || size() == 3);
19
20 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1> res(size() * size());
21 res.setZero();
22
23 const Eigen::MatrixXd &gradi = data.vals.basis_values[data.i].grad_t_m;
24 const Eigen::MatrixXd &gradj = data.vals.basis_values[data.j].grad_t_m;
25
26 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> epsi(size(), size());
27 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> epsj(size(), size());
28
29 for (long p = 0; p < gradi.rows(); ++p)
30 {
31
32 double lambda, mu;
33 params_.lambda_mu(data.vals.quadrature.points.row(p), data.vals.val.row(p), data.t, data.vals.element_id, lambda, mu);
34
35 for (int di = 0; di < size(); ++di)
36 {
37 epsi.setZero();
38 epsi.row(di) = gradi.row(p);
39 epsi = ((epsi + epsi.transpose()) / 2).eval();
40 for (int dj = 0; dj < size(); ++dj)
41 {
42 epsj.setZero();
43 epsj.row(dj) = gradj.row(p);
44 epsj = ((epsj + epsj.transpose()) / 2.0).eval();
45
46 res(dj * size() + di) += 2 * mu * (epsi.array() * epsj.array()).sum() * data.da(p);
47 }
48 }
49 }
50
51 return res;
52 }
53
55 const Eigen::Index p, const MatrixNd &displacement_grad, OutputStress &output) const
56 {
57 const auto &local_pts = data.local_pts;
58 const auto t = data.t;
59 output.energy = 0;
60 if (!output.needs_stress)
61 return true;
62 double lambda, mu;
63 params_.lambda_mu(local_pts.row(p), vals.val.row(p), t, vals.element_id, lambda, mu);
64 const MatrixNd strain = (displacement_grad + displacement_grad.transpose()) / 2;
65 output.native = 2 * mu * strain + lambda * strain.trace() * MatrixNd::Identity(size(), size());
66 return true;
67 }
68
69 std::map<std::string, Assembler::ParamFunc> IncompressibleLinearElasticityDispacement::parameters() const
70 {
71 std::map<std::string, ParamFunc> res;
72 const auto &params = params_;
73 const int size = this->size();
74
75 res["lambda"] = [&params](const RowVectorNd &uv, const RowVectorNd &p, double t, int e) {
76 double lambda, mu;
77
78 params.lambda_mu(uv, p, t, e, lambda, mu);
79 return lambda;
80 };
81
82 res["mu"] = [&params](const RowVectorNd &uv, const RowVectorNd &p, double t, int e) {
83 double lambda, mu;
84
85 params.lambda_mu(uv, p, t, e, lambda, mu);
86 return mu;
87 };
88
89 res["E"] = [&params, size](const RowVectorNd &uv, const RowVectorNd &p, double t, int e) {
90 double lambda, mu;
91 params.lambda_mu(uv, p, t, e, lambda, mu);
92
93 if (size == 3)
94 return mu * (3.0 * lambda + 2.0 * mu) / (lambda + mu);
95 else
96 return 2 * mu * (2.0 * lambda + 2.0 * mu) / (lambda + 2.0 * mu);
97 };
98
99 res["nu"] = [&params, size](const RowVectorNd &uv, const RowVectorNd &p, double t, int e) {
100 double lambda, mu;
101
102 params.lambda_mu(uv, p, t, e, lambda, mu);
103
104 if (size == 3)
105 return lambda / (2.0 * (lambda + mu));
106 else
107 return lambda / (lambda + 2.0 * mu);
108 };
109
110 return res;
111 }
112
113 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1>
115 {
116 // (psii : div phij) = -psii * gradphij
117 assert(size() == 2 || size() == 3);
118 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> res(rows() * cols());
119 res.setZero();
120
121 const Eigen::MatrixXd &psii = data.psi_vals.basis_values[data.i].val;
122 const Eigen::MatrixXd &gradphij = data.phi_vals.basis_values[data.j].grad_t_m;
123 assert(psii.size() == gradphij.rows());
124 assert(gradphij.cols() == rows());
125
126 for (int k = 0; k < gradphij.rows(); ++k)
127 {
128 res -= psii(k) * gradphij.row(k) * data.da(k);
129 }
130
131 return res;
132 }
133
134 void IncompressibleLinearElasticityPressure::add_multimaterial(const int index, const json &params, const Units &units, const io::ResourceIO &resources)
135 {
136 assert(disp_size_ == 2 || disp_size_ == 3);
137
138 params_.add_multimaterial(index, params, disp_size_ == 3, units.stress(), resources);
139 }
140
141 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1>
143 {
144 // -1/lambda phi_ * phi_j
145
146 const Eigen::MatrixXd &phii = data.vals.basis_values[data.i].val;
147 const Eigen::MatrixXd &phij = data.vals.basis_values[data.j].val;
148
149 double res = 0;
150
151 for (long p = 0; p < data.da.size(); ++p)
152 {
153 double lambda, mu;
154 params_.lambda_mu(data.vals.quadrature.points.row(p), data.vals.val.row(p), data.t, data.vals.element_id, lambda, mu);
155
156 res += -phii(p) * phij(p) * data.da(p) / lambda;
157 }
158
159 // double res = (phii.array() * phij.array() * da.array()).sum();
160 // res *= -1. / lambda;
161
162 return Eigen::Matrix<double, 1, 1>::Constant(res);
163 }
164} // namespace polyfem::assembler
ElementAssemblyValues vals
std::string stress() const
Definition Units.hpp:27
Scratch for one output point. All tensor storage has a fixed 3x3 capacity.
stores per element basis values at given quadrature points and geometric mapping
void add_multimaterial(const int index, const json &params, const Units &units, const io::ResourceIO &resources) override
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 9, 1 > assemble(const LinearAssemblerData &data) const override
local assembly function that defines the bilinear form (LHS) computes and returns a single local stif...
std::map< std::string, ParamFunc > parameters() const override
bool compute_output_stress(const OutputData &data, const ElementAssemblyValues &vals, Eigen::Index point, const MatrixNd &displacement_gradient, OutputStress &stress) const override
Return false to use a material's legacy assign_stress_tensor implementation.
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 3, 1 > assemble(const MixedAssemblerData &data) const override
void add_multimaterial(const int index, const json &params, const Units &units, const io::ResourceIO &resources) override
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 9, 1 > assemble(const LinearAssemblerData &data) const override
local assembly function that defines the bilinear form (LHS) computes and returns a single local stif...
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 add_multimaterial(const int index, const json &params, const bool is_volume, const std::string &stress_unit, const io::ResourceIO &resources)
const ElementAssemblyValues & vals
stores the evaluation for that element
const QuadratureVector & da
contains both the quadrature weight and the change of metric in the integral
const QuadratureVector & da
contains both the quadrature weight and the change of metric in the integral
const ElementAssemblyValues & phi_vals
stores the evaluation for that element
const ElementAssemblyValues & psi_vals
stores the evaluation for that element
const Eigen::MatrixXd & local_pts
Read-only interface to a hierarchical collection of simulation resources.
Used for test only.
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, 3, 3 > MatrixNd
Definition Types.hpp:14
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13