Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
IntegratorTypes.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <algorithm>
11#include <cctype>
13#include <stdexcept>
14#include <string>
15
16namespace icarus {
17
18// =============================================================================
19// Integrator Type Enumeration
20// =============================================================================
21
33
37[[nodiscard]] inline std::string to_string(IntegratorType type) {
38 switch (type) {
40 return "Euler";
42 return "RK2";
44 return "RK4";
46 return "RK45";
47 }
48 return "Unknown";
49}
50
56[[nodiscard]] inline IntegratorType parse_integrator_type(const std::string &name) {
57 std::string lower = name;
58 std::transform(lower.begin(), lower.end(), lower.begin(),
59 [](unsigned char c) { return std::tolower(c); });
60
61 if (lower == "euler")
63 if (lower == "rk2")
65 if (lower == "rk4")
67 if (lower == "rk45")
69 throw std::invalid_argument("Unknown integrator type: " + name);
70}
71
72// =============================================================================
73// Integrator Configuration
74// =============================================================================
75
83template <typename Scalar> struct IntegratorConfig {
85
86 // Adaptive stepping parameters (RK45 only)
87 Scalar abs_tol = Scalar{1e-6};
88 Scalar rel_tol = Scalar{1e-6};
89 Scalar min_dt = Scalar{1e-10};
90 Scalar max_dt = Scalar{1.0};
91 Scalar safety_factor = Scalar{0.9};
92
99 return cfg;
100 }
101
105 static IntegratorConfig RK45Adaptive(Scalar abs_tol_val = Scalar{1e-6},
106 Scalar rel_tol_val = Scalar{1e-6}) {
107 IntegratorConfig cfg;
108 cfg.type = IntegratorType::RK45;
109 cfg.abs_tol = abs_tol_val;
110 cfg.rel_tol = rel_tol_val;
111 return cfg;
112 }
113
119 cfg.type = method;
120 return cfg;
121 }
122};
123
124} // namespace icarus
Core type definitions, concepts, and configuration for Icarus.
Definition AggregationTypes.hpp:13
const char * to_string(SignalKind kind)
Convert SignalKind to string.
Definition Signal.hpp:86
IntegratorType
Available integrator methods.
Definition IntegratorTypes.hpp:27
@ 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
static IntegratorConfig RK45Adaptive(Scalar abs_tol_val=Scalar{1e-6}, Scalar rel_tol_val=Scalar{1e-6})
Create adaptive RK45 config with tolerances.
Definition IntegratorTypes.hpp:105
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