PolyFEM
Loading...
Searching...
No Matches
StackedAugmentedLagrangianForm.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <memory>
6#include <vector>
7
8namespace polyfem::solver
9{
11 {
12 public:
13 class Block
14 {
16
17 public:
18 int id() const { return id_; }
19 int offset() const { return offset_; }
20 int size() const { return size_; }
21
22 private:
23 Block(const int id, const int offset, const int size)
24 : id_(id), offset_(offset), size_(size) {}
25
26 int id_ = -1;
27 int offset_ = 0;
28 int size_ = 0;
29 };
30
32
33 std::string name() const override { return "stacked-alagrangian"; }
34
35 Block add_block(const int size);
36 void add(const Block &block, std::shared_ptr<AugmentedLagrangianForm> form);
37
38 int size() const { return size_; }
39
40 void init(const Eigen::VectorXd &x) override;
41 void finish() override;
42 void update_quantities(const double t, const Eigen::VectorXd &x) override;
43
44 void update_lagrangian(const Eigen::VectorXd &x, const double k_al) override;
45 double compute_error(const Eigen::VectorXd &x) const override;
46
47 bool can_project() const override { return has_projection(); }
48 void project_gradient(Eigen::VectorXd &grad) const override;
49 void project_hessian(StiffnessMatrix &hessian) const override;
50 void project_diag(Eigen::VectorXd &diag) const override;
51
52 protected:
53 double value_unweighted(const Eigen::VectorXd &x) const override;
54 void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override;
55 void second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override;
56
57 private:
58 struct Term
59 {
60 int block = -1;
61 std::shared_ptr<AugmentedLagrangianForm> form;
62 };
63
64 void validate_block(const Block &block) const;
65 Eigen::VectorXd gather(const Eigen::VectorXd &x, const Term &term) const;
66 int global_index(const Term &term, const int local_index) const;
68 void sync_child_weights() const;
69
70 std::vector<Block> blocks_;
71 std::vector<Term> terms_;
72 int size_ = 0;
74 };
75} // namespace polyfem::solver
int x
int global_index(const Term &term, const int local_index) const
void project_hessian(StiffnessMatrix &hessian) const override
void init(const Eigen::VectorXd &x) override
Initialize the form.
double compute_error(const Eigen::VectorXd &x) const override
void update_quantities(const double t, const Eigen::VectorXd &x) override
Update time-dependent fields.
double value_unweighted(const Eigen::VectorXd &x) const override
Compute the value of the form.
void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
Compute the first derivative of the value wrt x.
void add(const Block &block, std::shared_ptr< AugmentedLagrangianForm > form)
void project_gradient(Eigen::VectorXd &grad) const override
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.
void project_diag(Eigen::VectorXd &diag) const override
Eigen::VectorXd gather(const Eigen::VectorXd &x, const Term &term) const
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:24