47 if (state.
args[
"time"][
"integrator"].is_string())
49 if (state.
args[
"time"][
"integrator"][
"type"] ==
"ImplicitEuler")
51 if (state.
args[
"time"][
"integrator"][
"type"] ==
"BDF")
52 return state.
args[
"time"][
"integrator"][
"steps"].get<
int>();
58 double dot(
const Eigen::MatrixXd &A,
const Eigen::MatrixXd &B) {
return (A.array() * B.array()).sum(); }
60 class LocalThreadScalarStorage
67 LocalThreadScalarStorage()
73 class LocalThreadVecStorage
80 LocalThreadVecStorage(
const int size)
90 T triangle_area(
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &
V)
92 Eigen::Matrix<T, Eigen::Dynamic, 1> l1 =
V.row(1) -
V.row(0);
93 Eigen::Matrix<T, Eigen::Dynamic, 1> l2 =
V.row(2) -
V.row(0);
94 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));
98 Eigen::MatrixXd triangle_area_grad(
const Eigen::MatrixXd &
F)
101 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic> full_diff(
F.rows(),
F.cols());
102 for (
int i = 0; i <
F.rows(); i++)
103 for (
int j = 0; j <
F.cols(); j++)
104 full_diff(i, j) =
Diff(i + j *
F.rows(),
F(i, j));
107 Eigen::MatrixXd
grad(
F.rows(),
F.cols());
108 for (
int i = 0; i <
F.rows(); ++i)
109 for (
int j = 0; j <
F.cols(); ++j)
110 grad(i, j) = reduced_diff.getGradient()(i + j *
F.rows());
115 template <
typename T>
116 T line_length(
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &
V)
118 Eigen::Matrix<T, Eigen::Dynamic, 1> L =
V.row(1) -
V.row(0);
123 Eigen::MatrixXd line_length_grad(
const Eigen::MatrixXd &
F)
126 Eigen::Matrix<Diff, Eigen::Dynamic, Eigen::Dynamic> full_diff(
F.rows(),
F.cols());
127 for (
int i = 0; i <
F.rows(); i++)
128 for (
int j = 0; j <
F.cols(); j++)
129 full_diff(i, j) =
Diff(i + j *
F.rows(),
F(i, j));
130 auto reduced_diff = line_length(full_diff);
132 Eigen::MatrixXd
grad(
F.rows(),
F.cols());
133 for (
int i = 0; i <
F.rows(); ++i)
134 for (
int j = 0; j <
F.cols(); ++j)
135 grad(i, j) = reduced_diff.getGradient()(i + j *
F.rows());
140 template <
typename T>
141 Eigen::Matrix<T, 2, 1> edge_normal(
const Eigen::Matrix<T, 4, 1> &
V)
143 Eigen::Matrix<T, 2, 1> v1 =
V.segment(0, 2);
144 Eigen::Matrix<T, 2, 1> v2 =
V.segment(2, 2);
145 Eigen::Matrix<T, 2, 1> normal = v1 - v2;
147 normal = normal / normal.norm();
151 template <
typename T>
152 Eigen::Matrix<T, 3, 1> face_normal(
const Eigen::Matrix<T, 9, 1> &
V)
154 Eigen::Matrix<T, 3, 1> v1 =
V.segment(0, 3);
155 Eigen::Matrix<T, 3, 1> v2 =
V.segment(3, 3);
156 Eigen::Matrix<T, 3, 1> v3 =
V.segment(6, 3);
157 Eigen::Matrix<T, 3, 1> normal = (v2 - v1).
cross(v3 - v1);
158 normal = normal / normal.norm();
162 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)
164 Eigen::MatrixXd params = Eigen::MatrixXd::Zero(local_pts.rows(), 2);
166 auto search_lambda = lame_params.find(
"lambda");
167 auto search_mu = lame_params.find(
"mu");
169 if (search_lambda == lame_params.end() || search_mu == lame_params.end())
172 for (
int p = 0; p < local_pts.rows(); p++)
174 params(p, 0) = search_lambda->second(local_pts.row(p), pts.row(p), t, e);
175 params(p, 1) = search_mu->second(local_pts.row(p), pts.row(p), t, e);
185 const Eigen::MatrixXd &solution,
186 const std::set<int> &interested_ids,
190 const auto &bases = state.
bases;
193 const int dim = state.
mesh->dimension();
194 const int actual_dim = state.
problem->is_scalar() ? 1 : dim;
195 const int n_elements = int(bases.size());
196 const double t0 = state.
problem->is_time_dependent() ? state.
args[
"time"][
"t0"].get<
double>() : 0.0;
197 const double dt = state.
problem->is_time_dependent() ? state.
args[
"time"][
"dt"].get<
double>() : 0.0;
207 params.
t = dt * cur_step + t0;
208 params.
step = cur_step;
210 Eigen::MatrixXd u, grad_u;
211 Eigen::MatrixXd result;
213 for (
int e = start; e < end; ++e)
215 if (interested_ids.size() != 0 && interested_ids.find(state.
mesh->get_body_id(e)) == interested_ids.end())
231 local_storage.val += dot(result, local_storage.da);
234 for (
const LocalThreadScalarStorage &local_storage : storage)
235 integral += local_storage.val;
241 LocalThreadScalarStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
244 Eigen::MatrixXd points, normal;
245 Eigen::VectorXd weights;
247 Eigen::MatrixXd u, grad_u;
248 Eigen::MatrixXd result;
249 IntegrableFunctional::ParameterType params;
250 params.t = dt * cur_step + t0;
251 params.step = cur_step;
253 for (int lb_id = start; lb_id < end; ++lb_id)
255 const auto &lb = state.total_local_boundary[lb_id];
256 const int e = lb.element_id();
258 for (int i = 0; i < lb.size(); i++)
260 const int global_primitive_id = lb.global_primitive_id(i);
261 if (interested_ids.size() != 0 && interested_ids.find(state.mesh->get_boundary_id(global_primitive_id)) == interested_ids.end())
264 utils::BoundarySampler::boundary_quadrature(lb, state.n_boundary_samples(), *state.mesh, i, false, uv, points, normal, weights);
266 assembler::ElementAssemblyValues &vals = local_storage.vals;
267 vals.compute(e, state.mesh->is_volume(), points, bases[e], gbases[e]);
268 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim, vals, solution, u, grad_u);
270 const Eigen::MatrixXd lame_params = extract_lame_params(state.assembler->parameters(), e, params.t, points, vals.val);
273 params.body_id = state.mesh->get_body_id(e);
274 params.boundary_id = state.mesh->get_boundary_id(global_primitive_id);
275 j.evaluate(lame_params, points, vals.val, u, grad_u, normal, vals, params, result);
277 local_storage.val += dot(result, weights);
281 for (
const LocalThreadScalarStorage &local_storage : storage)
282 integral += local_storage.val;
286 std::vector<bool> traversed(state.
n_bases,
false);
288 params.
t = dt * cur_step + t0;
289 params.
step = cur_step;
290 for (
int e = 0; e < bases.size(); e++)
292 const auto &bs = bases[e];
293 for (
int i = 0; i < bs.bases.size(); i++)
295 const auto &b = bs.bases[i];
296 assert(b.global().size() == 1);
297 const auto &g = b.global()[0];
298 if (traversed[g.index])
301 const Eigen::MatrixXd lame_params = extract_lame_params(state.
assembler->parameters(), e, params.
t, Eigen::MatrixXd::Zero(1, dim) , g.node);
303 params.
node = g.index;
307 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);
309 traversed[g.index] =
true;
317 void AdjointTools::compute_shape_derivative_functional_term(
319 const Eigen::MatrixXd &solution,
321 const std::set<int> &interested_ids,
323 Eigen::VectorXd &term,
324 const int cur_time_step)
327 const auto &bases = state.
bases;
328 const int dim = state.
mesh->dimension();
329 const int actual_dim = state.
problem->is_scalar() ? 1 : dim;
330 const double t0 = state.
problem->is_time_dependent() ? state.
args[
"time"][
"t0"].get<
double>() : 0.0;
331 const double dt = state.
problem->is_time_dependent() ? state.
args[
"time"][
"dt"].get<
double>() : 0.0;
333 const int n_elements = int(bases.size());
336 auto storage = utils::create_thread_storage(LocalThreadVecStorage(term.size()));
338 if (spatial_integral_type == SpatialIntegralType::Volume)
340 utils::maybe_parallel_for(n_elements, [&](
int start,
int end,
int thread_id) {
341 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
343 Eigen::MatrixXd u, grad_u, j_val, dj_dgradu, dj_dx;
346 params.
t = cur_time_step * dt + t0;
347 params.
step = cur_time_step;
349 for (
int e = start; e < end; ++e)
351 if (interested_ids.size() != 0 && interested_ids.find(state.
mesh->get_body_id(e)) == interested_ids.end())
356 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim,
vals, solution, u, grad_u);
377 Eigen::MatrixXd tau_q, grad_u_q;
378 for (
auto &v :
gvals.basis_values)
380 for (
int q = 0; q < local_storage.da.size(); ++q)
382 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();
385 local_storage.vec.block(v.global[0].index * dim, 0, dim, 1) += (v.val(q) * local_storage.da(q)) * dj_dx.row(q).transpose();
389 if (dim == actual_dim)
396 tau_q = dj_dgradu.row(q);
397 grad_u_q = grad_u.row(q);
399 for (
int d = 0; d < dim; d++)
400 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);
407 else if (spatial_integral_type == SpatialIntegralType::Surface)
409 utils::maybe_parallel_for(state.
total_local_boundary.size(), [&](
int start,
int end,
int thread_id) {
410 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
412 Eigen::MatrixXd uv, points, normal;
413 Eigen::VectorXd &weights = local_storage.da;
415 Eigen::MatrixXd u, grad_u, x, grad_x, j_val, dj_dgradu, dj_dgradx, dj_dx;
417 IntegrableFunctional::ParameterType params;
418 params.t = cur_time_step * dt + t0;
419 params.step = cur_time_step;
421 for (int lb_id = start; lb_id < end; ++lb_id)
423 const auto &lb = state.total_local_boundary[lb_id];
424 const int e = lb.element_id();
426 for (int i = 0; i < lb.size(); i++)
428 const int global_primitive_id = lb.global_primitive_id(i);
429 if (interested_ids.size() != 0 && interested_ids.find(state.mesh->get_boundary_id(global_primitive_id)) == interested_ids.end())
432 utils::BoundarySampler::boundary_quadrature(lb, state.n_boundary_samples(), *state.mesh, i, false, uv, points, normal, weights);
434 assembler::ElementAssemblyValues &vals = local_storage.vals;
435 io::Evaluator::interpolate_at_local_vals(*state.mesh, state.problem->is_scalar(), bases, gbases, e, points, solution, u, grad_u);
438 vals.compute(e, state.mesh->is_volume(), points, gbases[e], gbases[e]);
442 const int n_loc_bases_ = int(vals.basis_values.size());
444 const Eigen::MatrixXd lame_params = extract_lame_params(state.assembler->parameters(), e, params.t, points, vals.val);
447 params.body_id = state.mesh->get_body_id(e);
448 params.boundary_id = state.mesh->get_boundary_id(global_primitive_id);
450 j.evaluate(lame_params, points, vals.val, u, grad_u, normal, vals, params, j_val);
451 j_val = j_val.array().colwise() * weights.array();
453 if (j.depend_on_gradu())
455 j.dj_dgradu(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradu);
456 dj_dgradu = dj_dgradu.array().colwise() * weights.array();
459 if (j.depend_on_gradx())
461 j.dj_dgradx(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradx);
462 dj_dgradx = dj_dgradx.array().colwise() * weights.array();
467 j.dj_dx(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dx);
468 dj_dx = dj_dx.array().colwise() * weights.array();
471 const auto nodes = gbases[e].local_nodes_for_primitive(lb.global_primitive_id(i), *state.mesh);
473 if (nodes.size() != dim)
474 log_and_throw_adjoint_error(
"Only linear geometry is supported in differentiable surface integral functional!");
476 Eigen::MatrixXd velocity_div_mat;
477 if (state.mesh->is_volume())
480 for (int d = 0; d < 3; d++)
481 V.row(d) = gbases[e].bases[nodes(d)].global()[0].node;
482 velocity_div_mat = face_velocity_divergence(V);
487 for (int d = 0; d < 2; d++)
488 V.row(d) = gbases[e].bases[nodes(d)].global()[0].node;
489 velocity_div_mat = edge_velocity_divergence(V);
492 Eigen::MatrixXd grad_u_q, tau_q, grad_x_q;
493 for (long n = 0; n < nodes.size(); ++n)
495 const assembler::AssemblyValues &v = vals.basis_values[nodes(n)];
497 local_storage.vec.block(v.global[0].index * dim, 0, dim, 1) += j_val.sum() * velocity_div_mat.row(n).transpose();
500 for (long n = 0; n < n_loc_bases_; ++n)
502 const assembler::AssemblyValues &v = vals.basis_values[n];
505 local_storage.vec.block(v.global[0].index * dim, 0, dim, 1) += dj_dx.transpose() * v.val;
508 if (j.depend_on_gradu())
510 for (int q = 0; q < weights.size(); ++q)
512 if (dim == actual_dim)
514 vector2matrix(grad_u.row(q), grad_u_q);
515 vector2matrix(dj_dgradu.row(q), tau_q);
519 grad_u_q = grad_u.row(q);
520 tau_q = dj_dgradu.row(q);
523 for (int d = 0; d < dim; d++)
524 local_storage.vec(v.global[0].index * dim + d) += -dot(tau_q, grad_u_q.col(d) * v.grad_t_m.row(q));
528 if (j.depend_on_gradx())
530 for (int d = 0; d < dim; d++)
532 for (int q = 0; q < weights.size(); ++q)
533 local_storage.vec(v.global[0].index * dim + d) += dot(dj_dgradx.block(q, d * dim, 1, dim), v.grad.row(q));
541 else if (spatial_integral_type == SpatialIntegralType::VertexSum)
545 for (
const LocalThreadVecStorage &local_storage : storage)
546 term += local_storage.
vec;
548 term = utils::flatten(utils::unflatten(term, dim)(state.
primitive_to_node(), Eigen::all));
317 void AdjointTools::compute_shape_derivative_functional_term( {
…}
551 void AdjointTools::dJ_shape_static_adjoint_term(
553 const Eigen::MatrixXd &sol,
554 const Eigen::MatrixXd &adjoint,
555 Eigen::VectorXd &one_form)
557 Eigen::VectorXd elasticity_term, rhs_term, pressure_term, contact_term, adhesion_term;
560 Eigen::MatrixXd adjoint_zeroed = adjoint;
569 rhs_term.setZero(one_form.size());
577 pressure_term.setZero(one_form.size());
593 contact_term.setZero(elasticity_term.size());
602 adhesion_term.setZero(elasticity_term.size());
606 one_form -= elasticity_term + rhs_term + pressure_term + contact_term + adhesion_term;
607 one_form = utils::flatten(utils::unflatten(one_form, state.
mesh->dimension())(state.
primitive_to_node(), Eigen::all));
551 void AdjointTools::dJ_shape_static_adjoint_term( {
…}
610 void AdjointTools::dJ_shape_homogenization_adjoint_term(
612 const Eigen::MatrixXd &sol,
613 const Eigen::MatrixXd &adjoint,
614 Eigen::VectorXd &one_form)
616 Eigen::VectorXd elasticity_term, contact_term, adhesion_term;
618 std::shared_ptr<NLHomoProblem> homo_problem = std::dynamic_pointer_cast<NLHomoProblem>(state.
solve_data.
nl_problem);
619 assert(homo_problem);
621 const int dim = state.
mesh->dimension();
624 const Eigen::MatrixXd affine_adjoint = homo_problem->reduced_to_disp_grad(adjoint,
true);
625 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 contact_term.setZero(elasticity_term.size());
652 adhesion_term.setZero(elasticity_term.size());
655 one_form = -(elasticity_term + contact_term + adhesion_term);
657 Eigen::VectorXd force;
658 homo_problem->FullNLProblem::gradient(sol, force);
661 one_form = utils::flatten(utils::unflatten(one_form, dim)(state.
primitive_to_node(), Eigen::all));
610 void AdjointTools::dJ_shape_homogenization_adjoint_term( {
…}
664 void AdjointTools::dJ_periodic_shape_adjoint_term(
667 const Eigen::VectorXd &periodic_mesh_representation,
668 const Eigen::MatrixXd &sol,
669 const Eigen::MatrixXd &adjoint,
670 Eigen::VectorXd &one_form)
672 std::shared_ptr<NLHomoProblem> homo_problem = std::dynamic_pointer_cast<NLHomoProblem>(state.
solve_data.
nl_problem);
673 assert(homo_problem);
675 const Eigen::MatrixXd reduced_sol = homo_problem->full_to_reduced(sol, state.
diff_cached.
disp_grad());
676 const Eigen::VectorXd extended_sol = homo_problem->reduced_to_extended(reduced_sol);
678 const Eigen::VectorXd extended_adjoint = homo_problem->reduced_to_extended(adjoint,
true);
679 const Eigen::MatrixXd affine_adjoint = homo_problem->reduced_to_disp_grad(adjoint,
true);
680 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);
682 const int dim = state.
mesh->dimension();
687 homo_problem->set_project_to_psd(
false);
688 homo_problem->FullNLProblem::hessian(sol, hessian);
689 Eigen::VectorXd partial_term = full_adjoint.transpose() * hessian;
691 one_form -= utils::flatten(utils::unflatten(partial_term, dim)(state.
primitive_to_node(), Eigen::all));
693 one_form = periodic_mesh_map.
apply_jacobian(one_form, periodic_mesh_representation);
697 Eigen::VectorXd contact_term;
700 one_form -= contact_term;
664 void AdjointTools::dJ_periodic_shape_adjoint_term( {
…}
704 void AdjointTools::dJ_shape_transient_adjoint_term(
706 const Eigen::MatrixXd &adjoint_nu,
707 const Eigen::MatrixXd &adjoint_p,
708 Eigen::VectorXd &one_form)
710 const double t0 = state.
args[
"time"][
"t0"];
711 const double dt = state.
args[
"time"][
"dt"];
712 const int time_steps = state.
args[
"time"][
"time_steps"];
713 const int bdf_order = get_bdf_order(state);
715 Eigen::VectorXd elasticity_term, rhs_term, pressure_term, damping_term, mass_term, contact_term, friction_term, adhesion_term, tangential_adhesion_term;
718 Eigen::VectorXd cur_p, cur_nu;
719 for (
int i = time_steps; i > 0; --i)
721 const int real_order = std::min(bdf_order, i);
722 double beta = time_integrator::BDF::betas(real_order - 1);
723 double beta_dt = beta * dt;
724 const double t = i * dt + t0;
728 cur_p = adjoint_p.col(i);
729 cur_nu = adjoint_nu.col(i);
743 damping_term.setZero(mass_term.size());
759 contact_term.setZero(mass_term.size());
768 friction_term.setZero(mass_term.size());
777 adhesion_term.setZero(mass_term.size());
787 tangential_adhesion_term.setZero(mass_term.size());
790 one_form += beta_dt * (elasticity_term + rhs_term + pressure_term + damping_term + contact_term + friction_term + mass_term + adhesion_term + tangential_adhesion_term);
794 Eigen::VectorXd sum_alpha_p;
796 sum_alpha_p.setZero(adjoint_p.rows());
797 int num = std::min(bdf_order, time_steps);
798 for (
int j = 0; j < num; ++j)
800 int order = std::min(bdf_order - 1, j);
801 sum_alpha_p -= time_integrator::BDF::alphas(order)[j] * adjoint_p.col(j + 1);
807 one_form += mass_term;
809 one_form = utils::flatten(utils::unflatten(one_form, state.
mesh->dimension())(state.
primitive_to_node(), Eigen::all));
704 void AdjointTools::dJ_shape_transient_adjoint_term( {
…}
812 void AdjointTools::dJ_material_static_adjoint_term(
814 const Eigen::MatrixXd &sol,
815 const Eigen::MatrixXd &adjoint,
816 Eigen::VectorXd &one_form)
818 Eigen::MatrixXd adjoint_zeroed = adjoint;
812 void AdjointTools::dJ_material_static_adjoint_term( {
…}
823 void AdjointTools::dJ_material_transient_adjoint_term(
825 const Eigen::MatrixXd &adjoint_nu,
826 const Eigen::MatrixXd &adjoint_p,
827 Eigen::VectorXd &one_form)
829 const double t0 = state.
args[
"time"][
"t0"];
830 const double dt = state.
args[
"time"][
"dt"];
831 const int time_steps = state.
args[
"time"][
"time_steps"];
832 const int bdf_order = get_bdf_order(state);
834 one_form.setZero(state.
bases.size() * 2);
836 auto storage = utils::create_thread_storage(LocalThreadVecStorage(one_form.size()));
838 utils::maybe_parallel_for(time_steps, [&](
int start,
int end,
int thread_id) {
839 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
840 Eigen::VectorXd elasticity_term;
841 for (
int i_aux = start; i_aux < end; ++i_aux)
843 const int i = time_steps - i_aux;
844 const int real_order = std::min(bdf_order, i);
845 double beta_dt = time_integrator::BDF::betas(real_order - 1) * dt;
847 Eigen::VectorXd cur_p = adjoint_p.col(i);
851 local_storage.vec += beta_dt * elasticity_term;
855 for (
const LocalThreadVecStorage &local_storage : storage)
856 one_form += local_storage.vec;
823 void AdjointTools::dJ_material_transient_adjoint_term( {
…}
859 void AdjointTools::dJ_friction_transient_adjoint_term(
861 const Eigen::MatrixXd &adjoint_nu,
862 const Eigen::MatrixXd &adjoint_p,
863 Eigen::VectorXd &one_form)
865 const double dt = state.
args[
"time"][
"dt"];
867 const int time_steps = state.
args[
"time"][
"time_steps"];
868 const int dim = state.
mesh->dimension();
869 const int bdf_order = get_bdf_order(state);
873 std::shared_ptr<time_integrator::ImplicitTimeIntegrator> time_integrator =
874 time_integrator::ImplicitTimeIntegrator::construct_time_integrator(state.
args[
"time"][
"integrator"]);
876 Eigen::MatrixXd solution, velocity, acceleration;
882 const double dt = state.
args[
"time"][
"dt"];
883 time_integrator->init(solution, velocity, acceleration, dt);
886 for (
int t = 1; t <= time_steps; ++t)
888 const int real_order = std::min(bdf_order, t);
889 double beta = time_integrator::BDF::betas(real_order - 1);
891 const Eigen::MatrixXd surface_solution_prev = state.
collision_mesh.vertices(utils::unflatten(state.
diff_cached.
u(t - 1), dim));
895 time_integrator->update_quantities(state.
diff_cached.
u(t));
904 surface_solution_prev,
906 barrier_contact->barrier_potential(),
907 barrier_contact->barrier_stiffness(),
910 Eigen::VectorXd cur_p = adjoint_p.col(t);
913 one_form(0) += dot(cur_p, force) * beta * dt;
859 void AdjointTools::dJ_friction_transient_adjoint_term( {
…}
918 void AdjointTools::dJ_damping_transient_adjoint_term(
920 const Eigen::MatrixXd &adjoint_nu,
921 const Eigen::MatrixXd &adjoint_p,
922 Eigen::VectorXd &one_form)
924 const double t0 = state.
args[
"time"][
"t0"];
925 const double dt = state.
args[
"time"][
"dt"];
926 const int time_steps = state.
args[
"time"][
"time_steps"];
927 const int bdf_order = get_bdf_order(state);
931 auto storage = utils::create_thread_storage(LocalThreadVecStorage(one_form.size()));
933 utils::maybe_parallel_for(time_steps, [&](
int start,
int end,
int thread_id) {
934 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
935 Eigen::VectorXd damping_term;
936 for (
int t_aux = start; t_aux < end; ++t_aux)
938 const int t = time_steps - t_aux;
939 const int real_order = std::min(bdf_order, t);
940 const double beta = time_integrator::BDF::betas(real_order - 1);
942 Eigen::VectorXd cur_p = adjoint_p.col(t);
946 local_storage.vec += (beta * dt) * damping_term;
950 for (
const LocalThreadVecStorage &local_storage : storage)
951 one_form += local_storage.vec;
918 void AdjointTools::dJ_damping_transient_adjoint_term( {
…}
954 void AdjointTools::dJ_initial_condition_adjoint_term(
956 const Eigen::MatrixXd &adjoint_nu,
957 const Eigen::MatrixXd &adjoint_p,
958 Eigen::VectorXd &one_form)
960 const int ndof = state.
ndof();
961 one_form.setZero(ndof * 2);
964 one_form.segment(0, ndof) = -adjoint_nu.col(0);
965 one_form.segment(ndof, ndof) = -adjoint_p.col(0);
970 one_form(ndof + b) = 0;
954 void AdjointTools::dJ_initial_condition_adjoint_term( {
…}
974 void AdjointTools::dJ_dirichlet_static_adjoint_term(
976 const Eigen::MatrixXd &adjoint,
977 Eigen::VectorXd &one_form)
982 gradd_h.prune([&boundary_nodes_set](
const Eigen::Index &row,
const Eigen::Index &col,
const FullNLProblem::Scalar &value) {
985 if (boundary_nodes_set.find(row) == boundary_nodes_set.end())
989 one_form.setZero(state.
ndof());
992 one_form = utils::flatten(utils::unflatten(one_form, state.
mesh->dimension())(state.
primitive_to_node(), Eigen::all));
974 void AdjointTools::dJ_dirichlet_static_adjoint_term( {
…}
995 void AdjointTools::dJ_dirichlet_transient_adjoint_term(
997 const Eigen::MatrixXd &adjoint_nu,
998 const Eigen::MatrixXd &adjoint_p,
999 Eigen::VectorXd &one_form)
1001 const double dt = state.
args[
"time"][
"dt"];
1002 const int time_steps = state.
args[
"time"][
"time_steps"];
1003 const int bdf_order = get_bdf_order(state);
1008 one_form.setZero(time_steps * n_dirichlet_dof);
1009 for (
int i = 1; i <= time_steps; ++i)
1011 const int real_order = std::min(bdf_order, i);
1012 const double beta_dt = time_integrator::BDF::betas(real_order - 1) * dt;
1014 one_form.segment((i - 1) * n_dirichlet_dof, n_dirichlet_dof) = -(1. / beta_dt) * adjoint_p(state.
boundary_nodes, i);
995 void AdjointTools::dJ_dirichlet_transient_adjoint_term( {
…}
1018 void AdjointTools::dJ_pressure_static_adjoint_term(
1020 const std::vector<int> &boundary_ids,
1021 const Eigen::MatrixXd &sol,
1022 const Eigen::MatrixXd &adjoint,
1023 Eigen::VectorXd &one_form)
1025 const int n_pressure_dof = boundary_ids.size();
1027 one_form.setZero(n_pressure_dof);
1029 for (
int i = 0; i < boundary_ids.size(); ++i)
1037 one_form(i) = pressure_term;
1018 void AdjointTools::dJ_pressure_static_adjoint_term( {
…}
1041 void AdjointTools::dJ_pressure_transient_adjoint_term(
1043 const std::vector<int> &boundary_ids,
1044 const Eigen::MatrixXd &adjoint_nu,
1045 const Eigen::MatrixXd &adjoint_p,
1046 Eigen::VectorXd &one_form)
1048 const double t0 = state.
args[
"time"][
"t0"];
1049 const double dt = state.
args[
"time"][
"dt"];
1050 const int time_steps = state.
args[
"time"][
"time_steps"];
1051 const int bdf_order = get_bdf_order(state);
1053 const int n_pressure_dof = boundary_ids.size();
1055 one_form.setZero(time_steps * n_pressure_dof);
1056 Eigen::VectorXd cur_p, cur_nu;
1057 for (
int i = time_steps; i > 0; --i)
1059 const int real_order = std::min(bdf_order, i);
1060 double beta = time_integrator::BDF::betas(real_order - 1);
1061 double beta_dt = beta * dt;
1062 const double t = i * dt + t0;
1064 cur_p = adjoint_p.col(i);
1065 cur_nu = adjoint_nu.col(i);
1069 for (
int b = 0; b < boundary_ids.size(); ++b)
1077 one_form((i - 1) * n_pressure_dof + b) = -beta_dt * pressure_term;
1041 void AdjointTools::dJ_pressure_transient_adjoint_term( {
…}
1082 void AdjointTools::dJ_du_step(
1085 const Eigen::MatrixXd &solution,
1086 const std::set<int> &interested_ids,
1089 Eigen::VectorXd &term)
1091 const auto &bases = state.
bases;
1094 const int dim = state.
mesh->dimension();
1095 const int actual_dim = state.
problem->is_scalar() ? 1 : dim;
1096 const int n_elements = int(bases.size());
1097 const double t0 = state.
problem->is_time_dependent() ? state.
args[
"time"][
"t0"].get<
double>() : 0.0;
1098 const double dt = state.
problem->is_time_dependent() ? state.
args[
"time"][
"dt"].get<
double>() : 0.0;
1100 term = Eigen::MatrixXd::Zero(state.
n_bases * actual_dim, 1);
1105 if (spatial_integral_type == SpatialIntegralType::Volume)
1107 auto storage = utils::create_thread_storage(LocalThreadVecStorage(term.size()));
1108 utils::maybe_parallel_for(n_elements, [&](
int start,
int end,
int thread_id) {
1109 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
1111 Eigen::MatrixXd u, grad_u;
1112 Eigen::MatrixXd lambda, mu;
1113 Eigen::MatrixXd dj_du, dj_dgradu, dj_dgradx;
1116 params.
t = dt * cur_step + t0;
1117 params.
step = cur_step;
1119 for (
int e = start; e < end; ++e)
1121 if (interested_ids.size() != 0 && interested_ids.find(state.
mesh->get_body_id(e)) == interested_ids.end())
1132 const int n_loc_bases_ = int(
vals.basis_values.size());
1134 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim,
vals, solution, u, grad_u);
1139 dj_dgradu.resize(0, 0);
1143 for (
int q = 0; q < dj_dgradu.rows(); q++)
1144 dj_dgradu.row(q) *= local_storage.da(q);
1151 for (
int q = 0; q < dj_du.rows(); q++)
1152 dj_du.row(q) *= local_storage.da(q);
1155 for (
int i = 0; i < n_loc_bases_; ++i)
1158 assert(v.
global.size() == 1);
1159 for (
int d = 0; d < actual_dim; d++)
1166 for (
int q = 0; q < local_storage.da.size(); ++q)
1167 val += dot(dj_dgradu.block(q, d * dim, 1, dim), v.
grad_t_m.row(q));
1173 for (
int q = 0; q < local_storage.da.size(); ++q)
1174 val += dj_du(q, d) * v.
val(q);
1176 local_storage.vec(v.
global[0].index * actual_dim + d) +=
val;
1181 for (
const LocalThreadVecStorage &local_storage : storage)
1182 term += local_storage.vec;
1184 else if (spatial_integral_type == SpatialIntegralType::Surface)
1186 auto storage = utils::create_thread_storage(LocalThreadVecStorage(term.size()));
1187 utils::maybe_parallel_for(state.
total_local_boundary.size(), [&](
int start,
int end,
int thread_id) {
1188 LocalThreadVecStorage &local_storage = utils::get_local_thread_storage(storage, thread_id);
1190 Eigen::MatrixXd uv, samples, gtmp;
1191 Eigen::MatrixXd points, normal;
1192 Eigen::VectorXd weights;
1194 Eigen::MatrixXd u, grad_u;
1195 Eigen::MatrixXd lambda, mu;
1196 Eigen::MatrixXd dj_du, dj_dgradu, dj_dgradu_local;
1198 IntegrableFunctional::ParameterType params;
1199 params.t = dt * cur_step + t0;
1200 params.step = cur_step;
1202 for (int lb_id = start; lb_id < end; ++lb_id)
1204 const auto &lb = state.total_local_boundary[lb_id];
1205 const int e = lb.element_id();
1207 for (int i = 0; i < lb.size(); i++)
1209 const int global_primitive_id = lb.global_primitive_id(i);
1210 if (interested_ids.size() != 0 && interested_ids.find(state.mesh->get_boundary_id(global_primitive_id)) == interested_ids.end())
1213 utils::BoundarySampler::boundary_quadrature(lb, state.n_boundary_samples(), *state.mesh, i, false, uv, points, normal, weights);
1215 assembler::ElementAssemblyValues &vals = local_storage.vals;
1216 vals.compute(e, state.mesh->is_volume(), points, bases[e], gbases[e]);
1217 io::Evaluator::interpolate_at_local_vals(e, dim, actual_dim, vals, solution, u, grad_u);
1219 const Eigen::MatrixXd lame_params = extract_lame_params(state.assembler->parameters(), e, params.t, points, vals.val);
1223 const int n_loc_bases_ = int(vals.basis_values.size());
1226 params.body_id = state.mesh->get_body_id(e);
1227 params.boundary_id = state.mesh->get_boundary_id(global_primitive_id);
1229 dj_dgradu.resize(0, 0);
1230 if (j.depend_on_gradu())
1232 j.dj_dgradu(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradu);
1233 for (int q = 0; q < dj_dgradu.rows(); q++)
1234 dj_dgradu.row(q) *= weights(q);
1237 dj_dgradu_local.resize(0, 0);
1238 if (j.depend_on_gradu_local())
1240 j.dj_dgradu_local(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_dgradu_local);
1241 for (int q = 0; q < dj_dgradu_local.rows(); q++)
1242 dj_dgradu_local.row(q) *= weights(q);
1246 if (j.depend_on_u())
1248 j.dj_du(lame_params, points, vals.val, u, grad_u, normal, vals, params, dj_du);
1249 for (int q = 0; q < dj_du.rows(); q++)
1250 dj_du.row(q) *= weights(q);
1253 for (int l = 0; l < lb.size(); ++l)
1255 const auto nodes = bases[e].local_nodes_for_primitive(lb.global_primitive_id(l), *state.mesh);
1257 for (long n = 0; n < nodes.size(); ++n)
1259 const assembler::AssemblyValues &v = vals.basis_values[nodes(n)];
1260 assert(v.global.size() == 1);
1261 for (int d = 0; d < actual_dim; d++)
1266 if (j.depend_on_gradu())
1268 for (int q = 0; q < weights.size(); ++q)
1269 val += dot(dj_dgradu.block(q, d * dim, 1, dim), v.grad_t_m.row(q));
1272 if (j.depend_on_gradu_local())
1274 for (int q = 0; q < weights.size(); ++q)
1275 val += dot(dj_dgradu_local.block(q, d * dim, 1, dim), v.grad.row(q));
1278 if (j.depend_on_u())
1280 for (int q = 0; q < weights.size(); ++q)
1281 val += dj_du(q, d) * v.val(q);
1283 local_storage.vec(v.global[0].index * actual_dim + d) += val;
1290 for (
const LocalThreadVecStorage &local_storage : storage)
1291 term += local_storage.vec;
1293 else if (spatial_integral_type == SpatialIntegralType::VertexSum)
1295 std::vector<bool> traversed(state.
n_bases,
false);
1297 params.
t = dt * cur_step + t0;
1298 params.
step = cur_step;
1299 for (
int e = 0; e < bases.size(); e++)
1301 const auto &bs = bases[e];
1302 for (
int i = 0; i < bs.bases.size(); i++)
1304 const auto &b = bs.bases[i];
1305 assert(b.global().size() == 1);
1306 const auto &g = b.global()[0];
1307 if (traversed[g.index])
1310 const Eigen::MatrixXd lame_params = extract_lame_params(state.
assembler->parameters(), e, params.
t, Eigen::MatrixXd::Zero(1, dim) , g.node);
1312 params.
node = g.index;
1315 Eigen::MatrixXd
val;
1316 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);
1317 term.block(g.index * actual_dim, 0, actual_dim, 1) +=
val.transpose();
1318 traversed[g.index] =
true;
1082 void AdjointTools::dJ_du_step( {
…}
1324 Eigen::VectorXd AdjointTools::map_primitive_to_node_order(
const State &state,
const Eigen::VectorXd &primitives)
1326 int dim = state.
mesh->dimension();
1327 assert(primitives.size() == (state.
n_geom_bases * dim));
1328 Eigen::VectorXd nodes(primitives.size());
1331 nodes.segment(map[v] * dim, dim) = primitives.segment(v * dim, dim);
1324 Eigen::VectorXd AdjointTools::map_primitive_to_node_order(
const State &state,
const Eigen::VectorXd &primitives) {
…}
1335 Eigen::VectorXd AdjointTools::map_node_to_primitive_order(
const State &state,
const Eigen::VectorXd &nodes)
1337 int dim = state.
mesh->dimension();
1339 Eigen::VectorXd primitives(nodes.size());
1342 primitives.segment(map[v] * dim, dim) = nodes.segment(v * dim, dim);
1335 Eigen::VectorXd AdjointTools::map_node_to_primitive_order(
const State &state,
const Eigen::VectorXd &nodes) {
…}
1346 Eigen::MatrixXd AdjointTools::edge_normal_gradient(
const Eigen::MatrixXd &
V)
1349 Eigen::Matrix<Diff, 4, 1> full_diff(4, 1);
1350 for (
int i = 0; i < 2; i++)
1351 for (
int j = 0; j < 2; j++)
1352 full_diff(i * 2 + j) =
Diff(i * 2 + j,
V(i, j));
1353 auto reduced_diff = edge_normal(full_diff);
1355 Eigen::MatrixXd grad(2, 4);
1356 for (
int i = 0; i < 2; ++i)
1357 grad.row(i) = reduced_diff[i].getGradient();
1346 Eigen::MatrixXd AdjointTools::edge_normal_gradient(
const Eigen::MatrixXd &
V) {
…}
1362 Eigen::MatrixXd AdjointTools::face_normal_gradient(
const Eigen::MatrixXd &
V)
1365 Eigen::Matrix<Diff, 9, 1> full_diff(9, 1);
1366 for (
int i = 0; i < 3; i++)
1367 for (
int j = 0; j < 3; j++)
1368 full_diff(i * 3 + j) =
Diff(i * 3 + j,
V(i, j));
1369 auto reduced_diff = face_normal(full_diff);
1371 Eigen::MatrixXd grad(3, 9);
1372 for (
int i = 0; i < 3; ++i)
1373 grad.row(i) = reduced_diff[i].getGradient();
1362 Eigen::MatrixXd AdjointTools::face_normal_gradient(
const Eigen::MatrixXd &
V) {
…}
1378 Eigen::MatrixXd AdjointTools::edge_velocity_divergence(
const Eigen::MatrixXd &
V)
1380 return line_length_grad(
V) / line_length<double>(
V);
1378 Eigen::MatrixXd AdjointTools::edge_velocity_divergence(
const Eigen::MatrixXd &
V) {
…}
1383 Eigen::MatrixXd AdjointTools::face_velocity_divergence(
const Eigen::MatrixXd &
V)
1385 return triangle_area_grad(
V) / triangle_area<double>(
V);
1383 Eigen::MatrixXd AdjointTools::face_velocity_divergence(
const Eigen::MatrixXd &
V) {
…}
1388 double AdjointTools::triangle_jacobian(
const Eigen::VectorXd &v1,
const Eigen::VectorXd &v2,
const Eigen::VectorXd &v3)
1390 Eigen::VectorXd a = v2 - v1, b = v3 - v1;
1391 return a(0) * b(1) - b(0) * a(1);
1388 double AdjointTools::triangle_jacobian(
const Eigen::VectorXd &v1,
const Eigen::VectorXd &v2,
const Eigen::VectorXd &v3) {
…}
1394 double AdjointTools::tet_determinant(
const Eigen::VectorXd &v1,
const Eigen::VectorXd &v2,
const Eigen::VectorXd &v3,
const Eigen::VectorXd &v4)
1396 Eigen::Matrix3d mat;
1397 mat.col(0) << v2 - v1;
1398 mat.col(1) << v3 - v1;
1399 mat.col(2) << v4 - v1;
1400 return mat.determinant();
1394 double AdjointTools::tet_determinant(
const Eigen::VectorXd &v1,
const Eigen::VectorXd &v2,
const Eigen::VectorXd &v3,
const Eigen::VectorXd &v4) {
…}
1403 void AdjointTools::scaled_jacobian(
const Eigen::MatrixXd &
V,
const Eigen::MatrixXi &F, Eigen::VectorXd &quality)
1405 const int dim = F.cols() - 1;
1407 quality.setZero(F.rows());
1410 for (
int i = 0; i < F.rows(); i++)
1412 Eigen::RowVector3d e0;
1414 e0.head(2) =
V.row(F(i, 2)) -
V.row(F(i, 1));
1415 Eigen::RowVector3d e1;
1417 e1.head(2) =
V.row(F(i, 0)) -
V.row(F(i, 2));
1418 Eigen::RowVector3d e2;
1420 e2.head(2) =
V.row(F(i, 1)) -
V.row(F(i, 0));
1422 double l0 = e0.norm();
1423 double l1 = e1.norm();
1424 double l2 = e2.norm();
1426 double A = 0.5 * (e0.cross(e1)).norm();
1427 double Lmax = std::max(l0 * l1, std::max(l1 * l2, l0 * l2));
1429 quality(i) = 2 * A * (2 / sqrt(3)) / Lmax;
1434 for (
int i = 0; i < F.rows(); i++)
1436 Eigen::RowVector3d e0 =
V.row(F(i, 1)) -
V.row(F(i, 0));
1437 Eigen::RowVector3d e1 =
V.row(F(i, 2)) -
V.row(F(i, 1));
1438 Eigen::RowVector3d e2 =
V.row(F(i, 0)) -
V.row(F(i, 2));
1439 Eigen::RowVector3d e3 =
V.row(F(i, 3)) -
V.row(F(i, 0));
1440 Eigen::RowVector3d e4 =
V.row(F(i, 3)) -
V.row(F(i, 1));
1441 Eigen::RowVector3d e5 =
V.row(F(i, 3)) -
V.row(F(i, 2));
1443 double l0 = e0.norm();
1444 double l1 = e1.norm();
1445 double l2 = e2.norm();
1446 double l3 = e3.norm();
1447 double l4 = e4.norm();
1448 double l5 = e5.norm();
1450 double J = std::abs((e0.cross(e3)).dot(e2));
1452 double a1 = l0 * l2 * l3;
1453 double a2 = l0 * l1 * l4;
1454 double a3 = l1 * l2 * l5;
1455 double a4 = l3 * l4 * l5;
1457 double a = std::max({a1, a2, a3, a4, J});
1458 quality(i) = J * sqrt(2) / a;
1403 void AdjointTools::scaled_jacobian(
const Eigen::MatrixXd &
V,
const Eigen::MatrixXi &F, Eigen::VectorXd &quality) {
…}
1463 bool AdjointTools::is_flipped(
const Eigen::MatrixXd &
V,
const Eigen::MatrixXi &F)
1467 for (
int i = 0; i < F.rows(); i++)
1471 else if (F.cols() == 4)
1473 for (
int i = 0; i < F.rows(); i++)
1463 bool AdjointTools::is_flipped(
const Eigen::MatrixXd &
V,
const Eigen::MatrixXi &F) {
…}
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.