PolyFEM
Loading...
Searching...
No Matches
GrowthDissipationForm.cpp
Go to the documentation of this file.
2
4
5#include <algorithm>
6
7namespace polyfem::solver
8{
10 const Eigen::VectorXd &weights,
11 const Eigen::VectorXd &theta_n,
12 const double floor_fraction)
13 : weights_(weights), theta_n_(theta_n)
14 {
15 if (weights_.size() != theta_n_.size())
16 log_and_throw_error("GrowthDissipationForm: {} weights for {} growth DOFs.", weights_.size(), theta_n_.size());
17 if (!(floor_fraction > 0 && floor_fraction < 1))
18 log_and_throw_error("GrowthDissipationForm: floor_fraction must lie in (0, 1), got {}.", floor_fraction);
19 if ((theta_n_.array() <= 0).any())
20 log_and_throw_error("GrowthDissipationForm: theta_n must be positive (min {}).", theta_n_.minCoeff());
21 floor_ = floor_fraction * theta_n_;
22 }
23
24 double GrowthDissipationForm::value_unweighted(const Eigen::VectorXd &x) const
25 {
26 assert(x.size() == weights_.size());
27 return weights_.dot(x - theta_n_);
28 }
29
30 void GrowthDissipationForm::first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
31 {
32 assert(x.size() == weights_.size());
33 gradv = weights_;
34 }
35
37 {
38 hessian.resize(x.size(), x.size());
39 hessian.setZero();
40 }
41
42 double GrowthDissipationForm::max_step_size(const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const
43 {
44 // Largest alpha in (0, 1] with x0 + alpha (x1 - x0) >= floor. A DOF
45 // already below its floor (only possible from outside data) is ignored
46 // here and rejected by is_step_valid; returning 0 would abort the line
47 // search outright.
48 double alpha = 1.0;
49 for (int i = 0; i < x0.size(); ++i)
50 {
51 const double dx = x1(i) - x0(i);
52 if (dx >= 0 || x0(i) <= floor_(i))
53 continue;
54 alpha = std::min(alpha, (floor_(i) - x0(i)) / dx * 0.99);
55 }
56 return std::max(alpha, 0.0);
57 }
58
59 bool GrowthDissipationForm::is_step_valid(const Eigen::VectorXd &, const Eigen::VectorXd &x1) const
60 {
61 return (x1.array() > 0).all();
62 }
63} // namespace polyfem::solver
LocalHessian hessian
std::vector< std::pair< int, double > > weights
int x
void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
Compute the first derivative of the value wrt x.
double max_step_size(const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override
Determine the maximum step size allowable between the current and next solution.
void second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override
Compute the second derivative of the value wrt x.
bool is_step_valid(const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override
Determine if a step from solution x0 to solution x1 is allowed.
GrowthDissipationForm(const Eigen::VectorXd &weights, const Eigen::VectorXd &theta_n, const double floor_fraction)
double value_unweighted(const Eigen::VectorXd &x) const override
Compute the value of the form.
void log_and_throw_error(const std::string &msg)
Definition Logger.cpp:73
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:24