PolyFEM
Loading...
Searching...
No Matches
VariableToSimulationGroup.cpp
Go to the documentation of this file.
2
5
6namespace polyfem::solver
7{
8
9 void VariableToSimulationGroup::update(const Eigen::VectorXd &x)
10 {
11 for (auto &v2s : data)
12 {
13 v2s->update(x);
14 }
15 }
16
18 const legacy::State &target,
19 const Eigen::VectorXd &x,
20 Eigen::VectorXd &state_variable) const
21 {
22
23 for (const auto &v2s : data)
24 {
25 if (v2s->parameter_type() != type)
26 {
27 continue;
28 }
29 if (!v2s->affect_state(target))
30 {
31 continue;
32 }
33
34 // If multiple var2sim updates the same dof, the later will overwrite previous updates.
35 v2s->update_state_variables(x, state_variable);
36 }
37 }
38
39 Eigen::VectorXd VariableToSimulationGroup::compute_adjoint_term(const Eigen::VectorXd &x) const
40 {
41 Eigen::VectorXd adjoint_term = Eigen::VectorXd::Zero(x.size());
42 for (const auto &v2s : data)
43 {
44 adjoint_term += v2s->compute_adjoint_term(x);
45 }
46 return adjoint_term;
47 }
48
50 const legacy::State &target,
51 const Eigen::VectorXd &x,
52 const std::function<Eigen::VectorXd()> &grad) const
53 {
54 Eigen::VectorXd gradv = Eigen::VectorXd::Zero(x.size());
55 for (const auto &v2s : data)
56 {
57 if (v2s->parameter_type() != type)
58 {
59 continue;
60 }
61 if (!v2s->affect_state(target))
62 {
63 continue;
64 }
65
66 gradv += v2s->apply_parametrization_jacobian(grad(), x);
67 }
68 return gradv;
69 }
70
71} // namespace polyfem::solver
int x
main class that contains the polyfem solver and all its state
Definition State.hpp:114
Eigen::VectorXd compute_adjoint_term(const Eigen::VectorXd &x) const
Eigen::VectorXd apply_parametrization_jacobian(ParameterType type, const legacy::State &target, const Eigen::VectorXd &x, const std::function< Eigen::VectorXd()> &grad) const
Compute parametrization jacobian for all var2sim matching parameter type and output to target state.
void compute_state_variable(ParameterType type, const legacy::State &target, const Eigen::VectorXd &x, Eigen::VectorXd &state_variable) const
std::vector< std::shared_ptr< VariableToSimulation > > data