PolyFEM
Loading...
Searching...
No Matches
ImplicitNewmark.cpp
Go to the documentation of this file.
1#include "ImplicitNewmark.hpp"
2
4
6{
8 : ImplicitTimeIntegrator(dynamic_order)
9 {
10 if (dynamic_order != DynamicOrder::Second)
11 log_and_throw_error("ImplicitNewmark only supports second-order dynamics.");
12 }
13
15 {
16 gamma_ = params.at("gamma");
17 beta_ = params.at("beta");
18 }
19
20 void ImplicitNewmark::update_quantities(const Eigen::VectorXd &x)
21 {
22 const Eigen::VectorXd v = compute_velocity(x);
24 set_v_prev(v);
26 }
27
28 Eigen::VectorXd ImplicitNewmark::x_tilde() const
29 {
30 return x_prev() + dt() * (v_prev() + dt() * (0.5 - beta()) * a_prev());
31 }
32
33 Eigen::VectorXd ImplicitNewmark::compute_velocity(const Eigen::VectorXd &x) const
34 {
35 const double c = gamma() / beta();
36 return c / dt() * (x - x_prev()) + (1 - c) * v_prev() + (1 - c / 2) * dt() * a_prev();
37 }
38
39 Eigen::VectorXd ImplicitNewmark::compute_acceleration(const Eigen::VectorXd &v) const
40 {
41 return (v - v_prev() - (1 - gamma()) * dt() * a_prev()) / (gamma() * dt());
42 }
43
45 {
46 return beta() * dt() * dt();
47 }
48
49 double ImplicitNewmark::dv_dx(const unsigned prev_ti) const
50 {
51 // if (i == n_steps - 1)
52 // throw std::runtime_error("dv_dx is not defined for the last step");
53 const double c = gamma() / beta();
54 if (prev_ti == 0)
55 return c / dt();
56 return ((prev_ti == 1 ? (-c / dt()) : 0)
57 + (1 - c) * dv_dx(prev_ti - 1)
58 + (1 - c / 2) * dt() * da_dx(prev_ti - 1));
59 }
60
61 double ImplicitNewmark::da_dx(const unsigned prev_ti) const
62 {
63 // if (i == n_steps - 1)
64 // throw std::runtime_error("da_dx is not defined for the last step");
65 if (prev_ti == 0)
66 return dv_dx(prev_ti) / (gamma() * dt());
67 return (dv_dx(prev_ti)
68 - dv_dx(prev_ti - 1)
69 - (1 - gamma()) * dt() * da_dx(prev_ti - 1))
70 / (gamma() * dt());
71 }
72} // namespace polyfem::time_integrator
int x
double beta() const
parameter for blending accelerations in the solution update.
double acceleration_scaling() const override
Compute the acceleration scaling used to scale forces when integrating a second order ODE.
double da_dx(const unsigned prev_ti=0) const
double gamma_
parameter for blending accelerations in the velocity update.
double beta_
parameter for blending accelerations in the solution update.
Eigen::VectorXd x_tilde() const override
Compute the predicted solution to be used in the inertia term .
void set_parameters(const json &params) override
Set the gamma and beta parameters from a json object.
double gamma() const
parameter for blending accelerations in the velocity update.
Eigen::VectorXd compute_velocity(const Eigen::VectorXd &x) const override
Compute the current velocity given the current solution and using the stored previous solution(s).
ImplicitNewmark(const DynamicOrder dynamic_order=DynamicOrder::Second)
Eigen::VectorXd compute_acceleration(const Eigen::VectorXd &v) const override
Compute the current acceleration given the current velocity and using the stored previous velocity(s)...
double dv_dx(const unsigned prev_ti=0) const override
Compute the derivative of the velocity with respect to the solution.
void update_quantities(const Eigen::VectorXd &x) override
Update the time integration quantities (i.e., , , and ).
Implicit time integrator of a second order ODE (equivently a system of coupled first order ODEs).
const Eigen::VectorXd & v_prev() const
Get the most recent previous velocity value.
const Eigen::VectorXd & x_prev() const
Get the most recent previous solution value.
void set_a_prev(const Eigen::VectorXd &a_prev)
Convenience functions for setting the most recent previous acceleration.
void set_v_prev(const Eigen::VectorXd &v_prev)
Convenience functions for setting the most recent previous velocity.
const double & dt() const
Access the time step size.
const Eigen::VectorXd & a_prev() const
Get the most recent previous acceleration value.
void set_x_prev(const Eigen::VectorXd &x_prev)
Convenience functions for setting the most recent previous solution.
nlohmann::json json
Definition Common.hpp:9
void log_and_throw_error(const std::string &msg)
Definition Logger.cpp:73