13 template <
typename Derived>
18 template <
typename Derived>
24 const std::function<Eigen::MatrixXd(
const Eigen::MatrixXd &)> &fun)
const
26 Eigen::MatrixXd deformation_grad(size(), size());
27 Eigen::MatrixXd stress_tensor(size(), size());
31 const auto &displacement = data.
fun;
33 const auto &bs = data.
bs;
34 const auto &gbs = data.
gbs;
35 const auto el_id = data.
el_id;
37 assert(displacement.cols() == 1);
39 all.resize(local_pts.rows(), all_size);
42 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> def_grad(size(), size());
45 vals.
compute(el_id, size() == 3, local_pts, bs, gbs);
47 for (
long p = 0; p < local_pts.rows(); ++p)
52 for (
int d = 0; d < size(); ++d)
53 deformation_grad(d, d) += 1;
57 all.row(p) = fun(deformation_grad);
61 for (
int d1 = 0; d1 < size(); ++d1)
63 for (
int d2 = 0; d2 < size(); ++d2)
64 def_grad(d1, d2) =
Diff(d1 * size() + d2, deformation_grad(d1, d2));
67 const auto val = derived().elastic_energy(local_pts.row(p), data.
t,
vals.
element_id, def_grad);
69 for (
int d1 = 0; d1 < size(); ++d1)
71 for (
int d2 = 0; d2 < size(); ++d2)
72 stress_tensor(d1, d2) =
val.getGradient()(d1 * size() + d2);
75 stress_tensor = 1.0 / deformation_grad.determinant() * stress_tensor * deformation_grad.transpose();
82 all.row(p) = fun(stress_tensor);
86 template <
typename Derived>
89 return compute_energy_aux<double>(data);
92 template <
typename Derived>
97 size(), n_bases, data,
98 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 6, 1>>>(data); },
99 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 8, 1>>>(data); },
100 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 12, 1>>>(data); },
101 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 18, 1>>>(data); },
102 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 24, 1>>>(data); },
103 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 30, 1>>>(data); },
104 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 60, 1>>>(data); },
105 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, 81, 1>>>(data); },
106 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, Eigen::Dynamic, 1, 0, SMALL_N, 1>>>(data); },
107 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::Matrix<double, Eigen::Dynamic, 1, 0, BIG_N, 1>>>(data); },
108 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar1<double, Eigen::VectorXd>>(data); });
111 template <
typename Derived>
116 size(), n_bases, data,
117 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 6, 1>, Eigen::Matrix<double, 6, 6>>>(data); },
118 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 8, 1>, Eigen::Matrix<double, 8, 8>>>(data); },
119 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 12, 1>, Eigen::Matrix<double, 12, 12>>>(data); },
120 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 18, 1>, Eigen::Matrix<double, 18, 18>>>(data); },
121 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 24, 1>, Eigen::Matrix<double, 24, 24>>>(data); },
122 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 30, 1>, Eigen::Matrix<double, 30, 30>>>(data); },
123 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 60, 1>, Eigen::Matrix<double, 60, 60>>>(data); },
124 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, 81, 1>, Eigen::Matrix<double, 81, 81>>>(data); },
125 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::Matrix<double, Eigen::Dynamic, 1, 0, SMALL_N, 1>, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, SMALL_N, SMALL_N>>>(data); },
126 [&](
const NonLinearAssemblerData &data) {
return compute_energy_aux<DScalar2<double, Eigen::VectorXd, Eigen::MatrixXd>>(data); });
129 template <
typename Derived>
132 const Eigen::MatrixXd &mat,
133 Eigen::MatrixXd &stress,
134 Eigen::MatrixXd &result)
const
136 typedef DScalar2<double, Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1>, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 9, 9>>
Diff;
138 const double t = data.
t;
139 const int el_id = data.
el_id;
140 const Eigen::MatrixXd &local_pts = data.
local_pts;
141 const Eigen::MatrixXd &global_pts = data.
global_pts;
142 const Eigen::MatrixXd &grad_u_i = data.
grad_u_i;
145 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> def_grad(size(), size());
147 Eigen::MatrixXd
F = grad_u_i;
148 for (
int d = 0; d < size(); ++d)
151 assert(local_pts.rows() == 1);
152 for (
int i = 0; i < size(); ++i)
153 for (
int j = 0; j < size(); ++j)
154 def_grad(i, j) =
Diff(i + j * size(),
F(i, j));
156 auto energy = derived().elastic_energy(global_pts, t, el_id, def_grad);
159 Eigen::MatrixXd grad = energy.getGradient().reshaped(size(), size());
161 Eigen::MatrixXd hess = energy.getHessian();
166 result = (hess * mat.reshaped(size() * size(), 1)).reshaped(size(), size());
169 template <
typename Derived>
172 Eigen::MatrixXd &stress,
173 Eigen::MatrixXd &result)
const
175 typedef DScalar2<double, Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1>, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 9, 9>>
Diff;
177 const double t = data.
t;
178 const int el_id = data.
el_id;
179 const Eigen::MatrixXd &local_pts = data.
local_pts;
180 const Eigen::MatrixXd &global_pts = data.
global_pts;
181 const Eigen::MatrixXd &grad_u_i = data.
grad_u_i;
184 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> def_grad(size(), size());
186 Eigen::MatrixXd
F = grad_u_i;
187 for (
int d = 0; d < size(); ++d)
190 assert(local_pts.rows() == 1);
191 for (
int i = 0; i < size(); ++i)
192 for (
int j = 0; j < size(); ++j)
193 def_grad(i, j) =
Diff(i + j * size(),
F(i, j));
195 auto energy = derived().elastic_energy(global_pts, t, el_id, def_grad);
198 Eigen::MatrixXd grad = energy.getGradient().reshaped(size(), size());
200 Eigen::MatrixXd hess = energy.getHessian();
205 result = (hess * stress.reshaped(size() * size(), 1)).reshaped(size(), size());
208 template <
typename Derived>
211 const Eigen::MatrixXd &vect,
212 Eigen::MatrixXd &stress,
213 Eigen::MatrixXd &result)
const
215 typedef DScalar2<double, Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1>, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 9, 9>>
Diff;
217 const double t = data.
t;
218 const int el_id = data.
el_id;
219 const Eigen::MatrixXd &local_pts = data.
local_pts;
220 const Eigen::MatrixXd &global_pts = data.
global_pts;
221 const Eigen::MatrixXd &grad_u_i = data.
grad_u_i;
224 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> def_grad(size(), size());
226 Eigen::MatrixXd
F = grad_u_i;
227 for (
int d = 0; d < size(); ++d)
230 assert(local_pts.rows() == 1);
231 for (
int i = 0; i < size(); ++i)
232 for (
int j = 0; j < size(); ++j)
233 def_grad(i, j) =
Diff(i + j * size(),
F(i, j));
235 auto energy = derived().elastic_energy(global_pts, t, el_id, def_grad);
238 Eigen::MatrixXd grad = energy.getGradient().reshaped(size(), size());
240 Eigen::MatrixXd hess = energy.getHessian();
244 result.resize(hess.rows(), vect.size());
245 for (
int i = 0; i < hess.rows(); ++i)
246 if (vect.rows() == 1)
248 result.row(i) = vect * hess.row(i).reshaped(size(), size());
251 result.row(i) = hess.row(i).reshaped(size(), size()) * vect;
ElementAssemblyValues vals
stores per element basis values at given quadrature points and geometric mapping
std::vector< AssemblyValues > basis_values
void compute(const int el_index, const bool is_volume, const Eigen::MatrixXd &pts, const basis::ElementBases &basis, const basis::ElementBases &gbasis)
computes the per element values at the local (ref el) points (pts) sets basis_values,...
void compute_stress_grad_multiply_stress(const OptAssemblerData &data, Eigen::MatrixXd &stress, Eigen::MatrixXd &result) 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
void compute_stress_grad_multiply_vect(const OptAssemblerData &data, const Eigen::MatrixXd &vect, Eigen::MatrixXd &stress, Eigen::MatrixXd &result) const override
Eigen::VectorXd assemble_gradient(const NonLinearAssemblerData &data) const override
double compute_energy(const NonLinearAssemblerData &data) const override
void compute_stress_grad_multiply_mat(const OptAssemblerData &data, const Eigen::MatrixXd &mat, Eigen::MatrixXd &stress, Eigen::MatrixXd &result) const override
const ElementAssemblyValues & vals
const Eigen::MatrixXd & local_pts
const Eigen::MatrixXd & global_pts
const Eigen::MatrixXd & grad_u_i
const basis::ElementBases & bs
const Eigen::MatrixXd & fun
const Eigen::MatrixXd & local_pts
const basis::ElementBases & gbs
DScalar1< double, Eigen::Matrix< double, Eigen::Dynamic, 1 > > Diff
Eigen::MatrixXd pk2_from_cauchy(const Eigen::MatrixXd &stress, const Eigen::MatrixXd &F)
Eigen::MatrixXd hessian_from_energy(const int size, const int n_bases, const assembler::NonLinearAssemblerData &data, const std::function< DScalar2< double, Eigen::Matrix< double, 6, 1 >, Eigen::Matrix< double, 6, 6 > >(const assembler::NonLinearAssemblerData &)> &fun6, const std::function< DScalar2< double, Eigen::Matrix< double, 8, 1 >, Eigen::Matrix< double, 8, 8 > >(const assembler::NonLinearAssemblerData &)> &fun8, const std::function< DScalar2< double, Eigen::Matrix< double, 12, 1 >, Eigen::Matrix< double, 12, 12 > >(const assembler::NonLinearAssemblerData &)> &fun12, const std::function< DScalar2< double, Eigen::Matrix< double, 18, 1 >, Eigen::Matrix< double, 18, 18 > >(const assembler::NonLinearAssemblerData &)> &fun18, const std::function< DScalar2< double, Eigen::Matrix< double, 24, 1 >, Eigen::Matrix< double, 24, 24 > >(const assembler::NonLinearAssemblerData &)> &fun24, const std::function< DScalar2< double, Eigen::Matrix< double, 30, 1 >, Eigen::Matrix< double, 30, 30 > >(const assembler::NonLinearAssemblerData &)> &fun30, const std::function< DScalar2< double, Eigen::Matrix< double, 60, 1 >, Eigen::Matrix< double, 60, 60 > >(const assembler::NonLinearAssemblerData &)> &fun60, const std::function< DScalar2< double, Eigen::Matrix< double, 81, 1 >, Eigen::Matrix< double, 81, 81 > >(const assembler::NonLinearAssemblerData &)> &fun81, const std::function< DScalar2< double, Eigen::Matrix< double, Eigen::Dynamic, 1, 0, SMALL_N, 1 >, Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, SMALL_N, SMALL_N > >(const assembler::NonLinearAssemblerData &)> &funN, const std::function< DScalar2< double, Eigen::VectorXd, Eigen::MatrixXd >(const assembler::NonLinearAssemblerData &)> &funn)
void compute_diplacement_grad(const int size, const ElementAssemblyValues &vals, const Eigen::MatrixXd &local_pts, const int p, const Eigen::MatrixXd &displacement, Eigen::MatrixXd &displacement_grad)
Eigen::MatrixXd pk1_from_cauchy(const Eigen::MatrixXd &stress, const Eigen::MatrixXd &F)
Eigen::VectorXd gradient_from_energy(const int size, const int n_bases, const assembler::NonLinearAssemblerData &data, const std::function< DScalar1< double, Eigen::Matrix< double, 6, 1 > >(const assembler::NonLinearAssemblerData &)> &fun6, const std::function< DScalar1< double, Eigen::Matrix< double, 8, 1 > >(const assembler::NonLinearAssemblerData &)> &fun8, const std::function< DScalar1< double, Eigen::Matrix< double, 12, 1 > >(const assembler::NonLinearAssemblerData &)> &fun12, const std::function< DScalar1< double, Eigen::Matrix< double, 18, 1 > >(const assembler::NonLinearAssemblerData &)> &fun18, const std::function< DScalar1< double, Eigen::Matrix< double, 24, 1 > >(const assembler::NonLinearAssemblerData &)> &fun24, const std::function< DScalar1< double, Eigen::Matrix< double, 30, 1 > >(const assembler::NonLinearAssemblerData &)> &fun30, const std::function< DScalar1< double, Eigen::Matrix< double, 60, 1 > >(const assembler::NonLinearAssemblerData &)> &fun60, const std::function< DScalar1< double, Eigen::Matrix< double, 81, 1 > >(const assembler::NonLinearAssemblerData &)> &fun81, const std::function< DScalar1< double, Eigen::Matrix< double, Eigen::Dynamic, 1, 0, SMALL_N, 1 > >(const assembler::NonLinearAssemblerData &)> &funN, const std::function< DScalar1< double, Eigen::Matrix< double, Eigen::Dynamic, 1, 0, BIG_N, 1 > >(const assembler::NonLinearAssemblerData &)> &funBigN, const std::function< DScalar1< double, Eigen::VectorXd >(const assembler::NonLinearAssemblerData &)> &funn)
Automatic differentiation scalar with first-order derivatives.
Automatic differentiation scalar with first- and second-order derivatives.
static void setVariableCount(size_t value)
Set the independent variable count used by the automatic differentiation layer.