PolyFEM
Loading...
Searching...
No Matches
ImplicitTimeIntegrator.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
4
5#include <Eigen/Core>
6
7#include <map>
8#include <functional>
9#include <vector>
10#include <deque>
11
12namespace polyfem::io
13{
14 class CheckpointReader;
15 class CheckpointWriter;
16} // namespace polyfem::io
17
19{
20 class BDF;
21
24 {
25 public:
26 enum class DynamicOrder
27 {
28 First,
29 Second,
30 };
31
34 virtual ~ImplicitTimeIntegrator() = default;
35
38 virtual void set_parameters(const json &params) {}
39
46 virtual void init(const Eigen::MatrixXd &x_prevs, const Eigen::MatrixXd &v_prevs, const Eigen::MatrixXd &a_prevs, double dt);
47
50 virtual void update_quantities(const Eigen::VectorXd &x) = 0;
51
54 virtual Eigen::VectorXd x_tilde() const = 0;
55
59 virtual Eigen::VectorXd compute_velocity(const Eigen::VectorXd &x) const = 0;
60
64 virtual Eigen::VectorXd compute_acceleration(const Eigen::VectorXd &v) const = 0;
65
68 virtual double acceleration_scaling() const = 0;
69
72 virtual double dv_dx(const unsigned prev_ti = 0) const = 0;
73
75 const double &dt() const { return dt_; }
77 int maximum_steps() const { return max_steps(); }
78
79 void serialize_checkpoint(io::CheckpointWriter &writer, const std::string &group) const;
81 const io::CheckpointReader &reader,
82 const std::string &group,
83 double expected_dt,
84 const std::function<void(Eigen::MatrixXd &)> &transform = {});
85
87 virtual void save_state(const std::string &state_path) const;
88
93 static std::shared_ptr<ImplicitTimeIntegrator> construct_time_integrator(
94 const json &params,
96
101 static std::shared_ptr<BDF> construct_bdf_integrator(
102 const json &params,
104
107 static const std::vector<std::string> &get_time_integrator_names();
108
110 const Eigen::VectorXd &x_prev() const { return x_prevs_.front(); }
112 const Eigen::VectorXd &v_prev() const { return v_prevs_.front(); }
114 const Eigen::VectorXd &a_prev() const { return a_prevs_.front(); }
115
117 const std::deque<Eigen::VectorXd> &x_prevs() const { return x_prevs_; }
119 const std::deque<Eigen::VectorXd> &v_prevs() const { return v_prevs_; }
121 const std::deque<Eigen::VectorXd> &a_prevs() const { return a_prevs_; }
122
124 int steps() const { return x_prevs_.size(); }
125
126 protected:
128
130 virtual int max_steps() const { return 1; }
131
134 double dt_ = 1;
135
137 std::deque<Eigen::VectorXd> x_prevs_;
139 std::deque<Eigen::VectorXd> v_prevs_;
141 std::deque<Eigen::VectorXd> a_prevs_;
142
144 void set_x_prev(const Eigen::VectorXd &x_prev) { x_prevs_.front() = x_prev; }
146 void set_v_prev(const Eigen::VectorXd &v_prev) { v_prevs_.front() = v_prev; }
148 void set_a_prev(const Eigen::VectorXd &a_prev) { a_prevs_.front() = a_prev; }
149 };
150} // namespace polyfem::time_integrator
int x
Implicit time integrator of a second order ODE (equivently a system of coupled first order ODEs).
const std::deque< Eigen::VectorXd > & v_prevs() const
Get the (relevant) history of previous velocity value.
const Eigen::VectorXd & v_prev() const
Get the most recent previous velocity value.
std::deque< Eigen::VectorXd > x_prevs_
Store the necessary previous values of the solution for single or multi-step integration.
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.
virtual Eigen::VectorXd compute_acceleration(const Eigen::VectorXd &v) const =0
Compute the current acceleration given the current velocity and using the stored previous velocity(s)...
const std::deque< Eigen::VectorXd > & a_prevs() const
Get the (relevant) history of previous acceleration value.
void set_v_prev(const Eigen::VectorXd &v_prev)
Convenience functions for setting the most recent previous velocity.
static std::shared_ptr< ImplicitTimeIntegrator > construct_time_integrator(const json &params, DynamicOrder dynamic_order=DynamicOrder::Second)
Factory method for constructing an implicit time integrator.
void serialize_checkpoint(io::CheckpointWriter &writer, const std::string &group) const
virtual int max_steps() const
Get the maximum number of steps to use for integration.
const double & dt() const
Access the time step size.
virtual void update_quantities(const Eigen::VectorXd &x)=0
Update the time integration quantities (i.e., , , and ).
void deserialize_checkpoint(const io::CheckpointReader &reader, const std::string &group, double expected_dt, const std::function< void(Eigen::MatrixXd &)> &transform={})
virtual Eigen::VectorXd compute_velocity(const Eigen::VectorXd &x) const =0
Compute the current velocity given the current solution and using the stored previous solution(s).
virtual void set_parameters(const json &params)
Set the time integrator parameters from a json object.
std::deque< Eigen::VectorXd > a_prevs_
Store the necessary previous values of the acceleration for single or multi-step integration.
static std::shared_ptr< BDF > construct_bdf_integrator(const json &params, DynamicOrder dynamic_order=DynamicOrder::Second)
Construct a BDF integrator for algorithms using BDF-specific operations.
const Eigen::VectorXd & a_prev() const
Get the most recent previous acceleration value.
virtual void init(const Eigen::MatrixXd &x_prevs, const Eigen::MatrixXd &v_prevs, const Eigen::MatrixXd &a_prevs, double dt)
Initialize the time integrator with the previous values for , , and .
const std::deque< Eigen::VectorXd > & x_prevs() const
Get the (relevant) history of previous solution value.
int steps() const
Get the current number of steps to use for integration.
void set_x_prev(const Eigen::VectorXd &x_prev)
Convenience functions for setting the most recent previous solution.
std::deque< Eigen::VectorXd > v_prevs_
Store the necessary previous values of the velocity for single or multi-step integration.
virtual double dv_dx(const unsigned prev_ti=0) const =0
Compute the derivative of the velocity with respect to the solution.
virtual double acceleration_scaling() const =0
Compute the acceleration scaling used to scale forces when integrating a second order ODE.
static const std::vector< std::string > & get_time_integrator_names()
Get a vector of the names of possible ImplicitTimeIntegrators.
virtual void save_state(const std::string &state_path) const
Legacy State persistence. Non-legacy code uses serialize_checkpoint().
virtual Eigen::VectorXd x_tilde() const =0
Compute the predicted solution to be used in the inertia term .
nlohmann::json json
Definition Common.hpp:9