PolyFEM
Loading...
Searching...
No Matches
MacroStrainLagrangianForm.cpp
Go to the documentation of this file.
3
4namespace polyfem::solver
5{
7 : AugmentedLagrangianForm(std::vector<int>()),
8 macro_strain_constraint_(macro_strain_constraint)
9 {
11 }
12
13 double MacroStrainLagrangianForm::value_unweighted(const Eigen::VectorXd &x) const
14 {
15 const Eigen::VectorXi indices = macro_strain_constraint_.get_fixed_entry().array() + (x.size() - macro_strain_constraint_.dim() * macro_strain_constraint_.dim());
16 const double larg = lagr_mults_.transpose() * (x(indices) - values);
17 const double pen = (x(indices) - values).squaredNorm() / 2.0;
18
19 return larg + k_al_ * pen;
20 }
21
22 void MacroStrainLagrangianForm::first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
23 {
24 const Eigen::VectorXi indices = macro_strain_constraint_.get_fixed_entry().array() + (x.size() - macro_strain_constraint_.dim() * macro_strain_constraint_.dim());
25 gradv.setZero(x.size());
26 gradv(indices) = lagr_mults_ + k_al_ * (x(indices) - values);
27 }
28
30 {
31 const Eigen::VectorXi indices = macro_strain_constraint_.get_fixed_entry().array() + (x.size() - macro_strain_constraint_.dim() * macro_strain_constraint_.dim());
32 hessian.resize(x.size(), x.size());
33 hessian.setZero();
34 for (int i = 0; i < indices.size(); i++)
35 hessian.coeffRef(indices(i), indices(i)) += k_al_;
36 }
37
38 void MacroStrainLagrangianForm::update_quantities(const double t, const Eigen::VectorXd &)
39 {
42 }
43
44 double MacroStrainLagrangianForm::compute_error(const Eigen::VectorXd &x) const
45 {
46 const Eigen::VectorXi indices = macro_strain_constraint_.get_fixed_entry().array() + (x.size() - macro_strain_constraint_.dim() * macro_strain_constraint_.dim());
47 return (x(indices).array() - values.array()).matrix().squaredNorm();
48 }
49
50 void MacroStrainLagrangianForm::update_lagrangian(const Eigen::VectorXd &x, const double k_al)
51 {
52 k_al_ = k_al;
53
54 const Eigen::VectorXi indices = macro_strain_constraint_.get_fixed_entry().array() + (x.size() - macro_strain_constraint_.dim() * macro_strain_constraint_.dim());
55 lagr_mults_ += k_al * (x(indices) - values);
56 }
57} // namespace polyfem::solver
int x
Eigen::MatrixXd eval(const double t) const
const Eigen::VectorXi & get_fixed_entry() const
void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
Compute the first derivative of the value wrt x.
void second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override
Compute the second derivative of the value wrt x.
double value_unweighted(const Eigen::VectorXd &x) const override
Compute the contact barrier potential value.
Eigen::VectorXd lagr_mults_
vector of lagrange multipliers
void update_lagrangian(const Eigen::VectorXd &x, const double k_al) override
const assembler::MacroStrainValue & macro_strain_constraint_
double compute_error(const Eigen::VectorXd &x) const override
void update_quantities(const double t, const Eigen::VectorXd &x) override
Update time-dependent fields.
MacroStrainLagrangianForm(const assembler::MacroStrainValue &macro_strain_constraint)
Construct a new MacroStrainLagrangianForm object.
Eigen::VectorXd flatten(const Eigen::MatrixXd &X)
Flatten rowwises.
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:22