36#include <polysolve/linear/Solver.hpp>
37#include <polysolve/nonlinear/Solver.hpp>
51 json first_material(
const json &materials)
53 return materials.is_array() ? materials.front() : materials;
56 void disable_newton_psd_projection(
json &solver_params)
58 const auto disable_for_newton = [](
json ¶ms) {
59 if (!params.contains(
"Newton") || params[
"Newton"].is_null())
60 params[
"Newton"] = json::object();
61 params[
"Newton"][
"use_psd_projection"] =
false;
64 if (solver_params.contains(
"solver") && solver_params[
"solver"].is_array())
66 for (
json &strategy : solver_params[
"solver"])
68 const std::string type = strategy.value(
"type",
"");
69 if (type ==
"Newton" || type ==
"SparseNewton" || type ==
"sparse_newton"
70 || type ==
"DenseNewton" || type ==
"dense_newton")
71 disable_for_newton(strategy);
76 disable_for_newton(solver_params);
80 json solver_params_for_residual_mode(
const json &solver_params,
const bool is_residual)
82 json params = solver_params;
84 disable_newton_psd_projection(params);
88 void assert_same_space_ids(
89 const json &materials,
90 const int displacement_space_id,
91 const int growth_space_id)
95 if (material.at(
"displacement_space_id").get<
int>() != displacement_space_id
96 || material.at(
"growth_space_id").get<
int>() != growth_space_id)
103 json elastic_material_from_growth_material(
const json &material)
105 if (!material.contains(
"elastic_material") || !material[
"elastic_material"].is_object())
106 log_and_throw_error(
"GrowthElasticity requires elastic_material to be an elastic material object.");
108 json elastic_material = material[
"elastic_material"];
109 const std::string type = elastic_material.value(
"type",
"");
111 log_and_throw_error(
"GrowthElasticity elastic_material must be an elastic material, got '{}'.", type);
113 if (material.contains(
"id"))
114 elastic_material[
"id"] = material[
"id"];
115 if (material.contains(
"rho"))
116 elastic_material[
"rho"] = material[
"rho"];
118 return elastic_material;
121 std::string elastic_formulation_from_growth_materials(
const json &materials)
123 std::string formulation;
126 const json elastic_material = elastic_material_from_growth_material(material);
127 const std::string type = elastic_material[
"type"];
128 if (formulation.empty())
130 else if (formulation != type)
131 formulation =
"MultiModels";
139 std::vector<Eigen::Triplet<double>>
entries;
140 entries.reserve(a.nonZeros() +
b.nonZeros());
142 for (
int k = 0; k < a.outerSize(); ++k)
143 for (StiffnessMatrix::InnerIterator it(a, k); it; ++it)
144 entries.emplace_back(it.row(), it.col(), it.value());
146 for (
int k = 0; k <
b.outerSize(); ++k)
147 for (StiffnessMatrix::InnerIterator it(b, k); it; ++it)
148 entries.emplace_back(a.rows() + it.row(), a.cols() + it.col(), it.value());
152 out.makeCompressed();
209 const json material = first_material(
args[
"materials"]);
210 if (!material.contains(
"growth_law") || material[
"growth_law"].is_null())
217 const json &gl = material[
"growth_law"];
218 const bool from_state = gl.contains(
"threshold") && gl[
"threshold"].is_string() && gl[
"threshold"] ==
"from_state";
219 const bool has_threshold = from_state || (gl.contains(
"threshold") && (gl[
"threshold"].is_number() || gl[
"threshold"].is_object()));
235 "(a number in Pa, a per_element_file, or \"from_state\"); set one to enable the law.");
262 log_and_throw_error(
"growth_law threshold \"from_state\" needs theta_crit > 0 (the C_check construction).");
276 const std::string nodal =
args[
"boundary_conditions"].value(
"growth_nodal_field",
"");
278 log_and_throw_error(
"growth_law (solved growth) cannot be combined with growth_nodal_field (prescribed growth).");
281 if (m.contains(
"growth_law") && m[
"growth_law"] != gl)
283 "(per-element thresholds go in the threshold file).");
288 const Eigen::MatrixXd &solution,
298 Eigen::MatrixXd &solution)
303 reader,
"primary",
space_,
304 mesh_->dimension(), 0, solution);
318 const std::string &formulation,
321 const std::string &out_path)
323 for (
const std::string field : {
"pressure_boundary",
"pressure_cavity"})
325 const json::json_pointer path(
"/boundary_conditions/" + field);
326 if (
args.contains(path) && !
args.at(path).empty())
339 if (
args.contains(
"time") && !
args[
"time"].is_null())
340 log_and_throw_error(
"GrowthElasticity has no dynamics: use growth_law.n_steps / t_end for pseudo-time, not \"time\".");
345 if (
args[
"contact"][
"enabled"].get<bool>())
346 log_and_throw_error(
"GrowthElasticity does not yet support contact (untested combination).");
349 if (
args[
"solver"][
"advanced"][
"check_inversion"] ==
"Conservative")
351 if (
auto elastic_assembler = std::dynamic_pointer_cast<assembler::ElasticityAssembler>(
primary_assembler_))
352 elastic_assembler->set_use_robust_jacobian();
360 growth_assembler_ = std::make_shared<assembler::Laplacian>(
"growth_diffusivity");
369 problem = std::make_shared<assembler::GenericTensorProblem>(
"GrowthDisplacement");
371 growth_problem_ = std::make_shared<assembler::GenericScalarProblem>(
"GrowthField");
375 tmp[
"is_time_dependent"] =
false;
385 td[
"is_time_dependent"] =
true;
389 auto bc =
args[
"boundary_conditions"];
404 this->args[
"contact"].erase(
"_dhat_was_explicit");
409 const json material = first_material(
args.at(
"materials"));
413 log_and_throw_error(
"GrowthElasticity requires distinct displacement and growth FE spaces.");
421 if (
args[
"materials"].is_array())
423 json materials = json::array();
424 for (
const json &material :
args[
"materials"])
425 materials.push_back(elastic_material_from_growth_material(material));
429 return elastic_material_from_growth_material(
args[
"materials"]);
476 logger().info(
"growth_law: quadrature_order raised to 2 "
477 "(the centroid rule leaves the P1 growth field with null modes).");
478 args[
"space"][
"advanced"][
"quadrature_order"] = 2;
486 Eigen::VectorXi displacement_orders, displacement_ordersq;
489 if (
args[
"space"][
"use_p_ref"])
493 args[
"space"][
"advanced"][
"B"],
494 args[
"space"][
"advanced"][
"h1_formula"],
495 args[
"space"][
"discr_order"],
496 args[
"space"][
"advanced"][
"discr_order_max"],
498 displacement_orders);
500 logger().info(
"min p: {} max p: {}", displacement_orders.minCoeff(), displacement_orders.maxCoeff());
507 displacement_ordersq,
508 args[
"space"][
"basis_type"],
509 args[
"space"][
"poly_basis_type"],
512 args[
"space"][
"advanced"][
"quadrature_order"],
513 args[
"space"][
"advanced"][
"mass_quadrature_order"],
514 args[
"space"][
"advanced"][
"use_corner_quadrature"],
515 args[
"space"][
"advanced"][
"n_harmonic_samples"],
516 args[
"space"][
"advanced"][
"integral_constraints"],
526 logger().info(
"Building collision mesh...");
533 for (
int d = 0; d < mesh.
dimension(); ++d)
542 if (
args[
"space"][
"advanced"][
"count_flipped_els"])
545 const int n_samples = 10;
554 logger().info(
"Building cache...");
560 logger().info(
" took {}s", timer.getElapsedTime());
585 std::vector<int> unused_neumann_boundary_nodes;
593 unused_neumann_boundary_nodes,
612 for (
int d = 0; d < mesh.
dimension(); ++d)
624 Eigen::VectorXi growth_orders, growth_ordersq;
632 args[
"space"][
"basis_type"],
633 args[
"space"][
"poly_basis_type"],
636 args[
"space"][
"advanced"][
"quadrature_order"],
637 args[
"space"][
"advanced"][
"mass_quadrature_order"],
638 args[
"space"][
"advanced"][
"use_corner_quadrature"],
639 args[
"space"][
"advanced"][
"n_harmonic_samples"],
640 args[
"space"][
"advanced"][
"integral_constraints"],
663 Eigen::VectorXi vmap(nv);
664 for (
int v = 0; v < nv; ++v)
672 logger().info(
"GrowthElasticity: growth node map built from mesh vertices ({} nodes).", nv);
693 std::vector<int> unused_neumann_boundary_nodes;
701 unused_neumann_boundary_nodes,
727 json rhs_solver_params =
args[
"solver"][
"linear"];
728 if (!rhs_solver_params.contains(
"Pardiso"))
729 rhs_solver_params[
"Pardiso"] = {};
730 rhs_solver_params[
"Pardiso"][
"mtype"] = -2;
738 args[
"space"][
"advanced"][
"bc_method"],
750 args[
"space"][
"advanced"][
"bc_method"],
763 delta = (max - min) / 2. + min;
765 p_params[
"bbox_center"] = {delta(0), delta(1), delta(2)};
767 p_params[
"bbox_center"] = {delta(0), delta(1)};
776 logger().info(
"Assigning rhs...");
799 logger().info(
"Assembling mass mat...");
805 assert(
mass_.size() > 0);
807 for (
int k = 0; k <
mass_.outerSize(); ++k)
808 for (StiffnessMatrix::InnerIterator it(
mass_, k); it; ++it)
813 if (
args[
"solver"][
"advanced"][
"lump_mass_matrix"])
840 const std::string path =
args[
"boundary_conditions"][
"growth_nodal_field"];
845 if (!input || !*input)
847 std::istream &in = *input;
849 std::vector<double> values;
857 "GrowthElasticity: growth_nodal_field '{}' has {} values, expected {} (one per growth node, mesh-vertex order).",
860 Eigen::MatrixXd field = Eigen::Map<Eigen::VectorXd>(values.data(), values.size());
866 if (map.size() != field.rows())
868 "GrowthElasticity: growth-space node map has {} entries for {} values; "
869 "growth_nodal_field cannot be placed on the right nodes.",
870 map.size(), field.rows());
871 Eigen::MatrixXd remapped(field.rows(), 1);
872 for (
int i = 0; i < map.size(); ++i)
873 remapped(map(i)) = field(i);
876 if ((field.array() <= 0).any())
878 "GrowthElasticity: growth_nodal_field '{}' contains non-positive theta (min {}).",
879 path, field.minCoeff());
890 if (prescribed.size() > 0)
892 solution = prescribed;
905 if (solution.size() > 0 && (solution.array() == 0.0).all())
907 logger().info(
"Growth field initialized to theta = 1 (identity growth).");
913 const Eigen::MatrixXd &displacement,
914 const Eigen::MatrixXd &growth)
const
918 assert(displacement.cols() == growth.cols());
920 Eigen::MatrixXd solution(displacement.rows() + growth.rows(), displacement.cols());
921 solution << displacement, growth;
926 const Eigen::MatrixXd &solution,
927 Eigen::MatrixXd &displacement,
928 Eigen::MatrixXd &growth)
const
937 assert(solution.cols() == 1);
944 Eigen::MatrixXd displacement, growth;
950 for (
const auto &form :
forms)
967 t, 0.0,
mesh_->is_volume());
985 for (
const auto &form :
forms)
993 auto stacked_al = std::make_shared<solver::StackedAugmentedLagrangianForm>();
994 const auto displacement_al_block = stacked_al->add_block(displacement_block.size());
995 const auto growth_al_block = stacked_al->add_block(growth_block.size());
1002 displacement_al_block,
1003 std::make_shared<solver::BCLagrangianForm>(
1004 displacement_block.size(),
1018 log_and_throw_error(
"growth_law: growth-space dirichlet_boundary entries are not supported "
1019 "(the growth law owns the growth DOFs; tag displacement BCs with fe_space).");
1020 if (has_growth_pins)
1023 std::make_shared<solver::BCLagrangianForm>(
1027 else if (prescribed.size() > 0)
1038 all_growth_nodes[i] = i;
1042 std::make_shared<solver::BCLagrangianForm>(
1049 const int gdiscr_order =
mesh_->orders().size() <= 0 ? 1 :
mesh_->orders().maxCoeff();
1055 std::make_shared<solver::BCLagrangianForm>(
1056 growth_block.size(),
1069 assert(
solve_data_.
nl_problem !=
nullptr &&
"Growth forms must initialize the nonlinear problem before solving");
1072 json nonlinear_params = solver_params_for_residual_mode(
args[
"solver"][
"nonlinear"], nl_problem.
is_residual());
1073 if (grad_tol_factor != 1.0 && nonlinear_params.contains(
"grad_norm_tol"))
1074 nonlinear_params[
"grad_norm_tol"] = nonlinear_params[
"grad_norm_tol"].get<
double>() * grad_tol_factor;
1075 json al_nonlinear_params = solver_params_for_residual_mode(
args[
"solver"][
"augmented_lagrangian"][
"nonlinear"], nl_problem.
is_residual());
1079 if (nonlinear_params.contains(
"Newton") && nonlinear_params[
"Newton"].contains(
"residual_tolerance"))
1081 const double main_tol = nonlinear_params[
"Newton"][
"residual_tolerance"];
1082 const double al_tol = al_nonlinear_params.value(
"Newton", json::object()).value(
"residual_tolerance", 0.0);
1083 if (main_tol > al_tol)
1084 al_nonlinear_params[
"Newton"][
"residual_tolerance"] = main_tol;
1087 std::shared_ptr<polysolve::nonlinear::Solver> nl_solver =
1088 polysolve::nonlinear::Solver::create(
1089 nonlinear_params,
args[
"solver"][
"linear"],
1095 const auto update_displacement_barrier_stiffness = [&](
const Eigen::VectorXd &
x) {
1104 args[
"solver"][
"augmented_lagrangian"][
"initial_weight"],
1105 args[
"solver"][
"augmented_lagrangian"][
"scaling"],
1106 args[
"solver"][
"augmented_lagrangian"][
"max_weight"],
1107 args[
"solver"][
"augmented_lagrangian"][
"eta"],
1108 update_displacement_barrier_stiffness);
1112 {{
"type", al_weight > 0 ?
"al" :
"rc"},
1114 {
"info", nl_solver->info()}});
1121 nl_problem, solution, al_nonlinear_params,
1124 nl_problem, solution, nonlinear_params,
1129 Eigen::VectorXd
x = solution;
1131 update_displacement_barrier_stiffness(
x);
1133 nl_solver->minimize(nl_problem,
x);
1136 stats.
solver_info.push_back({{
"type",
"rc"}, {
"t", step}, {
"info", nl_solver->info()}});
1141 Eigen::MatrixXd &sol,
1145 assert(!initial_condition_override &&
"GrowthElasticity does not support initial-condition overrides");
1146 assert(!post_step &&
"GrowthElasticity does not support post-step callbacks");
1152 logger().info(
"Solving GrowthElasticity");
1157 if (sol.size() <= 0)
1159 Eigen::MatrixXd displacement, growth;
1162 const int cols = std::max(displacement.cols(), growth.cols());
1163 if (displacement.cols() != cols)
1164 displacement.conservativeResize(Eigen::NoChange, cols);
1165 if (growth.cols() != cols)
1166 growth.conservativeResize(Eigen::NoChange, cols);
1171 sol.conservativeResize(Eigen::NoChange, 1);
1195 double characteristic_length = 0;
1196 if (
args[
"solver"][
"advanced"][
"characteristic_length"] > 0)
1197 characteristic_length =
args[
"solver"][
"advanced"][
"characteristic_length"];
1201 mesh_->bounding_box(min, max);
1202 characteristic_length = (max - min).norm();
1205 double characteristic_force_density = 0;
1206 if (
args[
"solver"][
"advanced"][
"characteristic_force_density"] <= 0)
1208 logger().warn(
"No user-specified force density was provided, defaulting to 10000.");
1209 characteristic_force_density = 10000;
1212 characteristic_force_density =
args[
"solver"][
"advanced"][
"characteristic_force_density"];
1217 polysolve::linear::Solver::create(
args[
"solver"][
"linear"],
logger()),
1218 characteristic_length, characteristic_force_density,
1232 const int n_el =
mesh_->n_elements();
1233 const json material = first_material(
args[
"materials"]);
1234 const json &gl = material[
"growth_law"];
1236 const auto read_scalar_field = [&](
const json &spec,
const std::string &what,
1237 const std::string &default_field, Eigen::VectorXd &out) {
1238 if (spec.is_number())
1240 out.setConstant(n_el, spec.get<
double>());
1243 if (!spec.is_object() || spec.value(
"type",
"") !=
"per_element_file")
1244 log_and_throw_error(
"growth_law: {} must be a number or {{type: per_element_file, path, field}}.", what);
1246 resources_, spec.at(
"path").get<std::string>(), spec.value(
"field", default_field), 1);
1247 if (values.rows() != n_el)
1248 log_and_throw_error(
"growth_law: {} file has {} cells, mesh has {} elements.", what, values.rows(), n_el);
1249 out = values.col(0);
1270 if (material.contains(
"normal_growth"))
1281 return std::nan(
"");
1282 std::vector<double> s(v.data(), v.data() + v.size());
1283 std::nth_element(s.begin(), s.begin() + s.size() / 2, s.end());
1284 return s[s.size() / 2];
1289 const int n_el =
mesh_->n_elements();
1297 for (
int e = 0; e < n_el; ++e)
1301 const Eigen::ArrayXd
da =
vals.det.array() *
vals.quadrature.weights.array();
1303 for (
const auto &bv :
vals.basis_values)
1305 const double integral = (bv.val.array() *
da).sum();
1306 for (
const auto &g : bv.global)
1322 logger().info(
"growth_law: threshold {} over {} elements; {} increments to t = {:g}; "
1323 "{} growth quadrature points on element 0.",
1330 const Eigen::VectorXd &u,
const double t,
1331 Eigen::VectorXd &phi_full, Eigen::VectorXd &phi_no_shear, Eigen::VectorXd &theta_tot_out)
1335 log_and_throw_error(
"growth_law: the C_check threshold needs the GrowthElasticity assembler.");
1336 const int n_el =
mesh_->n_elements();
1337 const int dim =
mesh_->dimension();
1343 phi_full.resize(n_el);
1344 phi_no_shear.resize(n_el);
1345 theta_tot_out.resize(n_el);
1348 for (
int e = 0; e < n_el; ++e)
1351 const Eigen::ArrayXd
da =
vals.det.array() *
vals.quadrature.weights.array();
1352 Eigen::Matrix3d
F = Eigen::Matrix3d::Zero();
1354 for (
int p = 0; p <
da.size(); ++p)
1356 Eigen::Matrix3d Fp = Eigen::Matrix3d::Identity();
1357 for (
const auto &bv :
vals.basis_values)
1358 for (
const auto &g : bv.global)
1359 for (
int d = 0; d < dim; ++d)
1360 Fp.row(d) += g.val * u(g.index * dim + d) * bv.grad_t_m.row(p);
1362 pos +=
da(p) *
vals.val.row(p);
1366 const Eigen::Matrix3d C =
F.transpose() *
F;
1369 const Eigen::Vector3d n = ge->wall_normal(e).normalized();
1370 const Eigen::Vector3d trial = std::abs(n(0)) < 0.9 ? Eigen::Vector3d::UnitX() : Eigen::Vector3d::UnitY();
1371 const Eigen::Vector3d e1 = (trial - trial.dot(n) * n).normalized();
1372 const Eigen::Vector3d e2 = n.cross(e1);
1373 const double c11 = e1.dot(C * e1), c22 = e2.dot(C * e2), c12 = e1.dot(C * e2);
1374 const double theta_tot = std::sqrt(std::max(c11 * c22 - c12 * c12, 0.0));
1375 if (!(theta_tot > 0))
1377 theta_tot_out(e) = theta_tot;
1380 const double th = theta_tot / crit;
1382 const Eigen::Matrix3d nn = n * n.transpose();
1383 const Eigen::Matrix3d P = Eigen::Matrix3d::Identity() - nn;
1384 const Eigen::Matrix3d Fgi = P / std::sqrt(th) + nn / vn;
1385 const Eigen::Matrix3d Ce = Fgi.transpose() * C * Fgi;
1388 const double layer = 1.0 / n.dot(Ce.inverse() * n);
1389 const Eigen::Matrix3d Ce_ns = P * Ce * P + layer * nn;
1391 phi_full(e) = ge->driving_force(e, pos, t, Ce);
1392 phi_no_shear(e) = ge->driving_force(e, pos, t, Ce_ns);
1394 if (!phi_full.allFinite() || !phi_no_shear.allFinite())
1399 Eigen::VectorXd &par, Eigen::VectorXd &gam, Eigen::VectorXd &clamped)
1401 Eigen::VectorXd full, ns, tt;
1404 par = ns.cwiseMax(0.0);
1405 clamped = (ns.array() < 0).cast<double>().matrix();
1409 const Eigen::VectorXd &clamped,
const double t,
const double omega)
1411 const int n_el =
mesh_->n_elements();
1414 if (clamped.size() == n_el)
1422 const std::string om = omega != 1.0 ? fmt::format(
"; relaxation omega {:.3g}", omega) : std::string();
1423 logger().info(
"growth_law: threshold from the state at t = {:g}: PHI_PAR median {:.4g} Pa, clamped on {:.1f}%; "
1424 "f_gamma median {:.4g} Pa, in [{:.4g}, {:.4g}]; threshold in [{:.4g}, {:.4g}] Pa, negative on {:.1f}% of elements{}",
1432 const int n_el =
mesh_->n_elements();
1433 Eigen::VectorXd out(n_el);
1435 for (
int e = 0; e < n_el; ++e)
1439 const Eigen::ArrayXd
da =
vals.det.array() *
vals.quadrature.weights.array();
1440 Eigen::ArrayXd th = Eigen::ArrayXd::Zero(
da.size());
1441 for (
const auto &bv :
vals.basis_values)
1442 for (
const auto &g : bv.global)
1443 th += g.val * theta(g.index) * bv.val.array();
1444 out(e) = (th *
da).sum() /
da.sum();
1450 const Eigen::VectorXd &mult,
const std::vector<char> &pinned)
1454 std::vector<double> free_res;
1455 double min_slack = std::numeric_limits<double>::infinity();
1457 for (
int a = 0; a < int(pinned.size()); ++a)
1460 const double r = mult(a) / v;
1463 min_slack = std::min(min_slack, r);
1467 free_res.push_back(std::abs(r));
1469 double med = 0, mx = 0;
1470 if (!free_res.empty())
1472 mx = *std::max_element(free_res.begin(), free_res.end());
1473 std::nth_element(free_res.begin(), free_res.begin() + free_res.size() / 2, free_res.end());
1474 med = free_res[free_res.size() / 2];
1476 logger().info(
"growth step {} (t = {:g}) KKT: free DOFs |phi - f_I| median {:.3g} Pa, max {:.3g} Pa ({}); "
1477 "pinned min slack {:.3g} Pa ({})",
1478 step, t, med, mx, free_res.size(), n_pinned > 0 ? min_slack : 0.0, n_pinned);
1480 {{
"type",
"growth_kkt"}, {
"t", t}, {
"step", step}, {
"free_median_pa", med}, {
"free_max_pa", mx}, {
"pinned_min_slack_pa", n_pinned > 0 ? min_slack : 0.0}});
1489 const int n_el =
mesh_->n_elements();
1496 for (
int e = 0; e < n_el; ++e)
1512 int n_grow = 0, n_neg = 0, n_dneg = 0;
1513 for (
int e = 0; e < n_el; ++e)
1518 n_dneg += (D(e) < 0);
1520 logger().info(
"growth step {} (t = {:g}): dissipation int D dV {:.4g} (cumulative {:.4g}), shear supply int S dV "
1521 "{:.4g} (cumulative {:.4g}) [Pa x mesh volume]; S/D {:.3f}; growing elements {}, with phi < 0: {}, with D < 0: {}",
1522 step, t, iD, cD, iS, cS, iD != 0 ? iS / iD : 0.0, n_grow, n_neg, n_dneg);
1524 {{
"type",
"growth_dissipation"}, {
"t", t}, {
"step", step}, {
"D", iD}, {
"S", iS}, {
"D_cumulative", cD}, {
"S_cumulative", cS}, {
"n_phi_negative", n_neg}, {
"n_D_negative", n_dneg}});
1532 Eigen::VectorXd full, ns, tt;
1534 const Eigen::VectorXd phi_state = ns.cwiseMax(0.0) + (full - ns);
1539 std::vector<double> res, att;
1540 for (
int e = 0; e < th_e.size(); ++e)
1541 if (th_e(e) > 1.0 + 1e-9 && ns(e) >= 0)
1548 logger().info(
"growth step {} (t = {:g}): lag residual: no grown unclamped elements yet", step, t);
1551 const auto q = [](std::vector<double> v,
const double f) {
1552 const size_t k = std::min(v.size() - 1,
size_t(f *
double(v.size() - 1) + 0.5));
1553 std::nth_element(v.begin(), v.begin() + k, v.end());
1556 logger().info(
"growth step {} (t = {:g}): lag residual |phi(state) - phi used| median {:.4g} Pa (p95 {:.4g}); "
1557 "attainment median {:.4f} (p5 {:.4f}, p95 {:.4f}) over {} grown unclamped elements",
1558 step, t, q(res, 0.5), q(res, 0.95), q(att, 0.5), q(att, 0.05), q(att, 0.95), res.size());
1560 {{
"type",
"growth_lag_residual"}, {
"t", t}, {
"step", step}, {
"abs_median", q(res, 0.5)}, {
"abs_p95", q(res, 0.95)}, {
"attainment_median", q(att, 0.5)}});
1566 Eigen::VectorXd full_grad;
1567 stacked_form_->first_derivative(solution.col(0), full_grad);
1592 std::vector<char> pinned(ng, 1);
1601 constexpr double omega_min = 0.05, omega_max = 5.0;
1602 Eigen::VectorXd r_prev;
1603 double omega_prev = 1.0;
1604 bool set_changed_last_pass =
true;
1605 int n_threshold_updates = 0;
1609 for (
int a = 0; a < ng; ++a)
1625 bool threshold_moved =
false;
1630 ++n_threshold_updates;
1633 Eigen::VectorXd par_g, gam_g, clamped_g;
1635 const int n_el = int(par_g.size());
1636 Eigen::VectorXd r(2 * n_el);
1638 const double dphi = ((par_g + gam_g) - phi_old).cwiseAbs().maxCoeff();
1640 if (!set_changed_last_pass && r_prev.size() == r.size())
1642 const Eigen::VectorXd dr = r - r_prev;
1643 const double den = dr.squaredNorm();
1645 omega = std::clamp(-omega_prev * r_prev.dot(dr) / den, omega_min, omega_max);
1653 const bool any_free = std::find(pinned.begin(), pinned.end(), 0) != pinned.end();
1657 logger().info(
"growth step {} (t = {:g}) pass {}: threshold updated, max |d phi| {:.4g} Pa{}{}",
1658 step, t, pass, dphi, threshold_moved ?
" (re-solving)" :
"",
1666 int n_released = 0, n_pinned = 0, n_pinned_total = 0;
1667 std::vector<char> next = pinned;
1668 for (
int a = 0; a < ng; ++a)
1670 const double theta = solution(nu + a, 0);
1674 if (mult(a) < -release_tol(a))
1685 n_pinned_total += next[a];
1689 logger().info(
"growth step {} (t = {:g}) active-set pass {}: {} released, {} pinned, {}/{} at theta_n",
1690 step, t, pass, n_released, n_pinned, n_pinned_total, ng);
1692 {{
"type",
"growth_active_set"}, {
"t", t}, {
"step", step}, {
"pass", pass}, {
"released", n_released}, {
"pinned", n_pinned}, {
"n_at_bound", n_pinned_total}});
1694 set_changed_last_pass = n_released != 0 || n_pinned != 0;
1695 if (n_released == 0 && n_pinned == 0 && !threshold_moved)
1700 logger().info(
"growth step {} (t = {:g}): active set settled; confirmation pass with the gradient "
1712 "(raise growth_law.max_active_set_iterations, or reduce the increment).",
1722 theta_n_ = solution.col(0).tail(ng);
1731 const Eigen::VectorXd theta_start =
theta_n_;
1734 const Eigen::VectorXd theta = solution.col(0).tail(ng);
1735 const Eigen::VectorXd dtheta = theta - theta_start;
1737 logger().info(
"growth step {}/{} (t = {:g}): {} pass(es), {}/{} DOFs growing, "
1738 "theta in [{:.6g}, {:.6g}], max increment {:.3e}, min increment {:.3e}",
1740 theta.minCoeff(), theta.maxCoeff(), dtheta.maxCoeff(), dtheta.minCoeff());
1742 {{
"type",
"growth_step"}, {
"t", t}, {
"step", step}, {
"passes", passes}, {
"n_growing", n_active}, {
"theta_min", theta.minCoeff()}, {
"theta_max", theta.maxCoeff()}});
1753 Eigen::MatrixXd &solution,
const int depth)
1756 const Eigen::MatrixXd solution0 = solution;
1766 catch (
const std::runtime_error &e)
1770 solution = solution0;
1777 const double t_mid = 0.5 * (t_from + t_to);
1778 logger().warn(
"growth step {}: the increment to t = {:g} failed ({}); retrying from t = {:g} as two "
1779 "half increments, to t = {:g} and t = {:g} (split level {} of {})",
1782 {{
"type",
"growth_split"}, {
"step", step}, {
"t_from", t_from}, {
"t_to", t_to}, {
"level", depth + 1}});
1793 const Eigen::VectorXd theta = solution.col(0).tail(ng);
1794 const Eigen::VectorXd dtheta = theta -
theta_n_;
1801 solution.col(0).segment(nu, ng) =
theta_n_;
1806 for (
int a = 0; a < ng; ++a)
1824 const std::string
name = fmt::format(
"growth_step_{:d}.vtu", step);
1831 pvd <<
"<?xml version=\"1.0\"?>\n"
1832 <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">\n"
1833 <<
" <Collection>\n";
1834 for (
int k = 1; k <= step; ++k)
1835 pvd << fmt::format(
" <DataSet timestep=\"{:.17g}\" group=\"\" part=\"0\" file=\"growth_step_{:d}.vtu\"/>\n",
1837 pvd <<
" </Collection>\n</VTKFile>\n";
1843 Eigen::MatrixXd displacement, growth;
1849 if (!
args[
"output"][
"data"][
"stress_mat"].get<std::string>().empty()
1850 || !
args[
"output"][
"data"][
"mises"].get<std::string>().empty())
1852 "GrowthElastic: output.data.stress_mat / mises are evaluated with the ungrown "
1853 "material at the total F; the grown-material stresses are the VTU fields "
1854 "(cauchy_stess_*, pk1_stess_*, pk2_stess_*, von_mises).");
1859 if (!
args[
"output"][
"advanced"][
"compute_error"])
1862 Eigen::MatrixXd displacement, growth;
1870 const int e,
const Eigen::MatrixXd &local_pts,
const double t,
1871 const Eigen::MatrixXd &displacement,
const Eigen::MatrixXd &growth,
1872 Eigen::MatrixXd &cauchy, Eigen::MatrixXd &pk1, Eigen::MatrixXd &pk2,
1873 Eigen::MatrixXd &von_mises, Eigen::MatrixXd &energy)
const
1877 log_and_throw_error(
"GrowthElastic: grown stresses need the GrowthElasticity assembler.");
1879 const int dim =
mesh_->dimension();
1885 Eigen::MatrixXd theta, theta_grad;
1888 e, local_pts, growth, theta, theta_grad);
1890 const int n = local_pts.rows();
1891 cauchy.resize(n, 9);
1894 von_mises.resize(n, 1);
1895 energy.resize(n, 1);
1897 Eigen::MatrixXd grad_u(dim, dim);
1898 Eigen::Matrix3d s, P, S;
1899 for (
int p = 0; p < n; ++p)
1902 const Eigen::Matrix3d
F = Eigen::Matrix3d::Identity() + grad_u;
1904 ge->grown_stresses(e,
vals.val.row(p), t,
F, theta(p, 0), s, P, S, w);
1907 cauchy.row(p) = Eigen::Map<const Eigen::Matrix<double, 1, 9>>(s.data());
1908 pk1.row(p) = Eigen::Map<const Eigen::Matrix<double, 1, 9>>(P.data());
1909 pk2.row(p) = Eigen::Map<const Eigen::Matrix<double, 1, 9>>(S.data());
1917 const Eigen::MatrixXd &displacement,
const Eigen::MatrixXd &growth,
1918 std::vector<io::OutputField> &fields)
const
1920 if (!
mesh_ ||
mesh_->dimension() != 3 || displacement.size() <= 0 || growth.size() <= 0)
1929 static const std::array<std::string, 3> tensor_names = {{
"cauchy_stess",
"pk1_stess",
"pk2_stess"}};
1933 std::array<std::array<io::OutputField *, 3>, 3> tensor{};
1936 const auto collect = [&](
const std::string &suffix) {
1940 if (field.name ==
"von_mises" + suffix)
1942 tg.von_mises = &field;
1946 for (
int a = 0; a < 3; ++a)
1947 for (
int k = 0; k < 3; ++k)
1948 if (field.name == fmt::format(
"{}{}_{}", tensor_names[a], suffix, k + 1))
1950 tg.tensor[a][k] = &field;
1956 const Targets
point = collect(
"");
1957 const Targets avg = collect(
"_avg");
1959 Eigen::MatrixXd cauchy, pk1, pk2, vm, w;
1966 if (field.name ==
"energy")
1968 else if (field.name ==
"energy_avg")
1969 energy_avg = &field;
1971 if ((energy || energy_avg) && has_element_samples)
1974 Eigen::VectorXd values = Eigen::VectorXd::Zero(ns);
1975 Eigen::VectorXd sum = Eigen::VectorXd::Zero(
mesh_->n_elements());
1976 Eigen::VectorXi count = Eigen::VectorXi::Zero(
mesh_->n_elements());
1977 for (
int i = 0; i < ns; ++i)
1983 values(i) = w(0, 0);
1984 sum(e) += values(i);
1987 for (
int i = 0; i < ns; ++i)
1992 if (energy && i < energy->values.rows())
1993 energy->values(i, 0) = values(i);
1994 if (energy_avg && i < energy_avg->values.rows())
1995 energy_avg->values(i, 0) = sum(e) / count(e);
1999 if (!
point.any && !avg.any)
2003 const auto write_row = [](
const Targets &tg,
const int row,
2004 const std::array<const Eigen::MatrixXd *, 3> &tensors,
2005 const Eigen::MatrixXd &vm,
const int src) {
2006 if (tg.von_mises && row < tg.von_mises->values.rows())
2007 tg.von_mises->values(row, 0) = vm(src, 0);
2008 for (
int a = 0; a < 3; ++a)
2009 for (
int k = 0; k < 3; ++k)
2010 if (tg.tensor[a][k] && row < tg.tensor[a][k]->values.rows())
2011 tg.tensor[a][k]->values.row(row) = tensors[a]->block(src, 3 * k, 1, 3);
2015 if (
point.any && has_element_samples)
2023 write_row(
point, i, {{&cauchy, &pk1, &pk2}}, vm, 0);
2034 Eigen::VectorXd areas = Eigen::VectorXd::Zero(nb);
2035 std::array<Eigen::MatrixXd, 3> avg_tensor;
2036 for (
auto &m : avg_tensor)
2038 Eigen::MatrixXd avg_vm = Eigen::MatrixXd::Zero(nb, 1);
2042 Eigen::MatrixXd local_pts;
2043 if (
mesh_->is_simplex(e))
2045 else if (
mesh_->is_cube(e))
2047 else if (
mesh_->is_prism(e))
2055 const double area = (
vals.det.array() *
vals.quadrature.weights.array()).sum();
2057 grown_stress_at(e, local_pts, sample.
time, displacement, growth, cauchy, pk1, pk2, vm, w);
2059 for (
size_t j = 0; j < bs.
bases.size(); ++j)
2062 if (b.global().size() > 1)
2064 const int index = b.global().front().index;
2065 areas(index) += area;
2066 avg_tensor[0].row(index) += cauchy.row(j) * area;
2067 avg_tensor[1].row(index) += pk1.row(j) * area;
2068 avg_tensor[2].row(index) += pk2.row(j) * area;
2069 avg_vm(index) += vm(j) * area;
2073 for (
int i = 0; i < nb; ++i)
2075 if (!(areas(i) > 0))
2077 for (
auto &m : avg_tensor)
2078 m.row(i) /= areas(i);
2079 avg_vm(i) /= areas(i);
2083 Eigen::MatrixXd nodal(nb, 28);
2084 nodal << avg_tensor[0], avg_tensor[1], avg_tensor[2], avg_vm;
2087 const auto write_sampled = [&](
const int row,
const Eigen::MatrixXd &v) {
2088 cauchy = v.middleCols(0, 9);
2089 pk1 = v.middleCols(9, 9);
2090 pk2 = v.middleCols(18, 9);
2091 write_row(avg, row, {{&cauchy, &pk1, &pk2}}, v.middleCols(27, 1), 0);
2094 if (has_element_samples)
2101 Eigen::MatrixXd local_sol, local_grad;
2104 e, sample.
local_points.row(i), nodal_flat, local_sol, local_grad);
2105 write_sampled(i, local_sol);
2108 else if (sample.
node_ids.size() > 0)
2110 for (
int i = 0; i < sample.
node_ids.size(); ++i)
2112 const int node = sample.
node_ids(i);
2113 if (node >= 0 && node < nb)
2114 write_sampled(i, nodal.row(node));
2121 const Eigen::MatrixXd &solution,
2128 const bool passed_is_stacked = solution.rows() ==
total_ndof();
2129 const Eigen::MatrixXd &stacked =
2134 Eigen::MatrixXd displacement, growth;
2137 std::vector<io::OutputField> fields =
2146 if (field.name ==
"solution")
2147 field.name =
"displacement";
2148 else if (field.name ==
"solution_gradient")
2149 field.name =
"displacement_gradient";
2152 if (!
mesh_ || growth.size() <= 0)
2162 const auto has_field = [&](
const std::string &
name) {
2163 return std::any_of(fields.begin(), fields.end(), [&](
const io::OutputField &field) {
2164 return field.name == name;
2169 const auto ¶view_options =
args[
"output"][
"paraview"][
"options"];
2170 if (!paraview_options[
"material"] || !has_element_samples)
2173 const auto params = assembler.parameters();
2174 std::map<std::string, Eigen::MatrixXd> param_values;
2175 for (
const auto &[p, _] : params)
2176 param_values[p].setZero(output_rows, 1);
2184 for (
const auto &[p, func] : params)
2188 for (
const auto &[
name, values] : param_values)
2196 const auto sample_growth_scalar = [&](
const Eigen::MatrixXd &nodal, Eigen::MatrixXd &values, Eigen::MatrixXd *gradients =
nullptr) ->
bool {
2197 if (has_element_samples)
2199 values.resize(sample.local_points.rows(), 1);
2201 gradients->resize(sample.local_points.rows(), mesh_->dimension());
2202 for (
int i = 0; i < sample.local_points.rows(); ++i)
2204 const int element_id = sample.element_ids(i);
2209 gradients->row(i).setZero();
2213 Eigen::MatrixXd local_sol, local_grad;
2215 *mesh_, 1, growth_space_.basis_list(), growth_space_.geometry_basis_list(),
2216 element_id, sample.local_points.row(i), nodal, local_sol, local_grad);
2217 values(i) = local_sol(0);
2219 gradients->row(i) = local_grad;
2222 if (output_rows > values.rows())
2224 const int previous_rows = values.rows();
2225 values.conservativeResize(output_rows, Eigen::NoChange);
2226 values.bottomRows(output_rows - previous_rows).setZero();
2229 gradients->conservativeResize(output_rows, Eigen::NoChange);
2230 gradients->bottomRows(output_rows - previous_rows).setZero();
2236 if (sample.node_ids.size() > 0)
2238 values.resize(sample.node_ids.size(), 1);
2239 for (
int i = 0; i < sample.node_ids.size(); ++i)
2241 const int node_id = sample.node_ids(i);
2242 if (node_id < 0 || node_id >= nodal.rows())
2244 values(i) = nodal(node_id);
2246 return sample.points.rows() == 0 || sample.points.rows() == values.rows();
2252 const bool export_growth_gradient =
2253 !options.fields.empty() && options.export_field(
"growth_gradient");
2254 if (options.export_field(
"growth") || export_growth_gradient)
2256 Eigen::MatrixXd values, gradients;
2257 if (sample_growth_scalar(growth, values, export_growth_gradient ? &gradients : nullptr))
2259 if (options.export_field(
"growth"))
2261 if (export_growth_gradient)
2272 if (stacked_form_ && options.export_field(
"growth_reaction"))
2274 Eigen::VectorXd full_grad;
2275 stacked_form_->first_derivative(stacked.col(0), full_grad);
2276 Eigen::MatrixXd reaction_nodal = full_grad.tail(growth_ndof());
2279 if (dissipation_form_)
2280 reaction_nodal -= dissipation_form_->weights();
2282 Eigen::MatrixXd values;
2283 if (sample_growth_scalar(reaction_nodal, values))
2288 if (dissipation_form_ && options.export_field(
"growth_multiplier"))
2290 const Eigen::MatrixXd mult = full_grad.tail(growth_ndof());
2291 if (sample_growth_scalar(mult, values))
2296 if (growth_law_.enabled &&
int(growth_pinned_mask_.size()) == growth_ndof()
2297 && options.export_field(
"growth_pinned"))
2299 Eigen::MatrixXd mask(growth_ndof(), 1);
2300 for (
int a = 0; a < growth_ndof(); ++a)
2301 mask(a) = growth_pinned_mask_[a] ? 1.0 : 0.0;
2302 Eigen::MatrixXd values;
2303 if (sample_growth_scalar(mask, values))
2307 if (growth_law_.enabled && has_element_samples && threshold_per_element_.size() == mesh_->n_elements())
2309 const auto per_element = [&](
const Eigen::VectorXd &data,
const std::string &name) {
2310 if (!options.export_field(name))
2312 Eigen::MatrixXd values = Eigen::MatrixXd::Zero(output_rows, 1);
2313 for (
int i = 0; i < sample.element_ids.size() && i < output_rows; ++i)
2314 if (sample.element_ids(i) >= 0)
2315 values(i) = data(sample.element_ids(i));
2318 per_element(threshold_per_element_,
"growth_threshold");
2319 if (shear_supply_.size() == mesh_->n_elements())
2320 per_element(shear_supply_,
"growth_shear_supply");
2321 if (threshold_parallel_.size() == mesh_->n_elements())
2322 per_element(threshold_parallel_,
"growth_threshold_parallel");
2323 if (threshold_clamped_.size() == mesh_->n_elements())
2324 per_element(threshold_clamped_,
"growth_clamped");
2325 if (lag_residual_.size() == mesh_->n_elements())
2326 per_element(lag_residual_,
"growth_lag_residual");
2327 if (attainment_.size() == mesh_->n_elements())
2328 per_element(attainment_,
"growth_attainment");
2329 if (dissipation_.size() == mesh_->n_elements())
2330 per_element(dissipation_,
"growth_dissipation");
2331 if (shear_work_.size() == mesh_->n_elements())
2332 per_element(shear_work_,
"growth_shear_supply_work");
2335 if (growth_law_.enabled && growth_activation_step_.size() == growth_ndof()
2336 && options.export_field(
"growth_activation_step"))
2338 const Eigen::MatrixXd steps = growth_activation_step_.cast<
double>();
2339 Eigen::MatrixXd values;
2340 if (sample_growth_scalar(steps, values))
2344 if (growthelastic_assembler_)
2345 append_material_fields(*growthelastic_assembler_);
ElementAssemblyValues vals
std::vector< Eigen::Triplet< double > > entries
#define POLYFEM_SCOPED_TIMER(...)
double characteristic_length() const
static std::shared_ptr< MixedNLAssembler > make_mixed_nl_assembler(const std::string &formulation)
static bool is_elastic_material(const std::string &material)
utility to check if material is one of the elastic materials
static std::shared_ptr< Assembler > make_assembler(const std::string &formulation)
void init(const bool is_volume, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const bool is_mass=false)
computes the basis evaluation and geometric mapping for each of the given ElementBases in bases initi...
void init_empty(const bool is_mass=false)
initialize an empty cache.
void compute(const int el_index, const bool is_volume, const basis::ElementBases &basis, const basis::ElementBases &gbasis, ElementAssemblyValues &vals) const
Copies cached values into vals, or computes into vals when the cache is empty.
stores per element basis values at given quadrature points and geometric mapping
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,...
Represents one basis function and its gradient.
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
static void interpolate_at_local_vals(const mesh::Mesh &mesh, const bool is_problem_scalar, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const int el_index, const Eigen::MatrixXd &local_pts, const Eigen::MatrixXd &fun, Eigen::MatrixXd &result, Eigen::MatrixXd &result_grad)
interpolate solution and gradient at element (calls interpolate_at_local_vals with sol)
void save_vtu(const std::string &path, const OutputSpace &space, const OutputFieldFunction &output_fields, const double t, const double dt, const ExportOptions &opts) const
saves the vtu file for time t
double assigning_rhs_time
time to computing the rhs
double assembling_mass_mat_time
time to assembly mass
double solving_time
time to solve
int n_flipped
number of flipped elements, compute only when using count_flipped_els (false by default)
json solver_info
information of the solver, eg num iteration, time, errors, etc the informations varies depending on t...
Eigen::Vector4d spectrum
spectrum of the stiffness matrix, enable only if POLYSOLVE_WITH_SPECTRA is ON (off by default)
void count_flipped_elements(const polyfem::mesh::Mesh &mesh, const std::vector< polyfem::basis::ElementBases > &gbases)
counts the number of flipped elements
void compute_errors(const int n_bases, const std::vector< polyfem::basis::ElementBases > &bases, const std::vector< polyfem::basis::ElementBases > &gbases, const polyfem::mesh::Mesh &mesh, const assembler::Problem &problem, const double tend, const Eigen::MatrixXd &sol)
compute errors
void compute_mesh_size(const polyfem::mesh::Mesh &mesh_in, const std::vector< polyfem::basis::ElementBases > &bases_in, const int n_samples, const bool use_curved_mesh_size)
computes the mesh size, it samples every edges n_samples times uses curved_mesh_size (false by defaul...
long long nn_zero
non zeros and sytem matrix size num dof is the total dof in the system
double mesh_size
max edge lenght
virtual std::string describe(const std::string &path) const =0
virtual std::unique_ptr< std::istream > open(const std::string &path, bool binary) const =0
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
int n_elements() const
utitlity to return the number of elements, cells or faces in 3d and 2d
virtual int n_vertices() const =0
number of vertices
virtual int get_body_id(const int primitive) const
Get the volume selection of an element (cell in 3d, face in 2d)
virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const =0
computes the bbox of the mesh
virtual bool is_volume() const =0
checks if mesh is volume
int dimension() const
utily for dimension
static void p_refine(const mesh::Mesh &mesh, const double B, const bool h1_formula, const int base_p, const int discr_order_max, io::OutStatsData &stats, Eigen::VectorXi &disc_orders)
compute a priori prefinement
void solve_reduced(NLProblem &nl_problem, Eigen::MatrixXd &sol, std::shared_ptr< polysolve::nonlinear::Solver > nl_solver)
std::function< void(const double)> post_subsolve
void solve_al(NLProblem &nl_problem, Eigen::MatrixXd &sol, std::shared_ptr< polysolve::nonlinear::Solver > nl_solver)
bool uses_lagging() const
bool is_residual() const override
virtual void init(const TVector &x0) override
double normalize_forms() override
void init_lagging(const TVector &x) override
std::shared_ptr< solver::NLProblem > nl_problem
std::vector< std::shared_ptr< solver::AugmentedLagrangianForm > > al_form
std::shared_ptr< time_integrator::ImplicitTimeIntegrator > time_integrator
void update_barrier_stiffness(const Eigen::VectorXd &x)
update the barrier stiffness for the forms
std::shared_ptr< assembler::RhsAssembler > rhs_assembler
Eigen::MatrixXd read_growth_cell_array(const io::ResourceIO &resources, const std::string &path, const std::string &field, const int ncomp_expected)
Mixed (displacement, growth) assembler implementing the correction energy of finite areal growth of a...
void prism_nodes_3d(const int p, const int q, Eigen::MatrixXd &val)
void p_nodes_3d(const int p, Eigen::MatrixXd &val)
void q_nodes_3d(const int q, Eigen::MatrixXd &val)
Eigen::SparseMatrix< double > lump_matrix(const Eigen::SparseMatrix< double > &M)
Lump each row of a matrix into the diagonal.
Eigen::SparseMatrix< double > sparse_identity(int rows, int cols)
std::vector< T > json_as_array(const json &j)
Return the value of a json object as an array.
Eigen::VectorXd flatten(const Eigen::MatrixXd &X)
Flatten rowwises.
spdlog::logger & logger()
Retrieves the current logger.
std::array< int, 2 > QuadratureOrders
double von_mises_stress_for_stress_tensor(const Eigen::MatrixXd &stress)
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::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
void log_and_throw_error(const std::string &msg)
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
bool export_field(const std::string &field) const
Eigen::VectorXi element_ids
Eigen::MatrixXd local_points