8 using namespace assembler;
10 using namespace utils;
15 return (E * nu) / ((1.0 + nu) * (1.0 - 2.0 * nu));
17 return (nu * E) / (1.0 - nu * nu);
22 return E / (2.0 * (1.0 + nu));
30 A(0, 0) = nu / ((1.0 + nu) * (1.0 - 2.0 * nu));
31 A(0, 1) = (E*(0.5*nu*nu + 0.25))/(pow(nu + 1., 2)*pow(0.5 - nu, 2));
35 A(0, 0) = nu / (1.0 - nu * nu);
36 A(0, 1) = (E*(1. + nu*nu))/pow(-1. + nu*nu, 2);
38 A(1, 0) = 1 / (2 * (1 + nu));
39 A(1, 1) = -E / 2 * pow(1 + nu, -2);
49 A(0, 0) = pow(mu / (lambda + mu), 2);
50 A(0, 1) = (3 * lambda * lambda + 4 * lambda * mu + 2 * mu * mu) / pow(lambda + mu, 2);
51 A(1, 0) = mu / 2 / pow(lambda + mu, 2);
52 A(1, 1) = -lambda / 2 / pow(lambda + mu, 2);
56 A(0, 0) = pow(2 * mu / (lambda + 2 * mu), 2);
57 A(0, 1) = (4 * lambda * lambda + 8 * lambda * mu + 8 * mu * mu) / pow(lambda + 2 * mu, 2);
58 A(1, 0) = mu * 2 / pow(lambda + 2 * mu, 2);
59 A(1, 1) = -lambda * 2 / pow(lambda + 2 * mu, 2);
65 double convert_to_E(
const bool is_volume,
const double lambda,
const double mu)
68 return mu * (3.0 * lambda + 2.0 * mu) / (lambda + mu);
70 return 2 * mu * (2.0 * lambda + 2.0 * mu) / (lambda + 2.0 * mu);
73 double convert_to_nu(
const bool is_volume,
const double lambda,
const double mu)
76 return lambda / (2.0 * (lambda + mu));
78 return lambda / (lambda + 2.0 * mu);
96 switch (size * n_bases)
100 auto auto_diff_energy = fun6(data);
101 grad = auto_diff_energy.getGradient();
106 auto auto_diff_energy = fun8(data);
107 grad = auto_diff_energy.getGradient();
112 auto auto_diff_energy = fun12(data);
113 grad = auto_diff_energy.getGradient();
118 auto auto_diff_energy = fun18(data);
119 grad = auto_diff_energy.getGradient();
124 auto auto_diff_energy = fun24(data);
125 grad = auto_diff_energy.getGradient();
130 auto auto_diff_energy = fun30(data);
131 grad = auto_diff_energy.getGradient();
136 auto auto_diff_energy = fun60(data);
137 grad = auto_diff_energy.getGradient();
142 auto auto_diff_energy = fun81(data);
143 grad = auto_diff_energy.getGradient();
150 if (grad.size() <= 0)
154 auto auto_diff_energy = funN(data);
155 grad = auto_diff_energy.getGradient();
157 else if (n_bases * size <=
BIG_N)
159 auto auto_diff_energy = funBigN(data);
160 grad = auto_diff_energy.getGradient();
164 static bool show_message =
true;
168 logger().debug(
"[Warning] grad {}^{} not using static sizes", n_bases, size);
169 show_message =
false;
172 auto auto_diff_energy = funn(data);
173 grad = auto_diff_energy.getGradient();
189 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,
192 Eigen::MatrixXd hessian;
194 switch (size * n_bases)
198 auto auto_diff_energy = fun6(data);
199 hessian = auto_diff_energy.getHessian();
204 auto auto_diff_energy = fun8(data);
205 hessian = auto_diff_energy.getHessian();
210 auto auto_diff_energy = fun12(data);
211 hessian = auto_diff_energy.getHessian();
216 auto auto_diff_energy = fun18(data);
217 hessian = auto_diff_energy.getHessian();
222 auto auto_diff_energy = fun24(data);
223 hessian = auto_diff_energy.getHessian();
228 auto auto_diff_energy = fun30(data);
229 hessian = auto_diff_energy.getHessian();
234 auto auto_diff_energy = fun60(data);
235 hessian = auto_diff_energy.getHessian();
240 auto auto_diff_energy = fun81(data);
241 hessian = auto_diff_energy.getHessian();
248 if (hessian.size() <= 0)
252 auto auto_diff_energy = funN(data);
253 hessian = auto_diff_energy.getHessian();
257 static bool show_message =
true;
261 logger().debug(
"[Warning] hessian {}*{} not using static sizes", n_bases, size);
262 show_message =
false;
265 auto auto_diff_energy = funn(data);
266 hessian = auto_diff_energy.getHessian();
278 assert(displacement.cols() == 1);
280 displacement_grad.setZero();
286 assert(loc_val.grad.rows() == local_pts.rows());
287 assert(loc_val.grad.cols() == size);
289 for (
int d = 0; d < size; ++d)
291 for (std::size_t ii = 0; ii < loc_val.global.size(); ++ii)
293 displacement_grad.row(d) += loc_val.global[ii].val * loc_val.grad.row(p) * displacement(loc_val.global[ii].index * size + d);
298 displacement_grad = (displacement_grad *
vals.
jac_it[p]).eval();
303 assert(displacement.cols() == 1);
305 displacement_grad.setZero();
307 for (std::size_t j = 0; j < bs.
bases.size(); ++j)
313 assert(loc_val.grad.rows() == local_pts.rows());
314 assert(loc_val.grad.cols() == size);
316 for (
int d = 0; d < size; ++d)
318 for (std::size_t ii = 0; ii < b.
global().size(); ++ii)
320 displacement_grad.row(d) += b.
global()[ii].val * loc_val.grad.row(p) * displacement(b.
global()[ii].index * size + d);
325 displacement_grad = (displacement_grad *
vals.
jac_it[p]).eval();
330 double von_mises_stress;
332 if (stress.rows() == 3)
334 von_mises_stress = 0.5 * (stress(0, 0) - stress(1, 1)) * (stress(0, 0) - stress(1, 1)) + 3.0 * stress(0, 1) * stress(1, 0);
335 von_mises_stress += 0.5 * (stress(2, 2) - stress(1, 1)) * (stress(2, 2) - stress(1, 1)) + 3.0 * stress(2, 1) * stress(2, 1);
336 von_mises_stress += 0.5 * (stress(2, 2) - stress(0, 0)) * (stress(2, 2) - stress(0, 0)) + 3.0 * stress(2, 0) * stress(2, 0);
341 von_mises_stress = stress(0, 0) * stress(0, 0) - stress(0, 0) * stress(1, 1) + stress(1, 1) * stress(1, 1) + 3.0 * stress(0, 1) * stress(1, 0);
344 von_mises_stress = sqrt(fabs(von_mises_stress));
346 return von_mises_stress;
351 return F.determinant() * stress *
F.inverse().transpose();
356 return F.determinant() *
F.inverse() * stress *
F.inverse().transpose();
ElementAssemblyValues vals
stores per element basis values at given quadrature points and geometric mapping
std::vector< AssemblyValues > basis_values
std::vector< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > > jac_it
Represents one basis function and its gradient.
const std::vector< Local2Global > & global() const
Stores the basis functions for a given element in a mesh (facet in 2d, cell in 3d).
std::vector< Basis > bases
one basis function per node in the element
spdlog::logger & logger()
Retrieves the current logger.
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)
double convert_to_E(const bool is_volume, const double lambda, const double mu)
double convert_to_mu(const double E, const double nu)
double von_mises_stress_for_stress_tensor(const Eigen::MatrixXd &stress)
double convert_to_nu(const bool is_volume, const double lambda, const double mu)
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)
double convert_to_lambda(const bool is_volume, const double E, const double nu)
Eigen::Matrix2d d_E_nu_d_lambda_mu(const bool is_volume, const double lambda, const double mu)
Eigen::Matrix2d d_lambda_mu_d_E_nu(const bool is_volume, const double E, const double nu)
Automatic differentiation scalar with first-order derivatives.
Automatic differentiation scalar with first- and second-order derivatives.