57 if (state.
args[
"time"][
"integrator"].is_string())
59 if (state.
args[
"time"][
"integrator"][
"type"] ==
"ImplicitEuler")
61 if (state.
args[
"time"][
"integrator"][
"type"] ==
"BDF")
62 return state.
args[
"time"][
"integrator"][
"steps"].get<
int>();
68 double dot(
const Eigen::MatrixXd &A,
const Eigen::MatrixXd &B) {
return (A.array() * B.array()).sum(); }
70 class LocalThreadScalarStorage
77 LocalThreadScalarStorage()
83 class LocalThreadVecStorage
90 LocalThreadVecStorage(
const int size)
100 T triangle_area(
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &
V)
102 Eigen::Matrix<T, Eigen::Dynamic, 1> l1 =
V.row(1) -
V.row(0);
103 Eigen::Matrix<T, Eigen::Dynamic, 1> l2 =
V.row(2) -
V.row(0);
104 T area = 0.5 * sqrt(pow(l1(1) * l2(2) - l1(2) * l2(1), 2) + pow(l1(0) * l2(2) - l1(2) * l2(0), 2) + pow(l1(1) * l2(0) - l1(0) * l2(1), 2));
108 Eigen::MatrixXd triangle_area_grad(
const Eigen::MatrixXd &
F)
111 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic> full_diff(
F.rows(),
F.cols());
112 for (
int i = 0; i <
F.rows(); i++)
113 for (
int j = 0; j <
F.cols(); j++)
114 full_diff(i, j) =
Diff(i + j *
F.rows(),
F(i, j));
117 Eigen::MatrixXd
grad(
F.rows(),
F.cols());
118 for (
int i = 0; i <
F.rows(); ++i)
119 for (
int j = 0; j <
F.cols(); ++j)
120 grad(i, j) = reduced_diff.getGradient()(i + j *
F.rows());
125 template <
typename T>
126 T line_length(
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &
V)
128 Eigen::Matrix<T, Eigen::Dynamic, 1> L =
V.row(1) -
V.row(0);
133 Eigen::MatrixXd line_length_grad(
const Eigen::MatrixXd &
F)
136 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic> full_diff(
F.rows(),
F.cols());
137 for (
int i = 0; i <
F.rows(); i++)
138 for (
int j = 0; j <
F.cols(); j++)
139 full_diff(i, j) =
Diff(i + j *
F.rows(),
F(i, j));
140 auto reduced_diff = line_length(full_diff);
142 Eigen::MatrixXd
grad(
F.rows(),
F.cols());
143 for (
int i = 0; i <
F.rows(); ++i)
144 for (
int j = 0; j <
F.cols(); ++j)
145 grad(i, j) = reduced_diff.getGradient()(i + j *
F.rows());
150 template <
typename T>
151 Eigen::Matrix<T, 2, 1> edge_normal(
const Eigen::Matrix<T, 4, 1> &
V)
153 Eigen::Matrix<T, 2, 1> v1 =
V.segment(0, 2);
154 Eigen::Matrix<T, 2, 1> v2 =
V.segment(2, 2);
155 Eigen::Matrix<T, 2, 1> normal = v1 - v2;
157 normal = normal / normal.norm();
161 template <
typename T>
162 Eigen::Matrix<T, 3, 1> face_normal(
const Eigen::Matrix<T, 9, 1> &
V)
164 Eigen::Matrix<T, 3, 1> v1 =
V.segment(0, 3);
165 Eigen::Matrix<T, 3, 1> v2 =
V.segment(3, 3);
166 Eigen::Matrix<T, 3, 1> v3 =
V.segment(6, 3);
167 Eigen::Matrix<T, 3, 1> normal = (v2 - v1).
cross(v3 - v1);
168 normal = normal / normal.norm();
172 Eigen::MatrixXd extract_lame_params(
const std::map<std::string, Assembler::ParamFunc> &lame_params,
const int e,
const int t,
const Eigen::MatrixXd &local_pts,
const Eigen::MatrixXd &pts)
174 Eigen::MatrixXd params = Eigen::MatrixXd::Zero(local_pts.rows(), 2);
176 auto search_lambda = lame_params.find(
"lambda");
177 auto search_mu = lame_params.find(
"mu");
179 if (search_lambda == lame_params.end() || search_mu == lame_params.end())
182 for (
int p = 0; p < local_pts.rows(); p++)
184 params(p, 0) = search_lambda->second(local_pts.row(p), pts.row(p), t, e);
185 params(p, 1) = search_mu->second(local_pts.row(p), pts.row(p), t, e);
195 const Eigen::MatrixXd &solution,
196 const std::set<int> &interested_ids,
200 const auto &bases = state.
bases;
203 const int dim = state.
mesh->dimension();
204 const int actual_dim = state.
problem->is_scalar() ? 1 : dim;
205 const int n_elements = int(bases.size());
206 const double t0 = state.
problem->is_time_dependent() ? state.
args[
"time"][
"t0"].get<
double>() : 0.0;
207 const double dt = state.
problem->is_time_dependent() ? state.
args[
"time"][
"dt"].get<
double>() : 0.0;
217 params.
t = dt * cur_step + t0;
218 params.
step = cur_step;
220 Eigen::MatrixXd u, grad_u;
221 Eigen::MatrixXd result;
223 for (
int e = start; e < end; ++e)
225 if (interested_ids.size() != 0 && interested_ids.find(state.
mesh->get_body_id(e)) == interested_ids.end())
241 local_storage.val += dot(result, local_storage.da);
244 for (
const LocalThreadScalarStorage &local_storage : storage)
245 integral += local_storage.val;
251 LocalThreadScalarStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
254 Eigen::MatrixXd points, normal;
255 Eigen::VectorXd weights;
257 Eigen::MatrixXd u, grad_u;
258 Eigen::MatrixXd result;
259 IntegrableFunctional::ParameterType params;
260 params.t = dt * cur_step + t0;
261 params.step = cur_step;
263 for (int lb_id = start; lb_id < end; ++lb_id)
265 const auto &lb = state.total_local_boundary[lb_id];
266 const int e = lb.element_id();
268 for (int i = 0; i < lb.size(); i++)
270 const int global_primitive_id = lb.global_primitive_id(i);
271 if (interested_ids.size() != 0 && interested_ids.find(state.mesh->get_boundary_id(global_primitive_id)) == interested_ids.end())
274 utils::BoundarySampler::boundary_quadrature(lb, state.n_boundary_samples(), *state.mesh, i, false, uv, points, normal, weights);
276 assembler::ElementAssemblyValues &vals = local_storage.vals;
277 vals.compute(e, state.mesh->is_volume(), points, bases[e], gbases[e]);
278 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim, vals, solution, u, grad_u);
280 const Eigen::MatrixXd lame_params = extract_lame_params(state.assembler->parameters(), e, params.t, points, vals.val);
283 params.body_id = state.mesh->get_body_id(e);
284 params.boundary_id = state.mesh->get_boundary_id(global_primitive_id);
285 j.evaluate(lame_params, points, vals.val, u, grad_u, normal, vals, params, result);
287 local_storage.val += dot(result, weights);
291 for (
const LocalThreadScalarStorage &local_storage : storage)
292 integral += local_storage.val;
296 std::vector<bool> traversed(state.
n_bases,
false);
298 params.
t = dt * cur_step + t0;
299 params.
step = cur_step;
300 for (
int e = 0; e < bases.size(); e++)
302 const auto &bs = bases[e];
303 for (
int i = 0; i < bs.bases.size(); i++)
305 const auto &b = bs.bases[i];
306 assert(b.global().size() == 1);
307 const auto &g = b.global()[0];
308 if (traversed[g.index])
311 const Eigen::MatrixXd lame_params = extract_lame_params(state.
assembler->parameters(), e, params.
t, Eigen::MatrixXd::Zero(1, dim) , g.node);
313 params.
node = g.index;
317 j.evaluate(lame_params, Eigen::MatrixXd::Zero(1, dim) , g.node, solution.block(g.index * dim, 0, dim, 1).transpose(), Eigen::MatrixXd::Zero(1, dim * actual_dim) , Eigen::MatrixXd::Zero(0, 0) ,
assembler::ElementAssemblyValues(), params,
val);
319 traversed[g.index] =
true;
327 void AdjointTools::compute_shape_derivative_functional_term(
329 const Eigen::MatrixXd &solution,
331 const std::set<int> &interested_ids,
333 Eigen::VectorXd &term,
334 const int cur_time_step)
337 const auto &bases = state.
bases;
338 const int dim = state.
mesh->dimension();
339 const int actual_dim = state.
problem->is_scalar() ? 1 : dim;
340 const double t0 = state.
problem->is_time_dependent() ? state.
args[
"time"][
"t0"].get<
double>() : 0.0;
341 const double dt = state.
problem->is_time_dependent() ? state.
args[
"time"][
"dt"].get<
double>() : 0.0;
343 const int n_elements = int(bases.size());
346 auto storage = utils::create_thread_storage(LocalThreadVecStorage(term.size()));
348 if (spatial_integral_type == SpatialIntegralType::Volume)
350 utils::maybe_parallel_for(n_elements, [&](
int start,
int end,
int thread_id) {
351 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
353 Eigen::MatrixXd u, grad_u, j_val, dj_dgradu, dj_dx;
356 params.
t = cur_time_step * dt + t0;
357 params.
step = cur_time_step;
359 for (
int e = start; e < end; ++e)
361 if (interested_ids.size() != 0 && interested_ids.find(state.
mesh->get_body_id(e)) == interested_ids.end())
366 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim,
vals, solution, u, grad_u);
387 Eigen::MatrixXd tau_q, grad_u_q;
388 for (
auto &v :
gvals.basis_values)
390 for (
int q = 0; q < local_storage.da.size(); ++q)
392 local_storage.vec.block(v.global[0].index * dim, 0, dim, 1) += (j_val(q) * local_storage.da(q)) * v.grad_t_m.row(q).transpose();
395 local_storage.vec.block(v.global[0].index * dim, 0, dim, 1) += (v.val(q) * local_storage.da(q)) * dj_dx.row(q).transpose();
399 if (dim == actual_dim)
406 tau_q = dj_dgradu.row(q);
407 grad_u_q = grad_u.row(q);
409 for (
int d = 0; d < dim; d++)
410 local_storage.vec(v.global[0].index * dim + d) += -dot(tau_q, grad_u_q.col(d) * v.grad_t_m.row(q)) * local_storage.da(q);
417 else if (spatial_integral_type == SpatialIntegralType::Surface)
419 utils::maybe_parallel_for(state.
total_local_boundary.size(), [&](
int start,
int end,
int thread_id) {
420 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
422 Eigen::MatrixXd uv, points, normal;
423 Eigen::VectorXd &weights = local_storage.da;
425 Eigen::MatrixXd u, grad_u, x, grad_x, j_val, dj_dgradu, dj_dgradx, dj_dx;
427 IntegrableFunctional::ParameterType params;
428 params.t = cur_time_step * dt + t0;
429 params.step = cur_time_step;
431 for (int lb_id = start; lb_id < end; ++lb_id)
433 const auto &lb = state.total_local_boundary[lb_id];
434 const int e = lb.element_id();
436 for (int i = 0; i < lb.size(); i++)
438 const int global_primitive_id = lb.global_primitive_id(i);
439 if (interested_ids.size() != 0 && interested_ids.find(state.mesh->get_boundary_id(global_primitive_id)) == interested_ids.end())
442 utils::BoundarySampler::boundary_quadrature(lb, state.n_boundary_samples(), *state.mesh, i, false, uv, points, normal, weights);
444 assembler::ElementAssemblyValues &vals = local_storage.vals;
445 io::Evaluator::interpolate_at_local_vals(*state.mesh, state.problem->is_scalar(), bases, gbases, e, points, solution, u, grad_u);
448 vals.compute(e, state.mesh->is_volume(), points, gbases[e], gbases[e]);
452 const int n_loc_bases_ = int(vals.basis_values.size());
454 const Eigen::MatrixXd lame_params = extract_lame_params(state.assembler->parameters(), e, params.t, points, vals.val);
457 params.body_id = state.mesh->get_body_id(e);
458 params.boundary_id = state.mesh->get_boundary_id(global_primitive_id);
460 j.evaluate(lame_params, points, vals.val, u, grad_u, normal, vals, params, j_val);
461 j_val = j_val.array().colwise() * weights.array();
463 if (j.depend_on_gradu())
465 j.dj_dgradu(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradu);
466 dj_dgradu = dj_dgradu.array().colwise() * weights.array();
469 if (j.depend_on_gradx())
471 j.dj_dgradx(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradx);
472 dj_dgradx = dj_dgradx.array().colwise() * weights.array();
477 j.dj_dx(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dx);
478 dj_dx = dj_dx.array().colwise() * weights.array();
481 const auto nodes = gbases[e].local_nodes_for_primitive(lb.global_primitive_id(i), *state.mesh);
483 if (nodes.size() != dim)
484 log_and_throw_adjoint_error(
"Only linear geometry is supported in differentiable surface integral functional!");
486 Eigen::MatrixXd velocity_div_mat;
487 if (state.mesh->is_volume())
490 for (int d = 0; d < 3; d++)
491 V.row(d) = gbases[e].bases[nodes(d)].global()[0].node;
492 velocity_div_mat = face_velocity_divergence(V);
497 for (int d = 0; d < 2; d++)
498 V.row(d) = gbases[e].bases[nodes(d)].global()[0].node;
499 velocity_div_mat = edge_velocity_divergence(V);
502 Eigen::MatrixXd grad_u_q, tau_q, grad_x_q;
503 for (long n = 0; n < nodes.size(); ++n)
505 const assembler::AssemblyValues &v = vals.basis_values[nodes(n)];
507 local_storage.vec.block(v.global[0].index * dim, 0, dim, 1) += j_val.sum() * velocity_div_mat.row(n).transpose();
510 for (long n = 0; n < n_loc_bases_; ++n)
512 const assembler::AssemblyValues &v = vals.basis_values[n];
515 local_storage.vec.block(v.global[0].index * dim, 0, dim, 1) += dj_dx.transpose() * v.val;
518 if (j.depend_on_gradu())
520 for (int q = 0; q < weights.size(); ++q)
522 if (dim == actual_dim)
524 vector2matrix(grad_u.row(q), grad_u_q);
525 vector2matrix(dj_dgradu.row(q), tau_q);
529 grad_u_q = grad_u.row(q);
530 tau_q = dj_dgradu.row(q);
533 for (int d = 0; d < dim; d++)
534 local_storage.vec(v.global[0].index * dim + d) += -dot(tau_q, grad_u_q.col(d) * v.grad_t_m.row(q));
538 if (j.depend_on_gradx())
540 for (int d = 0; d < dim; d++)
542 for (int q = 0; q < weights.size(); ++q)
543 local_storage.vec(v.global[0].index * dim + d) += dot(dj_dgradx.block(q, d * dim, 1, dim), v.grad.row(q));
551 else if (spatial_integral_type == SpatialIntegralType::VertexSum)
555 for (
const LocalThreadVecStorage &local_storage : storage)
556 term += local_storage.
vec;
558 term = utils::flatten(utils::unflatten(term, dim)(state.
primitive_to_node(), Eigen::all));
561 void AdjointTools::dJ_shape_static_adjoint_term(
563 const Eigen::MatrixXd &sol,
564 const Eigen::MatrixXd &adjoint,
565 Eigen::VectorXd &one_form)
567 Eigen::VectorXd elasticity_term, rhs_term, pressure_term, contact_term, adhesion_term;
570 Eigen::MatrixXd adjoint_zeroed = adjoint;
579 rhs_term.setZero(one_form.size());
587 pressure_term.setZero(one_form.size());
593 BarrierContactForceDerivative::force_shape_derivative(*barrier_contact, state.
diff_cached.
collision_set(0), sol, adjoint_zeroed, contact_term);
603 contact_term.setZero(elasticity_term.size());
612 adhesion_term.setZero(elasticity_term.size());
616 one_form -= elasticity_term + rhs_term + pressure_term + contact_term + adhesion_term;
617 one_form = utils::flatten(utils::unflatten(one_form, state.
mesh->dimension())(state.
primitive_to_node(), Eigen::all));
620 void AdjointTools::dJ_shape_homogenization_adjoint_term(
622 const Eigen::MatrixXd &sol,
623 const Eigen::MatrixXd &adjoint,
624 Eigen::VectorXd &one_form)
626 Eigen::VectorXd elasticity_term, contact_term, adhesion_term;
628 std::shared_ptr<NLHomoProblem> homo_problem = std::dynamic_pointer_cast<NLHomoProblem>(state.
solve_data.
nl_problem);
629 assert(homo_problem);
631 const int dim = state.
mesh->dimension();
634 const Eigen::MatrixXd affine_adjoint = homo_problem->reduced_to_disp_grad(adjoint,
true);
635 const Eigen::VectorXd full_adjoint = homo_problem->NLProblem::reduced_to_full(adjoint.topRows(homo_problem->reduced_size())) + io::Evaluator::generate_linear_field(state.
n_bases, state.
mesh_nodes, affine_adjoint);
643 BarrierContactForceDerivative::force_shape_derivative(*barrier_contact, state.
diff_cached.
collision_set(0), sol, full_adjoint, contact_term);
653 contact_term.setZero(elasticity_term.size());
662 adhesion_term.setZero(elasticity_term.size());
665 one_form = -(elasticity_term + contact_term + adhesion_term);
667 Eigen::VectorXd force;
668 homo_problem->FullNLProblem::gradient(sol, force);
671 one_form = utils::flatten(utils::unflatten(one_form, dim)(state.
primitive_to_node(), Eigen::all));
674 void AdjointTools::dJ_periodic_shape_adjoint_term(
677 const Eigen::VectorXd &periodic_mesh_representation,
678 const Eigen::MatrixXd &sol,
679 const Eigen::MatrixXd &adjoint,
680 Eigen::VectorXd &one_form)
682 std::shared_ptr<NLHomoProblem> homo_problem = std::dynamic_pointer_cast<NLHomoProblem>(state.
solve_data.
nl_problem);
683 assert(homo_problem);
685 const Eigen::MatrixXd reduced_sol = homo_problem->full_to_reduced(sol, state.
diff_cached.
disp_grad());
686 const Eigen::VectorXd extended_sol = homo_problem->reduced_to_extended(reduced_sol);
688 const Eigen::VectorXd extended_adjoint = homo_problem->reduced_to_extended(adjoint,
true);
689 const Eigen::MatrixXd affine_adjoint = homo_problem->reduced_to_disp_grad(adjoint,
true);
690 const Eigen::VectorXd full_adjoint = homo_problem->NLProblem::reduced_to_full(adjoint.topRows(homo_problem->reduced_size())) + io::Evaluator::generate_linear_field(state.
n_bases, state.
mesh_nodes, affine_adjoint);
692 const int dim = state.
mesh->dimension();
697 homo_problem->set_project_to_psd(
false);
698 homo_problem->FullNLProblem::hessian(sol, hessian);
699 Eigen::VectorXd partial_term = full_adjoint.transpose() * hessian;
701 one_form -= utils::flatten(utils::unflatten(partial_term, dim)(state.
primitive_to_node(), Eigen::all));
703 one_form = periodic_mesh_map.
apply_jacobian(one_form, periodic_mesh_representation);
707 Eigen::VectorXd contact_term;
710 one_form -= contact_term;
714 void AdjointTools::dJ_shape_transient_adjoint_term(
716 const Eigen::MatrixXd &adjoint_nu,
717 const Eigen::MatrixXd &adjoint_p,
718 Eigen::VectorXd &one_form)
720 const double t0 = state.
args[
"time"][
"t0"];
721 const double dt = state.
args[
"time"][
"dt"];
722 const int time_steps = state.
args[
"time"][
"time_steps"];
723 const int bdf_order = get_bdf_order(state);
725 Eigen::VectorXd elasticity_term, rhs_term, pressure_term, damping_term, mass_term, contact_term, friction_term, adhesion_term, tangential_adhesion_term;
728 Eigen::VectorXd cur_p, cur_nu;
729 for (
int i = time_steps; i > 0; --i)
731 const int real_order = std::min(bdf_order, i);
732 double beta = time_integrator::BDF::betas(real_order - 1);
733 double beta_dt = beta * dt;
734 const double t = i * dt + t0;
738 cur_p = adjoint_p.col(i);
739 cur_nu = adjoint_nu.col(i);
744 InertiaForceDerivative::force_shape_derivative(*state.
solve_data.
inertia_form, state.
mesh->is_volume(), state.
n_geom_bases, t, state.
bases, state.
geom_bases(), *(state.
mass_matrix_assembler), state.
mass_ass_vals_cache, velocity, cur_nu, mass_term);
753 damping_term.setZero(mass_term.size());
769 contact_term.setZero(mass_term.size());
778 friction_term.setZero(mass_term.size());
787 adhesion_term.setZero(mass_term.size());
797 tangential_adhesion_term.setZero(mass_term.size());
800 one_form += beta_dt * (elasticity_term + rhs_term + pressure_term + damping_term + contact_term + friction_term + mass_term + adhesion_term + tangential_adhesion_term);
804 Eigen::VectorXd sum_alpha_p;
806 sum_alpha_p.setZero(adjoint_p.rows());
807 int num = std::min(bdf_order, time_steps);
808 for (
int j = 0; j < num; ++j)
810 int order = std::min(bdf_order - 1, j);
811 sum_alpha_p -= time_integrator::BDF::alphas(order)[j] * adjoint_p.col(j + 1);
815 InertiaForceDerivative::force_shape_derivative(*state.
solve_data.
inertia_form, state.
mesh->is_volume(), state.
n_geom_bases, t0, state.
bases, state.
geom_bases(), *(state.
mass_matrix_assembler), state.
mass_ass_vals_cache, state.
diff_cached.
v(0), sum_alpha_p, mass_term);
817 one_form += mass_term;
819 one_form = utils::flatten(utils::unflatten(one_form, state.
mesh->dimension())(state.
primitive_to_node(), Eigen::all));
822 void AdjointTools::dJ_material_static_adjoint_term(
824 const Eigen::MatrixXd &sol,
825 const Eigen::MatrixXd &adjoint,
826 Eigen::VectorXd &one_form)
828 Eigen::MatrixXd adjoint_zeroed = adjoint;
830 ElasticForceDerivative::force_material_derivative(*state.
solve_data.
elastic_form, 0, sol, sol, adjoint_zeroed, one_form);
833 void AdjointTools::dJ_material_transient_adjoint_term(
835 const Eigen::MatrixXd &adjoint_nu,
836 const Eigen::MatrixXd &adjoint_p,
837 Eigen::VectorXd &one_form)
839 const double t0 = state.
args[
"time"][
"t0"];
840 const double dt = state.
args[
"time"][
"dt"];
841 const int time_steps = state.
args[
"time"][
"time_steps"];
842 const int bdf_order = get_bdf_order(state);
844 one_form.setZero(state.
bases.size() * 2);
846 auto storage = utils::create_thread_storage(LocalThreadVecStorage(one_form.size()));
848 utils::maybe_parallel_for(time_steps, [&](
int start,
int end,
int thread_id) {
849 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
850 Eigen::VectorXd elasticity_term;
851 for (
int i_aux = start; i_aux < end; ++i_aux)
853 const int i = time_steps - i_aux;
854 const int real_order = std::min(bdf_order, i);
855 double beta_dt = time_integrator::BDF::betas(real_order - 1) * dt;
857 Eigen::VectorXd cur_p = adjoint_p.col(i);
861 local_storage.vec += beta_dt * elasticity_term;
865 for (
const LocalThreadVecStorage &local_storage : storage)
866 one_form += local_storage.vec;
869 void AdjointTools::dJ_friction_transient_adjoint_term(
871 const Eigen::MatrixXd &adjoint_nu,
872 const Eigen::MatrixXd &adjoint_p,
873 Eigen::VectorXd &one_form)
875 const double dt = state.
args[
"time"][
"dt"];
877 const int time_steps = state.
args[
"time"][
"time_steps"];
878 const int dim = state.
mesh->dimension();
879 const int bdf_order = get_bdf_order(state);
883 std::shared_ptr<time_integrator::ImplicitTimeIntegrator> time_integrator =
884 time_integrator::ImplicitTimeIntegrator::construct_time_integrator(state.
args[
"time"][
"integrator"]);
886 Eigen::MatrixXd solution, velocity, acceleration;
892 const double dt = state.
args[
"time"][
"dt"];
893 time_integrator->init(solution, velocity, acceleration, dt);
896 for (
int t = 1; t <= time_steps; ++t)
898 const int real_order = std::min(bdf_order, t);
899 double beta = time_integrator::BDF::betas(real_order - 1);
901 const Eigen::MatrixXd surface_solution_prev = state.
collision_mesh.vertices(utils::unflatten(state.
diff_cached.
u(t - 1), dim));
905 time_integrator->update_quantities(state.
diff_cached.
u(t));
914 surface_solution_prev,
916 barrier_contact->barrier_potential(),
917 barrier_contact->barrier_stiffness(),
920 Eigen::VectorXd cur_p = adjoint_p.col(t);
923 one_form(0) += dot(cur_p, force) * beta * dt;
928 void AdjointTools::dJ_damping_transient_adjoint_term(
930 const Eigen::MatrixXd &adjoint_nu,
931 const Eigen::MatrixXd &adjoint_p,
932 Eigen::VectorXd &one_form)
934 const double t0 = state.
args[
"time"][
"t0"];
935 const double dt = state.
args[
"time"][
"dt"];
936 const int time_steps = state.
args[
"time"][
"time_steps"];
937 const int bdf_order = get_bdf_order(state);
941 auto storage = utils::create_thread_storage(LocalThreadVecStorage(one_form.size()));
943 utils::maybe_parallel_for(time_steps, [&](
int start,
int end,
int thread_id) {
944 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
945 Eigen::VectorXd damping_term;
946 for (
int t_aux = start; t_aux < end; ++t_aux)
948 const int t = time_steps - t_aux;
949 const int real_order = std::min(bdf_order, t);
950 const double beta = time_integrator::BDF::betas(real_order - 1);
952 Eigen::VectorXd cur_p = adjoint_p.col(t);
956 local_storage.vec += (beta * dt) * damping_term;
960 for (
const LocalThreadVecStorage &local_storage : storage)
961 one_form += local_storage.vec;
964 void AdjointTools::dJ_initial_condition_adjoint_term(
966 const Eigen::MatrixXd &adjoint_nu,
967 const Eigen::MatrixXd &adjoint_p,
968 Eigen::VectorXd &one_form)
970 const int ndof = state.
ndof();
971 one_form.setZero(ndof * 2);
974 one_form.segment(0, ndof) = -adjoint_nu.col(0);
975 one_form.segment(ndof, ndof) = -adjoint_p.col(0);
980 one_form(ndof + b) = 0;
984 void AdjointTools::dJ_dirichlet_static_adjoint_term(
986 const Eigen::MatrixXd &adjoint,
987 Eigen::VectorXd &one_form)
992 gradd_h.prune([&boundary_nodes_set](
const Eigen::Index &row,
const Eigen::Index &col,
const FullNLProblem::Scalar &value) {
995 if (boundary_nodes_set.find(row) == boundary_nodes_set.end())
999 one_form.setZero(state.
ndof());
1002 one_form = utils::flatten(utils::unflatten(one_form, state.
mesh->dimension())(state.
primitive_to_node(), Eigen::all));
1005 void AdjointTools::dJ_dirichlet_transient_adjoint_term(
1007 const Eigen::MatrixXd &adjoint_nu,
1008 const Eigen::MatrixXd &adjoint_p,
1009 Eigen::VectorXd &one_form)
1011 const double dt = state.
args[
"time"][
"dt"];
1012 const int time_steps = state.
args[
"time"][
"time_steps"];
1013 const int bdf_order = get_bdf_order(state);
1018 one_form.setZero(time_steps * n_dirichlet_dof);
1019 for (
int i = 1; i <= time_steps; ++i)
1021 const int real_order = std::min(bdf_order, i);
1022 const double beta_dt = time_integrator::BDF::betas(real_order - 1) * dt;
1024 one_form.segment((i - 1) * n_dirichlet_dof, n_dirichlet_dof) = -(1. / beta_dt) * adjoint_p(state.
boundary_nodes, i);
1028 void AdjointTools::dJ_pressure_static_adjoint_term(
1030 const std::vector<int> &boundary_ids,
1031 const Eigen::MatrixXd &sol,
1032 const Eigen::MatrixXd &adjoint,
1033 Eigen::VectorXd &one_form)
1035 const int n_pressure_dof = boundary_ids.size();
1037 one_form.setZero(n_pressure_dof);
1039 for (
int i = 0; i < boundary_ids.size(); ++i)
1041 double pressure_term = PressureForceDerivative::force_pressure_derivative(
1048 one_form(i) = pressure_term;
1052 void AdjointTools::dJ_pressure_transient_adjoint_term(
1054 const std::vector<int> &boundary_ids,
1055 const Eigen::MatrixXd &adjoint_nu,
1056 const Eigen::MatrixXd &adjoint_p,
1057 Eigen::VectorXd &one_form)
1059 const double t0 = state.
args[
"time"][
"t0"];
1060 const double dt = state.
args[
"time"][
"dt"];
1061 const int time_steps = state.
args[
"time"][
"time_steps"];
1062 const int bdf_order = get_bdf_order(state);
1064 const int n_pressure_dof = boundary_ids.size();
1066 one_form.setZero(time_steps * n_pressure_dof);
1067 Eigen::VectorXd cur_p, cur_nu;
1068 for (
int i = time_steps; i > 0; --i)
1070 const int real_order = std::min(bdf_order, i);
1071 double beta = time_integrator::BDF::betas(real_order - 1);
1072 double beta_dt = beta * dt;
1073 const double t = i * dt + t0;
1075 cur_p = adjoint_p.col(i);
1076 cur_nu = adjoint_nu.col(i);
1080 for (
int b = 0; b < boundary_ids.size(); ++b)
1082 double pressure_term = PressureForceDerivative::force_pressure_derivative(
1089 one_form((i - 1) * n_pressure_dof + b) = -beta_dt * pressure_term;
1094 void AdjointTools::dJ_du_step(
1097 const Eigen::MatrixXd &solution,
1098 const std::set<int> &interested_ids,
1101 Eigen::VectorXd &term)
1103 const auto &bases = state.
bases;
1106 const int dim = state.
mesh->dimension();
1107 const int actual_dim = state.
problem->is_scalar() ? 1 : dim;
1108 const int n_elements = int(bases.size());
1109 const double t0 = state.
problem->is_time_dependent() ? state.
args[
"time"][
"t0"].get<
double>() : 0.0;
1110 const double dt = state.
problem->is_time_dependent() ? state.
args[
"time"][
"dt"].get<
double>() : 0.0;
1112 term = Eigen::MatrixXd::Zero(state.
n_bases * actual_dim, 1);
1117 if (spatial_integral_type == SpatialIntegralType::Volume)
1119 auto storage = utils::create_thread_storage(LocalThreadVecStorage(term.size()));
1120 utils::maybe_parallel_for(n_elements, [&](
int start,
int end,
int thread_id) {
1121 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
1123 Eigen::MatrixXd u, grad_u;
1124 Eigen::MatrixXd lambda, mu;
1125 Eigen::MatrixXd dj_du, dj_dgradu, dj_dgradx;
1128 params.
t = dt * cur_step + t0;
1129 params.
step = cur_step;
1131 for (
int e = start; e < end; ++e)
1133 if (interested_ids.size() != 0 && interested_ids.find(state.
mesh->get_body_id(e)) == interested_ids.end())
1144 const int n_loc_bases_ = int(
vals.basis_values.size());
1146 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim,
vals, solution, u, grad_u);
1151 dj_dgradu.resize(0, 0);
1155 for (
int q = 0; q < dj_dgradu.rows(); q++)
1156 dj_dgradu.row(q) *= local_storage.da(q);
1163 for (
int q = 0; q < dj_du.rows(); q++)
1164 dj_du.row(q) *= local_storage.da(q);
1167 for (
int i = 0; i < n_loc_bases_; ++i)
1170 assert(v.
global.size() == 1);
1171 for (
int d = 0; d < actual_dim; d++)
1178 for (
int q = 0; q < local_storage.da.size(); ++q)
1179 val += dot(dj_dgradu.block(q, d * dim, 1, dim), v.
grad_t_m.row(q));
1185 for (
int q = 0; q < local_storage.da.size(); ++q)
1186 val += dj_du(q, d) * v.
val(q);
1188 local_storage.vec(v.
global[0].index * actual_dim + d) +=
val;
1193 for (
const LocalThreadVecStorage &local_storage : storage)
1194 term += local_storage.vec;
1196 else if (spatial_integral_type == SpatialIntegralType::Surface)
1198 auto storage = utils::create_thread_storage(LocalThreadVecStorage(term.size()));
1199 utils::maybe_parallel_for(state.
total_local_boundary.size(), [&](
int start,
int end,
int thread_id) {
1200 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
1202 Eigen::MatrixXd uv, samples, gtmp;
1203 Eigen::MatrixXd points, normal;
1204 Eigen::VectorXd weights;
1206 Eigen::MatrixXd u, grad_u;
1207 Eigen::MatrixXd lambda, mu;
1208 Eigen::MatrixXd dj_du, dj_dgradu, dj_dgradu_local;
1210 IntegrableFunctional::ParameterType params;
1211 params.t = dt * cur_step + t0;
1212 params.step = cur_step;
1214 for (int lb_id = start; lb_id < end; ++lb_id)
1216 const auto &lb = state.total_local_boundary[lb_id];
1217 const int e = lb.element_id();
1219 for (int i = 0; i < lb.size(); i++)
1221 const int global_primitive_id = lb.global_primitive_id(i);
1222 if (interested_ids.size() != 0 && interested_ids.find(state.mesh->get_boundary_id(global_primitive_id)) == interested_ids.end())
1225 utils::BoundarySampler::boundary_quadrature(lb, state.n_boundary_samples(), *state.mesh, i, false, uv, points, normal, weights);
1227 assembler::ElementAssemblyValues &vals = local_storage.vals;
1228 vals.compute(e, state.mesh->is_volume(), points, bases[e], gbases[e]);
1229 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim, vals, solution, u, grad_u);
1231 const Eigen::MatrixXd lame_params = extract_lame_params(state.assembler->parameters(), e, params.t, points, vals.val);
1235 const int n_loc_bases_ = int(vals.basis_values.size());
1238 params.body_id = state.mesh->get_body_id(e);
1239 params.boundary_id = state.mesh->get_boundary_id(global_primitive_id);
1241 dj_dgradu.resize(0, 0);
1242 if (j.depend_on_gradu())
1244 j.dj_dgradu(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradu);
1245 for (int q = 0; q < dj_dgradu.rows(); q++)
1246 dj_dgradu.row(q) *= weights(q);
1249 dj_dgradu_local.resize(0, 0);
1250 if (j.depend_on_gradu_local())
1252 j.dj_dgradu_local(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradu_local);
1253 for (int q = 0; q < dj_dgradu_local.rows(); q++)
1254 dj_dgradu_local.row(q) *= weights(q);
1258 if (j.depend_on_u())
1260 j.dj_du(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_du);
1261 for (int q = 0; q < dj_du.rows(); q++)
1262 dj_du.row(q) *= weights(q);
1265 for (int l = 0; l < lb.size(); ++l)
1267 const auto nodes = bases[e].local_nodes_for_primitive(lb.global_primitive_id(l), *state.mesh);
1269 for (long n = 0; n < nodes.size(); ++n)
1271 const assembler::AssemblyValues &v = vals.basis_values[nodes(n)];
1272 assert(v.global.size() == 1);
1273 for (int d = 0; d < actual_dim; d++)
1278 if (j.depend_on_gradu())
1280 for (int q = 0; q < weights.size(); ++q)
1281 val += dot(dj_dgradu.block(q, d * dim, 1, dim), v.grad_t_m.row(q));
1284 if (j.depend_on_gradu_local())
1286 for (int q = 0; q < weights.size(); ++q)
1287 val += dot(dj_dgradu_local.block(q, d * dim, 1, dim), v.grad.row(q));
1290 if (j.depend_on_u())
1292 for (int q = 0; q < weights.size(); ++q)
1293 val += dj_du(q, d) * v.val(q);
1295 local_storage.vec(v.global[0].index * actual_dim + d) += val;
1302 for (
const LocalThreadVecStorage &local_storage : storage)
1303 term += local_storage.vec;
1305 else if (spatial_integral_type == SpatialIntegralType::VertexSum)
1307 std::vector<bool> traversed(state.
n_bases,
false);
1309 params.
t = dt * cur_step + t0;
1310 params.
step = cur_step;
1311 for (
int e = 0; e < bases.size(); e++)
1313 const auto &bs = bases[e];
1314 for (
int i = 0; i < bs.bases.size(); i++)
1316 const auto &b = bs.bases[i];
1317 assert(b.global().size() == 1);
1318 const auto &g = b.global()[0];
1319 if (traversed[g.index])
1322 const Eigen::MatrixXd lame_params = extract_lame_params(state.
assembler->parameters(), e, params.
t, Eigen::MatrixXd::Zero(1, dim) , g.node);
1324 params.
node = g.index;
1327 Eigen::MatrixXd
val;
1328 j.dj_du(lame_params, Eigen::MatrixXd::Zero(1, dim) , g.node, solution.block(g.index * dim, 0, dim, 1).transpose(), Eigen::MatrixXd::Zero(1, dim * actual_dim) , Eigen::MatrixXd::Zero(0, 0) ,
assembler::ElementAssemblyValues(), params,
val);
1329 term.block(g.index * actual_dim, 0, actual_dim, 1) +=
val.transpose();
1330 traversed[g.index] =
true;
1336 Eigen::VectorXd AdjointTools::map_primitive_to_node_order(
const State &state,
const Eigen::VectorXd &primitives)
1338 int dim = state.
mesh->dimension();
1339 assert(primitives.size() == (state.
n_geom_bases * dim));
1340 Eigen::VectorXd nodes(primitives.size());
1343 nodes.segment(map[v] * dim, dim) = primitives.segment(v * dim, dim);
1347 Eigen::VectorXd AdjointTools::map_node_to_primitive_order(
const State &state,
const Eigen::VectorXd &nodes)
1349 int dim = state.
mesh->dimension();
1351 Eigen::VectorXd primitives(nodes.size());
1354 primitives.segment(map[v] * dim, dim) = nodes.segment(v * dim, dim);
1358 Eigen::MatrixXd AdjointTools::edge_normal_gradient(
const Eigen::MatrixXd &
V)
1361 Eigen::Matrix<Diff, 4, 1> full_diff(4, 1);
1362 for (
int i = 0; i < 2; i++)
1363 for (
int j = 0; j < 2; j++)
1364 full_diff(i * 2 + j) =
Diff(i * 2 + j,
V(i, j));
1365 auto reduced_diff = edge_normal(full_diff);
1367 Eigen::MatrixXd grad(2, 4);
1368 for (
int i = 0; i < 2; ++i)
1369 grad.row(i) = reduced_diff[i].getGradient();
1374 Eigen::MatrixXd AdjointTools::face_normal_gradient(
const Eigen::MatrixXd &
V)
1377 Eigen::Matrix<Diff, 9, 1> full_diff(9, 1);
1378 for (
int i = 0; i < 3; i++)
1379 for (
int j = 0; j < 3; j++)
1380 full_diff(i * 3 + j) =
Diff(i * 3 + j,
V(i, j));
1381 auto reduced_diff = face_normal(full_diff);
1383 Eigen::MatrixXd grad(3, 9);
1384 for (
int i = 0; i < 3; ++i)
1385 grad.row(i) = reduced_diff[i].getGradient();
1390 Eigen::MatrixXd AdjointTools::edge_velocity_divergence(
const Eigen::MatrixXd &
V)
1392 return line_length_grad(
V) / line_length<double>(
V);
1395 Eigen::MatrixXd AdjointTools::face_velocity_divergence(
const Eigen::MatrixXd &
V)
1397 return triangle_area_grad(
V) / triangle_area<double>(
V);
1400 void AdjointTools::scaled_jacobian(
const Eigen::MatrixXd &
V,
const Eigen::MatrixXi &F, Eigen::VectorXd &quality)
1402 const int dim = F.cols() - 1;
1404 quality.setZero(F.rows());
1407 for (
int i = 0; i < F.rows(); i++)
1409 Eigen::RowVector3d e0;
1411 e0.head(2) =
V.row(F(i, 2)) -
V.row(F(i, 1));
1412 Eigen::RowVector3d e1;
1414 e1.head(2) =
V.row(F(i, 0)) -
V.row(F(i, 2));
1415 Eigen::RowVector3d e2;
1417 e2.head(2) =
V.row(F(i, 1)) -
V.row(F(i, 0));
1419 double l0 = e0.norm();
1420 double l1 = e1.norm();
1421 double l2 = e2.norm();
1423 double A = 0.5 * (e0.cross(e1)).norm();
1424 double Lmax = std::max(l0 * l1, std::max(l1 * l2, l0 * l2));
1426 quality(i) = 2 * A * (2 / sqrt(3)) / Lmax;
1431 for (
int i = 0; i < F.rows(); i++)
1433 Eigen::RowVector3d e0 =
V.row(F(i, 1)) -
V.row(F(i, 0));
1434 Eigen::RowVector3d e1 =
V.row(F(i, 2)) -
V.row(F(i, 1));
1435 Eigen::RowVector3d e2 =
V.row(F(i, 0)) -
V.row(F(i, 2));
1436 Eigen::RowVector3d e3 =
V.row(F(i, 3)) -
V.row(F(i, 0));
1437 Eigen::RowVector3d e4 =
V.row(F(i, 3)) -
V.row(F(i, 1));
1438 Eigen::RowVector3d e5 =
V.row(F(i, 3)) -
V.row(F(i, 2));
1440 double l0 = e0.norm();
1441 double l1 = e1.norm();
1442 double l2 = e2.norm();
1443 double l3 = e3.norm();
1444 double l4 = e4.norm();
1445 double l5 = e5.norm();
1447 double J = std::abs((e0.cross(e3)).dot(e2));
1449 double a1 = l0 * l2 * l3;
1450 double a2 = l0 * l1 * l4;
1451 double a3 = l1 * l2 * l5;
1452 double a4 = l3 * l4 * l5;
1454 double a = std::max({a1, a2, a3, a4, J});
1455 quality(i) = J * sqrt(2) / a;
ElementAssemblyValues vals
assembler::ElementAssemblyValues gvals
bool depend_on_gradu_local() const
void dj_du(const Eigen::MatrixXd &elastic_params, const Eigen::MatrixXd &local_pts, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &u, const Eigen::MatrixXd &grad_u, const Eigen::MatrixXd &reference_normals, const assembler::ElementAssemblyValues &vals, ParameterType ¶ms, Eigen::MatrixXd &val) const
bool depend_on_gradu() const
void dj_dgradu(const Eigen::MatrixXd &elastic_params, const Eigen::MatrixXd &local_pts, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &u, const Eigen::MatrixXd &grad_u, const Eigen::MatrixXd &reference_normals, const assembler::ElementAssemblyValues &vals, ParameterType ¶ms, Eigen::MatrixXd &val) const
void evaluate(const Eigen::MatrixXd &elastic_params, const Eigen::MatrixXd &local_pts, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &u, const Eigen::MatrixXd &grad_u, const Eigen::MatrixXd &reference_normals, const assembler::ElementAssemblyValues &vals, ParameterType ¶ms, Eigen::MatrixXd &val) const
void dj_dx(const Eigen::MatrixXd &elastic_params, const Eigen::MatrixXd &local_pts, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &u, const Eigen::MatrixXd &grad_u, const Eigen::MatrixXd &reference_normals, const assembler::ElementAssemblyValues &vals, ParameterType ¶ms, Eigen::MatrixXd &val) const
main class that contains the polyfem solver and all its state
Eigen::MatrixXd initial_vel_update
int n_bases
number of bases
assembler::AssemblyValsCache ass_vals_cache
used to store assembly values for small problems
bool is_adhesion_enabled() const
does the simulation have adhesion
const std::vector< basis::ElementBases > & geom_bases() const
Get a constant reference to the geometry mapping bases.
std::shared_ptr< assembler::Assembler > assembler
assemblers
ipc::CollisionMesh collision_mesh
IPC collision mesh.
std::shared_ptr< assembler::Mass > mass_matrix_assembler
std::vector< int > primitive_to_node() const
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
std::shared_ptr< polyfem::mesh::MeshNodes > mesh_nodes
Mapping from input nodes to FE nodes.
std::shared_ptr< assembler::Problem > problem
current problem, it contains rhs and bc
std::vector< int > node_to_primitive() const
json args
main input arguments containing all defaults
solver::DiffCache diff_cached
void initial_velocity(Eigen::MatrixXd &velocity) const
Load or compute the initial velocity.
void initial_acceleration(Eigen::MatrixXd &acceleration) const
Load or compute the initial acceleration.
std::vector< basis::ElementBases > bases
FE bases, the size is #elements.
int n_geom_bases
number of geometric bases
std::vector< mesh::LocalBoundary > total_local_boundary
mapping from elements to nodes for all mesh
assembler::AssemblyValsCache mass_ass_vals_cache
std::vector< int > boundary_nodes
list of boundary nodes
solver::SolveData solve_data
timedependent stuff cached
bool is_contact_enabled() const
does the simulation have contact
StiffnessMatrix basis_nodes_to_gbasis_nodes
void compute(const int el_index, const bool is_volume, const basis::ElementBases &basis, const basis::ElementBases &gbasis, ElementAssemblyValues &vals) const
retrieves cached basis evaluation and geometric for the given element if it doesn't exist,...
stores per local bases evaluations
std::vector< basis::Local2Global > global
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,...
quadrature::Quadrature quadrature
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)
const ipc::NormalCollisions & collision_set(int step) const
const StiffnessMatrix & gradu_h(int step) const
const ipc::TangentialCollisions & friction_collision_set(int step) const
Eigen::MatrixXd disp_grad(int step=0) const
const ipc::SmoothCollisions & smooth_collision_set(int step) const
const ipc::TangentialCollisions & tangential_adhesion_collision_set(int step) const
const ipc::NormalCollisions & normal_adhesion_collision_set(int step) const
Eigen::VectorXd v(int step) const
Eigen::VectorXd u(int step) const
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad, const Eigen::VectorXd &x) const override
std::shared_ptr< solver::FrictionForm > friction_form
std::shared_ptr< solver::InertiaForm > inertia_form
std::shared_ptr< solver::PeriodicContactForm > periodic_contact_form
std::shared_ptr< solver::PressureForm > pressure_form
std::shared_ptr< solver::BodyForm > body_form
std::shared_ptr< solver::NLProblem > nl_problem
std::shared_ptr< solver::NormalAdhesionForm > normal_adhesion_form
std::shared_ptr< solver::ContactForm > contact_form
std::shared_ptr< solver::ElasticForm > damping_form
std::shared_ptr< solver::ElasticForm > elastic_form
std::shared_ptr< solver::TangentialAdhesionForm > tangential_adhesion_form
Eigen::Matrix< double, dim, 1 > cross(const Eigen::Matrix< double, dim, 1 > &x, const Eigen::Matrix< double, dim, 1 > &y)
DScalar1< double, Eigen::Matrix< double, Eigen::Dynamic, 1 > > Diff
void vector2matrix(const Eigen::VectorXd &vec, Eigen::MatrixXd &mat)
auto & get_local_thread_storage(Storages &storage, int thread_id)
auto create_thread_storage(const LocalStorage &initial_local_storage)
double triangle_area(const Eigen::MatrixXd V)
Compute the signed area of a triangle defined by three points.
void maybe_parallel_for(int size, const std::function< void(int, int, int)> &partial_for)
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, MAX_QUAD_POINTS, 1 > QuadratureVector
void log_and_throw_adjoint_error(const std::string &msg)
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Automatic differentiation scalar with first-order derivatives.
static void setVariableCount(size_t value)
Set the independent variable count used by the automatic differentiation layer.
Parameters for the functional evaluation.