Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
IntegratorFactory.hpp
Go to the documentation of this file.
1#pragma once
2
9
14#include <memory>
15#include <stdexcept>
16
17namespace icarus {
18
27template <typename Scalar> class IntegratorFactory {
28 public:
35 static std::unique_ptr<Integrator<Scalar>> Create(const IntegratorConfig<Scalar> &config) {
36 switch (config.type) {
38 return std::make_unique<EulerIntegrator<Scalar>>();
39
41 return std::make_unique<RK2Integrator<Scalar>>();
42
44 return std::make_unique<RK4Integrator<Scalar>>();
45
47 auto rk45 = std::make_unique<RK45Integrator<Scalar>>(config.abs_tol, config.rel_tol);
48 rk45->SetMinDt(config.min_dt);
49 rk45->SetMaxDt(config.max_dt);
50 rk45->SetSafetyFactor(config.safety_factor);
51 return rk45;
52 }
53 }
54 throw std::invalid_argument("Unknown integrator type");
55 }
56
62 static std::unique_ptr<Integrator<Scalar>> Create(const std::string &type_name) {
64 }
65
69 static std::unique_ptr<Integrator<Scalar>> CreateDefault() {
71 }
72};
73
74} // namespace icarus
Integrator type enumeration and configuration.
Abstract interface for numerical integrators.
Adaptive Dormand-Prince RK45 integrator.
Fixed-step integrators: Euler, RK2, RK4.
Factory for creating integrators from configuration.
Definition IntegratorFactory.hpp:27
static std::unique_ptr< Integrator< Scalar > > CreateDefault()
Create default integrator (RK4).
Definition IntegratorFactory.hpp:69
static std::unique_ptr< Integrator< Scalar > > Create(const std::string &type_name)
Create integrator from type name string.
Definition IntegratorFactory.hpp:62
static std::unique_ptr< Integrator< Scalar > > Create(const IntegratorConfig< Scalar > &config)
Create integrator from configuration.
Definition IntegratorFactory.hpp:35
Definition AggregationTypes.hpp:13
@ Euler
Forward Euler (1st order, 1 eval) - janus::euler_step.
Definition IntegratorTypes.hpp:28
@ RK45
Dormand-Prince adaptive (5th order, 7 evals) - janus::rk45_step.
Definition IntegratorTypes.hpp:31
@ RK2
Heun's method (2nd order, 2 evals) - janus::rk2_step.
Definition IntegratorTypes.hpp:29
@ RK4
Classic RK4 (4th order, 4 evals) - janus::rk4_step.
Definition IntegratorTypes.hpp:30
IntegratorType parse_integrator_type(const std::string &name)
Parse integrator type from string (case-insensitive).
Definition IntegratorTypes.hpp:56
Configuration for integrator creation.
Definition IntegratorTypes.hpp:83
Scalar rel_tol
Relative tolerance.
Definition IntegratorTypes.hpp:88
static IntegratorConfig RK4Default()
Create default RK4 config.
Definition IntegratorTypes.hpp:96
Scalar max_dt
Maximum step size.
Definition IntegratorTypes.hpp:90
static IntegratorConfig ForMethod(IntegratorType method)
Create config for specified method.
Definition IntegratorTypes.hpp:117
Scalar min_dt
Minimum step size.
Definition IntegratorTypes.hpp:89
Scalar abs_tol
Absolute tolerance.
Definition IntegratorTypes.hpp:87
IntegratorType type
Method to use.
Definition IntegratorTypes.hpp:84
Scalar safety_factor
Step size safety factor.
Definition IntegratorTypes.hpp:91