21 : dim_(states[0]->mesh->dimension()),
22 vertex_num_(states[0]->mesh->n_vertices()),
23 states_(std::move(states)),
24 diff_caches_(std::move(diff_caches)),
25 parametrization_(std::move(parametrizations))
32 if (s->mesh->dimension() !=
dim_)
34 log_and_throw_adjoint_error(
"Fail to construct periodic shape variable to simulation. Reason: mesh dimension mismatch between states.");
38 log_and_throw_adjoint_error(
"Fail to construct periodic shape variable to simulation. Reason: mesh vertex num mismatch between states.");
40 if (s->problem->is_time_dependent())
42 log_and_throw_adjoint_error(
"Fail to construct periodic shape variable to simulation. Reason: transient simulations are not supported.");
44 if (!s->has_periodic_bc() || s->periodic_bc ==
nullptr)
46 log_and_throw_adjoint_error(
"Fail to construct periodic shape variable to simulation. Reason: periodic boundary conditions are not enabled.");
48 if (!s->periodic_bc->all_direction_periodic())
50 log_and_throw_adjoint_error(
"Fail to construct periodic shape variable to simulation. Reason: partial periodicity is not supported.");
52 if (!s->is_homogenization())
54 log_and_throw_adjoint_error(
"Fail to construct periodic shape variable to simulation. Reason: only homogenization problems are supported.");
65 return "periodic-shape";
77 if (s.get() == &target)
93 s->mesh->set_point(i,
V.row(i));
108 Eigen::VectorXd term, cur_term;
109 for (
int i = 0; i <
states_.size(); ++i)
125 if (term.size() != cur_term.size())
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).
void update(const Eigen::VectorXd &x) override
Update forward simulation states from optimization variables.
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 apply_parametrization_jacobian(const Eigen::VectorXd &term, const Eigen::VectorXd &x) const override
Apply parametrization jacobian to compute the gradient w.r.t.
std::unique_ptr< PeriodicMeshToMesh > periodic_mesh_map_
std::vector< std::shared_ptr< DiffCache > > DiffCachePtrs
DiffCachePtrs diff_caches_
CompositeParametrization parametrization_
ParameterType parameter_type() const override
int inverse_dof() const override
Compute optimization variables dof.
PeriodicShapeVariableToSimulation(StatePtrs states, DiffCachePtrs diff_caches, CompositeParametrization parametrizations)
Construct PeriodicShapeVariableToSimulation.
bool affect_state(const legacy::State &target) const override
Return true if current var2sim maps to target state.
Eigen::VectorXd inverse_eval() const override
Compute optimization variables from forward simulation legacy::State.
std::vector< std::shared_ptr< legacy::State > > StatePtrs
std::string name() const override
Eigen::MatrixXd unflatten(const Eigen::VectorXd &x, int dim)
Unflatten rowwises, so every dim elements in x become a row.
Eigen::VectorXd flatten(const Eigen::MatrixXd &X)
Flatten rowwises.
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.