Loading [MathJax]/jax/input/TeX/config.js
PolyFEM
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatrixLagrangianForm.cpp
Go to the documentation of this file.
2
5
6namespace polyfem::solver
7{
8
10 const Eigen::MatrixXd &b,
11 const StiffnessMatrix &A_proj,
12 const Eigen::MatrixXd &b_proj)
13 {
14 A_ = A;
15 b_ = b;
16 A_proj_ = A_proj;
17 b_proj_ = b_proj;
18
19 assert(A_.rows() == b_.rows());
20 AtA = A_.transpose() * A_;
21 Atb = A_.transpose() * b_;
22
23 lagr_mults_.resize(A_.rows());
24 lagr_mults_.setZero();
25 }
26
27 double MatrixLagrangianForm::value_unweighted(const Eigen::VectorXd &x) const
28 {
29 const Eigen::VectorXd res = A_ * x - b_;
30 const double L_penalty = lagr_mults_.transpose() * res;
31 const double A_penalty = res.squaredNorm() / 2;
32 return L_weight() * L_penalty + A_weight() * A_penalty;
33 }
34
35 void MatrixLagrangianForm::first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
36 {
37 gradv = L_weight() * A_.transpose() * lagr_mults_ + A_weight() * (AtA * x - Atb);
38 }
39
40 void MatrixLagrangianForm::second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const
41 {
42 hessian = A_weight() * AtA;
43 }
44
45 void MatrixLagrangianForm::update_lagrangian(const Eigen::VectorXd &x, const double k_al)
46 {
47 k_al_ = k_al;
48 lagr_mults_ += k_al * (A_ * x - b_);
49 }
50
51 double MatrixLagrangianForm::compute_error(const Eigen::VectorXd &x) const
52 {
53 const Eigen::VectorXd res = A_ * x - b_;
54 return res.squaredNorm();
55 }
56
57} // namespace polyfem::solver
int x
Eigen::VectorXd lagr_mults_
vector of lagrange multipliers
StiffnessMatrix A_proj_
Constraints projection matrix.
Eigen::MatrixXd b_proj_
Constraints projection value.
void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
Compute the first derivative of the value wrt x.
void update_lagrangian(const Eigen::VectorXd &x, const double k_al) override
void second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override
Compute the second derivative of the value wrt x.
double compute_error(const Eigen::VectorXd &x) const override
double value_unweighted(const Eigen::VectorXd &x) const override
Compute the value of the form.
MatrixLagrangianForm(const StiffnessMatrix &A, const Eigen::MatrixXd &b, const StiffnessMatrix &A_proj={}, const Eigen::MatrixXd &b_pro={})
Construct a new MatrixLagrangianForm object for the constraints Ax = b, where A is sparse.
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:22