26 Eigen::VectorXi active_geom_nodes)
27 : dim_(states[0]->mesh->dimension()),
28 vertex_num_(states[0]->mesh->n_vertices()),
29 states_(std::move(states)),
30 diff_caches_(std::move(diff_caches)),
31 parametrization_(std::move(parametrizations)),
32 active_geom_nodes_(std::move(active_geom_nodes))
40 if (s->problem->is_time_dependent())
42 log_and_throw_adjoint_error(
"Fail to construct dirichlet nodes variable to simulation. Reason: only quasistatic simulations supported.");
53 int v = s.in_node_to_node(v_in);
54 int tag = s.mesh->get_node_id(v);
55 if (s.problem->is_nodal_dirichlet_boundary(v, tag))
60 std::sort(tmp.begin(), tmp.end());
74 return "dirichlet-nodes";
86 if (s.get() == &target)
103 auto tensor_problem = std::dynamic_pointer_cast<polyfem::assembler::GenericTensorProblem>(s->problem);
109 tensor_problem->update_dirichlet_nodes(s->in_node_to_node,
active_geom_nodes_, nodal_dirichlet);
121 Eigen::VectorXd term = Eigen::VectorXd::Zero(
para_out_dof());
123 for (
int si = 0; si <
states_.size(); ++si)
130 Eigen::VectorXd full_term;
152 logger().warn(
"Inverse eval is not implemented in {}; falling back to zero.",
name());
main class that contains the polyfem solver and all its state
Eigen::VectorXd apply_jacobian(const Eigen::VectorXd &grad_full, const Eigen::VectorXd &x) const override
Apply jacobian for chain rule.
Eigen::VectorXd inverse_eval(const Eigen::VectorXd &y) const override
Eval x = f^-1 (y).
int inverse_size(int y_size) const override
Compute DOF of x given DOF of y.
Eigen::VectorXd eval(const Eigen::VectorXd &x) const override
Eval y = f(x).
std::vector< std::shared_ptr< DiffCache > > DiffCachePtrs
CompositeParametrization parametrization_
Eigen::VectorXd apply_parametrization_jacobian(const Eigen::VectorXd &term, const Eigen::VectorXd &x) const override
Apply parametrization jacobian to compute the gradient w.r.t.
ParameterType parameter_type() const override
std::string name() const override
DiffCachePtrs diff_caches_
void update(const Eigen::VectorXd &x) override
Update forward simulation states from optimization variables.
std::vector< std::shared_ptr< legacy::State > > StatePtrs
Eigen::VectorXi active_geom_nodes_
int inverse_dof() const override
Compute optimization variables dof.
Eigen::VectorXd compute_adjoint_term(const Eigen::VectorXd &x) const override
Compute adjoint contribution of objective gradient.
void update_state_variables(const Eigen::VectorXd &x, Eigen::VectorXd &state_variables) const override
Update state variables from optimization variables.
Eigen::VectorXd inverse_eval() const override
Compute optimization variables from forward simulation legacy::State.
bool affect_state(const legacy::State &target) const override
Return true if current var2sim maps to target state.
DirichletNodesVariableToSimulation(StatePtrs states, DiffCachePtrs diff_caches, CompositeParametrization parametrizations, Eigen::VectorXi active_geom_nodes)
Construct DirichletNodesVariableToSimulation.
bool is_active_dirichlet_node_valid(const Eigen::VectorXi &active_dirichlet_nodes, const std::vector< std::shared_ptr< legacy::State > > &states, std::string &reason)
Validate active Dirichlet node ids selection given states.
Eigen::MatrixXd unflatten(const Eigen::VectorXd &x, int dim)
Unflatten rowwises, so every dim elements in x become a row.
spdlog::logger & logger()
Retrieves the current logger.
void log_and_throw_adjoint_error(const std::string &msg)
Eigen::MatrixXd get_adjoint_mat(const legacy::State &state, const DiffCache &diff_cache, int type)
Get adjoint parameter nu or p.