27 Eigen::VectorXi active_boundary_ids,
28 Eigen::VectorXi active_time_slices)
29 : is_transient_(varforms[0]->get_problem().is_time_dependent()),
31 varforms_(std::move(varforms)),
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))
42 if (varform->get_problem().is_time_dependent() !=
is_transient_)
44 log_and_throw_adjoint_error(
"Fail to construct pressure boundary variable to simulation. Reason: inconsistent transient/static varforms.");
57 json boundary_json =
varforms_[0]->get_args()[
"boundary_conditions"][
"pressure_boundary"];
61 tmp.push_back(bc[
"id"].get<int>());
104 if (varform.get() == &target)
136 varform->set_pressure_boundary(boundary_id, 1,
y(bi));
150 Eigen::VectorXd term = Eigen::VectorXd::Zero(
para_out_dof());
157 for (
int si = 0; si <
varforms_.size(); ++si)
165 Eigen::MatrixXd adjoint_nu =
get_adjoint_mat(*varform, *diff_cache, 1);
167 Eigen::VectorXd cur_term;
174 term.segment(ti * bnum, bnum) += cur_term.segment(slice * bnum, bnum);
180 Eigen::VectorXd cur_term;
182 assert(cur_term.size() == bnum);
201 json boundary_json =
varforms_[0]->get_args()[
"boundary_conditions"][
"pressure_boundary"];
204 for (
int bi = 0; bi < bnum; ++bi)
208 auto pred = [boundary_id](
const json &bc) {
return bc[
"id"].get<
int>() == boundary_id; };
209 auto iter = std::find_if(boundaries.begin(), boundaries.end(), pred);
210 if (iter == boundaries.end())
212 logger().warn(
"Cannot find pressure boundary id {} in JSON; falling back to zero.", boundary_id);
216 const json &value = (*iter)[
"value"];
219 Eigen::VectorXd pressures;
224 catch (std::exception &err)
229 if (pressures.size() != required)
231 logger().warn(
"Unsupported initial value spec for pressure boundary id {}; falling back to zero.", boundary_id);
232 pressures = Eigen::VectorXd::Zero(required);
238 y(ti * bnum + bi) = pressures(slice + 1);
243 if (value.is_number())
245 y(bi) = value.get<
double>();
249 logger().warn(
"Unsupported initial value spec for pressure boundary id {}; falling back to zero.", boundary_id);
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).
PressureBoundaryVariableToSimulation(VarFormPtrs varforms, DiffCachePtrs diff_caches, CompositeParametrization parametrizations, Eigen::VectorXi active_boundary_ids, Eigen::VectorXi active_time_slices)
Construct ShapeVariableToSimulation.
Eigen::VectorXi active_boundary_ids_
void update(const Eigen::VectorXd &x) override
Update forward simulation varforms 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.
std::vector< std::shared_ptr< varform::DifferentiableVarForm > > VarFormPtrs
bool affects_varform(const varform::DifferentiableVarForm &target) const override
Return true if current var2sim maps to target varform.
Eigen::VectorXi active_time_slices_
void update_state_variables(const Eigen::VectorXd &x, Eigen::VectorXd &state_variables) const override
Update varform variables from optimization variables.
std::string name() const override
Eigen::VectorXd inverse_eval() const override
Compute optimization variables from forward simulation varform::DifferentiableVarForm.
bool is_active_time_slices_valid(const Eigen::VectorXi &active_time_slices, const std::vector< std::shared_ptr< varform::DifferentiableVarForm > > &varforms, std::string &reason)
Validate active time slices selection given varforms.
bool is_active_pressure_boundary_ids_valid(const Eigen::VectorXi &active_boundary_ids, const std::vector< std::shared_ptr< varform::DifferentiableVarForm > > &varforms, std::string &reason)
Validate active pressure boundary ids selection given varforms.
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 varform::DifferentiableVarForm &varform, const DiffCache &diff_cache, int type)
Get adjoint parameter nu or p.