16 namespace time_integrator
19 const Eigen::MatrixXd &x_prevs,
20 const Eigen::MatrixXd &v_prevs,
21 const Eigen::MatrixXd &a_prevs,
33 for (
int i = 0; i < n; i++)
46 assert(!state_path.empty());
48 const int ndof =
x_prev().size();
49 const int prev_steps =
x_prevs().size();
51 Eigen::MatrixXd tmp(ndof, prev_steps);
53 for (
int i = 0; i < prev_steps; ++i)
57 for (
int i = 0; i < prev_steps; ++i)
61 for (
int i = 0; i < prev_steps; ++i)
70 const std::string type = params.is_object() ? params[
"type"] : params;
72 std::shared_ptr<ImplicitTimeIntegrator> integrator;
73 if (type ==
"implict_euler" || type ==
"ImplicitEuler")
75 integrator = std::make_shared<ImplicitEuler>(dynamic_order);
77 else if (type ==
"implict_newmark" || type ==
"ImplicitNewmark")
79 integrator = std::make_shared<ImplicitNewmark>(dynamic_order);
83 integrator = std::make_shared<BDF>(type ==
"BDF" ? 1 : std::stoi(type.substr(3)), dynamic_order);
87 logger().error(
"Unknown time integrator ({})", type);
88 throw std::runtime_error(fmt::format(
"Unknown time integrator ({})", type));
91 if (params.is_object())
92 integrator->set_parameters(params);
101 const std::string type = params.is_object() ? params[
"type"] : params;
102 if (type !=
"implict_euler" && type !=
"ImplicitEuler"
106 "BDF-specific transient formulations require ImplicitEuler or BDF, got {}.",
110 auto integrator = std::make_shared<BDF>(
112 ? std::stoi(type.substr(3))
115 if (params.is_object() && params.contains(
"steps"))
116 integrator->set_parameters(params);
122 static const std::vector<std::string> names = {
123 std::string(
"ImplicitEuler"),
124 std::string(
"ImplicitNewmark"),
const std::deque< Eigen::VectorXd > & v_prevs() const
Get the (relevant) history of 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.
const std::deque< Eigen::VectorXd > & a_prevs() const
Get the (relevant) history of previous acceleration value.
static std::shared_ptr< ImplicitTimeIntegrator > construct_time_integrator(const json ¶ms, DynamicOrder dynamic_order=DynamicOrder::Second)
Factory method for constructing an implicit time integrator.
virtual int max_steps() const
Get the maximum number of steps to use for integration.
const double & dt() const
Access the time step size.
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 ¶ms, DynamicOrder dynamic_order=DynamicOrder::Second)
Construct a BDF integrator for algorithms using BDF-specific operations.
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.
std::deque< Eigen::VectorXd > v_prevs_
Store the necessary previous values of the velocity for single or multi-step integration.
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
Save the values of , , and .
double dt_
Time step size.
bool write_matrix(const std::string &path, const Mat &mat)
Writes a matrix to a file. Determines the file format based on the path's extension.
bool startswith(const std::string &str, const std::string &prefix)
spdlog::logger & logger()
Retrieves the current logger.
void log_and_throw_error(const std::string &msg)