PolyFEM
Loading...
Searching...
No Matches
InertiaForm.cpp
Go to the documentation of this file.
1#include "InertiaForm.hpp"
2
5
6#include <cassert>
7#include <utility>
8
9namespace polyfem::solver
10{
12 const time_integrator::ImplicitTimeIntegrator &time_integrator)
13 : mass_(mass), time_integrator_(time_integrator), x_tilde_(time_integrator.x_tilde())
14 {
15 assert(mass.size() != 0);
16 assert(x_tilde_.size() == mass.rows());
17 }
18
20 {
21 x_tilde_updater_ = std::move(updater);
22 }
23
24 Eigen::VectorXd InertiaForm::x_tilde() const
25 {
26 assert(x_tilde_.size() == mass_.rows());
27 return x_tilde_;
28 }
29
30 void InertiaForm::update_quantities(const double t, const Eigen::VectorXd &x)
31 {
33
36
37 assert(x_tilde_.size() == mass_.rows());
38 }
39
40 double InertiaForm::value_unweighted(const Eigen::VectorXd &x) const
41 {
42 const Eigen::VectorXd tmp = x - x_tilde();
43 const double prod = tmp.transpose() * mass_ * tmp;
44 const double energy = 0.5 * prod;
45 return energy;
46 }
47
48 void InertiaForm::first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
49 {
50 gradv = mass_ * (x - x_tilde());
51 }
52
53 void InertiaForm::second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const
54 {
55 hessian = mass_;
56 }
57} // namespace polyfem::solver
int x
double value_unweighted(const Eigen::VectorXd &x) const override
Compute the value of the form.
void set_x_tilde_updater(XTildeUpdater updater)
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.
void update_quantities(const double t, const Eigen::VectorXd &x) override
Update time-dependent fields.
Eigen::VectorXd x_tilde() const
InertiaForm(const StiffnessMatrix &mass, const time_integrator::ImplicitTimeIntegrator &time_integrator)
Construct a new Inertia Form object.
const time_integrator::ImplicitTimeIntegrator & time_integrator_
Time integrator.
const StiffnessMatrix & mass_
Mass matrix.
std::function< void(const double, const Eigen::VectorXd &, Eigen::VectorXd &)> XTildeUpdater
Implicit time integrator of a second order ODE (equivently a system of coupled first order ODEs).
virtual Eigen::VectorXd x_tilde() const =0
Compute the predicted solution to be used in the inertia term .
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:24