27 Eigen::VectorXi active_boundary_ids,
28 Eigen::VectorXi active_time_slices)
29 : is_transient_(states[0]->problem->is_time_dependent()),
31 states_(std::move(states)),
32 diff_caches_(std::move(diff_caches)),
33 parametrization_(std::move(parametrizations)),
34 active_boundary_ids_(std::move(active_boundary_ids)),
35 active_time_slices_(std::move(active_time_slices))
44 log_and_throw_adjoint_error(
"Fail to construct pressure boundary variable to simulation. Reason: inconsistent transient/static states.");
57 json boundary_json =
states_[0]->args[
"boundary_conditions"][
"pressure_boundary"];
61 tmp.push_back(bc[
"id"].get<int>());
104 if (s.get() == &target)
119 auto tensor_problem = std::dynamic_pointer_cast<polyfem::assembler::GenericTensorProblem>(s->problem);
133 tensor_problem->update_pressure_boundary(boundary_id, time_step,
y(ti *
active_boundary_ids_.size() + bi));
142 tensor_problem->update_pressure_boundary(boundary_id, 1,
y(bi));
156 Eigen::VectorXd term = Eigen::VectorXd::Zero(
para_out_dof());
163 for (
int si = 0; si <
states_.size(); ++si)
173 Eigen::VectorXd cur_term;
180 term.segment(ti * bnum, bnum) += cur_term.segment(slice * bnum, bnum);
186 Eigen::VectorXd cur_term;
188 assert(cur_term.size() == bnum);
207 json boundary_json =
states_[0]->args[
"boundary_conditions"][
"pressure_boundary"];
210 for (
int bi = 0; bi < bnum; ++bi)
214 auto pred = [boundary_id](
const json &bc) {
return bc[
"id"].get<
int>() == boundary_id; };
215 auto iter = std::find_if(boundaries.begin(), boundaries.end(), pred);
216 if (iter == boundaries.end())
218 logger().warn(
"Cannot find pressure boundary id {} in JSON; falling back to zero.", boundary_id);
222 const json &value = (*iter)[
"value"];
225 Eigen::VectorXd pressures;
230 catch (std::exception &err)
235 if (pressures.size() != required)
237 logger().warn(
"Unsupported initial value spec for pressure boundary id {}; falling back to zero.", boundary_id);
238 pressures = Eigen::VectorXd::Zero(required);
244 y(ti * bnum + bi) = pressures(slice + 1);
249 if (value.is_number())
251 y(bi) = value.get<
double>();
255 logger().warn(
"Unsupported initial value spec for pressure boundary id {}; falling back to zero.", boundary_id);
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).
Eigen::VectorXi active_boundary_ids_
void update(const Eigen::VectorXd &x) override
Update forward simulation states from optimization variables.
std::vector< std::shared_ptr< DiffCache > > DiffCachePtrs
DiffCachePtrs diff_caches_
Eigen::VectorXd compute_adjoint_term(const Eigen::VectorXd &x) const override
Compute adjoint contribution of objective gradient.
CompositeParametrization parametrization_
int inverse_dof() const override
Compute optimization variables dof.
ParameterType parameter_type() const override
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.
Eigen::VectorXi active_time_slices_
void update_state_variables(const Eigen::VectorXd &x, Eigen::VectorXd &state_variables) const override
Update state variables from optimization variables.
std::string name() const override
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.
PressureBoundaryVariableToSimulation(StatePtrs states, DiffCachePtrs diff_caches, CompositeParametrization parametrizations, Eigen::VectorXi active_boundary_ids, Eigen::VectorXi active_time_slices)
Construct ShapeVariableToSimulation.
std::vector< std::shared_ptr< legacy::State > > StatePtrs
bool is_active_time_slices_valid(const Eigen::VectorXi &active_time_slices, const std::vector< std::shared_ptr< legacy::State > > &states, std::string &reason)
Validate active time slices selection given states.
bool is_active_pressure_boundary_ids_valid(const Eigen::VectorXi &active_boundary_ids, const std::vector< std::shared_ptr< legacy::State > > &states, std::string &reason)
Validate active pressure boundary ids selection given states.
std::vector< T > json_as_array(const json &j)
Return the value of a json object as an array.
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.