Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
CoreTypes.hpp
Go to the documentation of this file.
1#pragma once
2
12
13#include <concepts>
14#include <cstdint>
15#include <string>
16
17// Re-export Janus types and concepts
18#include <janus/core/JanusConcepts.hpp>
19#include <janus/core/JanusTypes.hpp>
20
21namespace icarus {
22
23// =============================================================================
24// Build Mode Detection
25// =============================================================================
26
28#ifdef ICARUS_DEBUG
29constexpr bool kDebugMode = true;
30#else
31constexpr bool kDebugMode = false;
32#endif
33
34// =============================================================================
35// Janus Type Re-exports
36// =============================================================================
37
38// Matrix and vector types (templated on Scalar)
39using janus::JanusMatrix;
40using janus::JanusVector;
41
42// Fixed-size types
43using janus::Mat2;
44using janus::Mat3;
45using janus::Mat4;
46using janus::Vec2;
47using janus::Vec3;
48using janus::Vec4;
49
50// Concrete backend types
51using janus::NumericMatrix;
52using janus::NumericScalar;
53using janus::NumericVector;
54using janus::SymbolicMatrix;
55using janus::SymbolicScalar;
56using janus::SymbolicVector;
57
58// Sparse types (numeric only)
59using janus::SparseMatrix;
60using janus::SparseTriplet;
61
62// Symbolic variable creation
63using janus::as_mx;
64using janus::as_vector;
65using janus::sym;
66using janus::sym_vec;
67using janus::sym_vector;
68using janus::to_eigen;
69using janus::to_mx;
70
71// =============================================================================
72// Scalar Concepts
73// =============================================================================
74
81using janus::JanusScalar;
82
88template <typename T>
89concept IcarusScalar = JanusScalar<T>;
90
91// =============================================================================
92// Simulation Lifecycle
93// =============================================================================
94
107
108// =============================================================================
109// Configuration Structures
110// =============================================================================
111
112// ComponentConfig with typed accessors is now in its own header
113// (Phase 4.0: Configuration Infrastructure)
114
120struct RunConfig {
121 double t_start = 0.0;
122 double t_end = 10.0;
123 double dt = 0.001;
124 bool equilibrium = false;
125 // Additional fields for ICs, Monte Carlo, etc.
126};
127
128// =============================================================================
129// Version Information
130// =============================================================================
131
132// Single source of truth for version numbers
133#define ICARUS_VERSION_MAJOR 0
134#define ICARUS_VERSION_MINOR 6
135#define ICARUS_VERSION_PATCH 0
136
137// Stringify helper
138#define ICARUS_STRINGIFY(x) #x
139#define ICARUS_VERSION_STR(major, minor, patch) \
140 ICARUS_STRINGIFY(major) "." ICARUS_STRINGIFY(minor) "." ICARUS_STRINGIFY(patch)
141
143constexpr int VersionMajor() { return ICARUS_VERSION_MAJOR; }
144
146constexpr int VersionMinor() { return ICARUS_VERSION_MINOR; }
147
149constexpr int VersionPatch() { return ICARUS_VERSION_PATCH; }
150
155
156// =============================================================================
157// Naming Utilities
158// =============================================================================
159
166inline std::string MakeFullPath(const std::string &entity, const std::string &name) {
167 if (entity.empty())
168 return name;
169 return entity + "." + name;
170}
171
172// =============================================================================
173// Component Concepts
174// =============================================================================
175
176// Forward declarations
177class ComponentConfig;
178template <typename Scalar> class Backplane;
179
188template <typename T, typename Scalar>
190 requires(T &c, Backplane<Scalar> &bp, const ComponentConfig &cfg, Scalar t, Scalar dt) {
191 // Component must have a name
192 { c.Name() } -> std::convertible_to<std::string>;
193
194 // Core lifecycle methods
195 { c.Provision(bp, cfg) } -> std::same_as<void>;
196 { c.Stage(bp, cfg) } -> std::same_as<void>;
197 { c.Step(t, dt) } -> std::same_as<void>;
198 };
199
203template <typename T, typename Scalar>
204concept ExtendedComponent = ComponentType<T, Scalar> && requires(T &c, Lifecycle lifecycle) {
205 { c.OnPhaseEnter(lifecycle) } -> std::same_as<void>;
206 { c.OnPhaseExit(lifecycle) } -> std::same_as<void>;
207};
208
209} // namespace icarus
210
211// =============================================================================
212// Debug Assertion Macros
213// =============================================================================
214
215#ifdef ICARUS_DEBUG
216
224#define ICARUS_ASSERT(cond, msg) \
225 do { \
226 if (!(cond)) { \
227 throw std::runtime_error(std::string("ICARUS_ASSERT failed: ") + (msg)); \
228 } \
229 } while (0)
230
235#define ICARUS_DEBUG_ONLY(code) code
236
242#define ICARUS_ASSERT_PTR(ptr, context) ICARUS_ASSERT((ptr) != nullptr, "Null pointer in " context)
243
250#define ICARUS_ASSERT_LIFECYCLE(lifecycle, required, operation) \
251 ICARUS_ASSERT((lifecycle) >= (required), std::string(operation) + \
252 " requires lifecycle state >= " + \
253 std::to_string(static_cast<int>(required)))
254
255#else // Release builds
256
257// All debug macros compile to nothing
258#define ICARUS_ASSERT(cond, msg) ((void)0)
259#define ICARUS_DEBUG_ONLY(code) ((void)0)
260#define ICARUS_ASSERT_PTR(ptr, context) ((void)0)
261#define ICARUS_ASSERT_LIFECYCLE(lifecycle, required, operation) ((void)0)
262
263#endif // ICARUS_DEBUG
#define ICARUS_VERSION_MINOR
Definition CoreTypes.hpp:134
#define ICARUS_VERSION_STR(major, minor, patch)
Definition CoreTypes.hpp:139
#define ICARUS_VERSION_MAJOR
Definition CoreTypes.hpp:133
#define ICARUS_VERSION_PATCH
Definition CoreTypes.hpp:135
Component-facing facade for signal registration and resolution.
Definition Backplane.hpp:32
Base class for all Icarus exceptions.
Definition Error.hpp:52
Concept for types that can serve as Icarus components.
Definition CoreTypes.hpp:189
Concept for components with optional extended hooks.
Definition CoreTypes.hpp:204
Alias for Icarus-specific documentation.
Definition CoreTypes.hpp:89
Definition AggregationTypes.hpp:13
constexpr int VersionPatch()
Patch version number.
Definition CoreTypes.hpp:149
std::string MakeFullPath(const std::string &entity, const std::string &name)
Build a full path from entity and name.
Definition CoreTypes.hpp:166
constexpr int VersionMinor()
Minor version number.
Definition CoreTypes.hpp:146
Lifecycle
Simulation lifecycle phases.
Definition CoreTypes.hpp:98
@ Completed
Simulation finished.
Definition CoreTypes.hpp:104
@ Provisioned
After Provision, before Stage.
Definition CoreTypes.hpp:100
@ Staged
After Stage, ready to run.
Definition CoreTypes.hpp:101
@ Running
During Step loop.
Definition CoreTypes.hpp:102
@ Paused
Temporarily halted.
Definition CoreTypes.hpp:103
@ Uninitialized
Before Provision.
Definition CoreTypes.hpp:99
constexpr bool kDebugMode
Check if we're in debug mode at compile time.
Definition CoreTypes.hpp:31
constexpr int VersionMajor()
Major version number.
Definition CoreTypes.hpp:143
constexpr const char * Version()
Version string (derived from components).
Definition CoreTypes.hpp:152
Configuration container for components.
Definition ComponentConfig.hpp:37
Run configuration for Stage phase.
Definition CoreTypes.hpp:120
double t_start
Simulation start time.
Definition CoreTypes.hpp:121
bool equilibrium
If true, run trim solver at Stage.
Definition CoreTypes.hpp:124
double t_end
Simulation end time.
Definition CoreTypes.hpp:122
double dt
Time step.
Definition CoreTypes.hpp:123