Oakfield API Documentation 1.0.0
Numerical core APIs
Loading...
Searching...
No Matches
sim_runtime_state.h
Go to the documentation of this file.
1
5#ifndef OAKFIELD_SIM_RUNTIME_STATE_H
6#define OAKFIELD_SIM_RUNTIME_STATE_H
7
8#include <stdbool.h>
9#include <stddef.h>
10#include <stdint.h>
11
12#include "field.h"
15#include "sim_flux_lens.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#ifndef SIM_RUNTIME_DEFAULT_DT
22#define SIM_RUNTIME_DEFAULT_DT 0.0166667f
23#endif
24
25#define SIM_RUNTIME_VIS_DOWNSAMPLE_TARGET_DEFAULT 4096U
26#define SIM_RUNTIME_VIS_DOWNSAMPLE_MAX_DEFAULT 16384U
27#define SIM_RUNTIME_VIS_DOWNSAMPLE_TARGET_MIN 64U
28#define SIM_RUNTIME_VIS_DOWNSAMPLE_TARGET_MAX 65536U
29
37
54
64
76
78#define SIM_STEP_METRIC_HISTORY 128U
79
102
115
128
138
151
165
191
195typedef struct SimRuntimeState {
196 double dt;
198 size_t step_index;
262 size_t
280 size_t
290
298
305
314
321
329
338 SimStepMetrics *out_metrics);
339
349 size_t capacity);
350
358
366
375
383
390
400 SimRuntimeLoopErrorSource source, size_t step_index);
401
410 SimRuntimeLoopError *out_error);
411
419
426
434
442
449
456
463
471
479 const SimRuntimeLoopProgress *progress);
480
487
496 SimRuntimeLoopProgress *out_progress);
497
506 SimRuntimeLoopProgress *out_progress);
507
514
522
530
538
546
547#ifdef __cplusplus
548}
549#endif
550
551#endif /* OAKFIELD_SIM_RUNTIME_STATE_H */
Multidimensional contiguous field abstraction with configurable layout.
SimResult
Return codes shared by libsimcore modules.
Definition field.h:29
Runtime field-statistics configuration, accumulation, and profiling helpers.
Runtime cache and texture-packing state for field-topology extraction.
Flux lens state and skew-Burgers flux utilities.
SimRuntimeLoopStopReason
Last observed terminal/non-running reason for a managed loop.
Definition sim_runtime_state.h:106
@ SIM_RUNTIME_LOOP_STOP_REASON_MAX_WALL_MS_REACHED
Definition sim_runtime_state.h:112
@ SIM_RUNTIME_LOOP_STOP_REASON_STEPS_EXHAUSTED
Definition sim_runtime_state.h:110
@ SIM_RUNTIME_LOOP_STOP_REASON_PAUSED
Definition sim_runtime_state.h:108
@ SIM_RUNTIME_LOOP_STOP_REASON_NONE
Definition sim_runtime_state.h:107
@ SIM_RUNTIME_LOOP_STOP_REASON_RUNTIME_ERROR
Definition sim_runtime_state.h:113
@ SIM_RUNTIME_LOOP_STOP_REASON_CANCELLED
Definition sim_runtime_state.h:109
@ SIM_RUNTIME_LOOP_STOP_REASON_MAX_SIM_TIME_REACHED
Definition sim_runtime_state.h:111
SimTimeModel
Time evolution model for the simulation.
Definition sim_runtime_state.h:71
@ SIM_TIME_MODEL_CONTINUOUS
Definition sim_runtime_state.h:72
@ SIM_TIME_MODEL_MAP
Definition sim_runtime_state.h:74
const char * sim_runtime_caller_step_mode_name(SimRuntimeCallerStepMode mode)
Convert a caller-owned step mode to a stable machine-readable name.
const char * sim_runtime_loop_error_source_name(SimRuntimeLoopErrorSource source)
Convert a loop error source to a stable machine-readable name.
size_t sim_runtime_state_caller_step_streak(const SimRuntimeState *state)
Fetch the consecutive caller-owned step streak.
size_t sim_runtime_state_copy_step_metrics(const SimRuntimeState *state, SimStepMetrics *dest, size_t capacity)
Copy up to capacity samples into dest ordered from oldest to newest.
SimRuntimeLoopErrorSource
Origin of the most recent loop/runtime failure.
Definition sim_runtime_state.h:119
@ SIM_RUNTIME_LOOP_ERROR_SOURCE_OPERATOR_EXECUTION
Definition sim_runtime_state.h:123
@ SIM_RUNTIME_LOOP_ERROR_SOURCE_NONE
Definition sim_runtime_state.h:120
@ SIM_RUNTIME_LOOP_ERROR_SOURCE_INTEGRATOR_BRIDGE
Definition sim_runtime_state.h:124
@ SIM_RUNTIME_LOOP_ERROR_SOURCE_SCHEDULER_STEP
Definition sim_runtime_state.h:121
@ SIM_RUNTIME_LOOP_ERROR_SOURCE_INTEGRATOR_SEQUENCE
Definition sim_runtime_state.h:125
@ SIM_RUNTIME_LOOP_ERROR_SOURCE_EXECUTION_FRAME
Definition sim_runtime_state.h:122
@ SIM_RUNTIME_LOOP_ERROR_SOURCE_LEGACY_STEP
Definition sim_runtime_state.h:126
void sim_runtime_state_release_continuity_buffers(SimRuntimeState *state)
Release continuity buffer allocations.
SimRuntimeCallerStepMode sim_runtime_state_last_caller_step_mode(const SimRuntimeState *state)
Fetch the last caller-owned step primitive observed.
SimRuntimeCallerStepMode
Most recent caller-owned stepping primitive observed on the context.
Definition sim_runtime_state.h:146
@ SIM_RUNTIME_CALLER_STEP_MODE_NONE
Definition sim_runtime_state.h:147
@ SIM_RUNTIME_CALLER_STEP_MODE_INTEGRATOR_STEP
Definition sim_runtime_state.h:149
@ SIM_RUNTIME_CALLER_STEP_MODE_MANUAL_STEP
Definition sim_runtime_state.h:148
bool sim_runtime_state_last_loop_error(const SimRuntimeState *state, SimRuntimeLoopError *out_error)
Fetch the most recent loop/runtime error.
void sim_runtime_state_clear_external_driver(SimRuntimeState *state)
Clear all caller-owned external-driver claims.
void sim_runtime_state_record_step_metrics(SimRuntimeState *state, const SimStepMetrics *metrics)
Append a step metrics sample to the runtime ring buffer.
void sim_runtime_state_release_external_driver(SimRuntimeState *state)
Release one caller-owned external-driver claim.
SimRuntimeLoopProgressKind
Kind of caller-owned bounded loop currently being observed.
Definition sim_runtime_state.h:155
@ SIM_RUNTIME_LOOP_PROGRESS_NONE
Definition sim_runtime_state.h:156
@ SIM_RUNTIME_LOOP_PROGRESS_RUN_PARAMETER_GRID
Definition sim_runtime_state.h:162
@ SIM_RUNTIME_LOOP_PROGRESS_RUN_PARAMETER_CONTINUATION
Definition sim_runtime_state.h:163
@ SIM_RUNTIME_LOOP_PROGRESS_RUN_UNTIL_INTEGRATOR
Definition sim_runtime_state.h:160
@ SIM_RUNTIME_LOOP_PROGRESS_RUN_UNTIL
Definition sim_runtime_state.h:158
@ SIM_RUNTIME_LOOP_PROGRESS_RUN_INTEGRATOR_STEPS
Definition sim_runtime_state.h:159
@ SIM_RUNTIME_LOOP_PROGRESS_RUN_PARAMETER_SWEEP
Definition sim_runtime_state.h:161
@ SIM_RUNTIME_LOOP_PROGRESS_RUN_STEPS
Definition sim_runtime_state.h:157
SimRuntimeLoopStopReason sim_runtime_state_last_stop_reason(const SimRuntimeState *state)
Fetch the most recent loop stop reason.
bool sim_runtime_state_latest_step_metrics(const SimRuntimeState *state, SimStepMetrics *out_metrics)
Copy the most recent step metrics sample.
#define SIM_STEP_METRIC_HISTORY
Definition sim_runtime_state.h:78
void sim_runtime_state_clear_loop_progress(SimRuntimeState *state)
Clear the current caller-owned loop progress snapshot.
void sim_runtime_state_clear_last_loop_progress(SimRuntimeState *state)
Clear any retained completed caller-owned loop progress snapshot.
void sim_runtime_state_clear_caller_step_history(SimRuntimeState *state)
Clear descriptive caller-owned step history.
void sim_runtime_state_clear_loop_error(SimRuntimeState *state)
Clear the most recent loop/runtime error record.
const char * sim_runtime_loop_stop_reason_name(SimRuntimeLoopStopReason reason)
Convert a loop stop reason to a stable machine-readable name.
void sim_runtime_state_note_caller_step(SimRuntimeState *state, SimRuntimeCallerStepMode mode)
Record a successful caller-owned step primitive.
void sim_runtime_state_set_pending_cancel(SimRuntimeState *state, bool pending)
Mark whether a scheduler-owned cancel is in progress.
const char * sim_runtime_loop_progress_kind_name(SimRuntimeLoopProgressKind kind)
Convert a loop-progress kind to a stable machine-readable name.
size_t sim_runtime_state_external_driver_depth(const SimRuntimeState *state)
Report the current nested external-driver claim depth.
bool sim_runtime_state_pending_cancel(const SimRuntimeState *state)
Read the current pending-cancel flag.
void sim_runtime_state_acquire_external_driver(SimRuntimeState *state)
Acquire a caller-owned external-driver claim.
bool sim_runtime_state_last_loop_progress(const SimRuntimeState *state, SimRuntimeLoopProgress *out_progress)
Fetch the most recent completed caller-owned loop progress snapshot.
SimResult sim_runtime_state_init(SimRuntimeState *state)
Initialize runtime state with defaults.
void sim_runtime_state_destroy(SimRuntimeState *state)
Destroy runtime state and release resources.
SimResult sim_runtime_state_ensure_continuity_capacity(SimRuntimeState *state, size_t required)
Ensure continuity counters can index at least required fields.
bool sim_runtime_state_loop_progress(const SimRuntimeState *state, SimRuntimeLoopProgress *out_progress)
Fetch the current caller-owned loop progress snapshot.
void sim_runtime_state_set_last_stop_reason(SimRuntimeState *state, SimRuntimeLoopStopReason reason)
Record the most recent loop stop reason.
void sim_runtime_state_record_loop_error(SimRuntimeState *state, SimResult code, SimRuntimeLoopErrorSource source, size_t step_index)
Record the most recent loop/runtime error.
void sim_runtime_state_set_loop_progress(SimRuntimeState *state, const SimRuntimeLoopProgress *progress)
Replace the current caller-owned loop progress snapshot.
Persistent flux-lens band state and analysis buffers for a simulation context.
Definition sim_flux_lens.h:43
Scratch workspace used while computing and reconstructing flux-lens bands.
Definition sim_flux_lens.h:84
Explicit in-memory representation for a complex double scalar (re, im)
Definition field.h:175
Feature selection for one field-statistics computation.
Definition sim_field_stats_runtime.h:57
Rolling counters for runtime field-statistics requests and costs.
Definition sim_field_stats_runtime.h:86
Summary statistics for a scalar or complex field slice.
Definition sim_field_stats.h:14
Reusable runtime state for one field's topology cache.
Definition sim_field_topology_runtime.h:37
Complex sample stored in runtime visualization and drift caches.
Definition sim_runtime_state.h:33
double re
Definition sim_runtime_state.h:34
double im
Definition sim_runtime_state.h:35
Structured record of the most recent loop/runtime failure.
Definition sim_runtime_state.h:132
SimRuntimeLoopErrorSource source
Definition sim_runtime_state.h:135
bool valid
Definition sim_runtime_state.h:133
SimResult code
Definition sim_runtime_state.h:134
size_t step_index
Definition sim_runtime_state.h:136
Snapshot of caller-owned loop progress and declared budgets.
Definition sim_runtime_state.h:169
bool has_trace_limit
Definition sim_runtime_state.h:189
double sim_time_budget
Definition sim_runtime_state.h:179
bool has_wall_time_budget
Definition sim_runtime_state.h:187
bool has_check_budget
Definition sim_runtime_state.h:185
uint64_t step_chunk
Definition sim_runtime_state.h:174
uint64_t check_budget
Definition sim_runtime_state.h:176
double wall_time_ms
Definition sim_runtime_state.h:178
bool has_step_chunk
Definition sim_runtime_state.h:183
bool has_sim_time_budget
Definition sim_runtime_state.h:186
bool active
Definition sim_runtime_state.h:170
SimRuntimeLoopProgressKind kind
Definition sim_runtime_state.h:171
double wall_time_budget
Definition sim_runtime_state.h:180
uint64_t checks_completed
Definition sim_runtime_state.h:173
double requested_dt
Definition sim_runtime_state.h:181
double sim_time_advanced
Definition sim_runtime_state.h:177
size_t trace_limit
Definition sim_runtime_state.h:182
bool has_step_budget
Definition sim_runtime_state.h:184
bool has_requested_dt
Definition sim_runtime_state.h:188
uint64_t step_budget
Definition sim_runtime_state.h:175
uint64_t steps_completed
Definition sim_runtime_state.h:172
Bounds and aggregate radii for phase-portrait visualization samples.
Definition sim_runtime_state.h:41
size_t count
Definition sim_runtime_state.h:52
double rms_radius
Definition sim_runtime_state.h:51
double max_radius
Definition sim_runtime_state.h:48
double max_dev
Definition sim_runtime_state.h:46
double max_dev_x
Definition sim_runtime_state.h:44
double min_radius
Definition sim_runtime_state.h:47
double min_r2
Definition sim_runtime_state.h:49
double max_dev_y
Definition sim_runtime_state.h:45
double max_r2
Definition sim_runtime_state.h:50
double mean_im
Definition sim_runtime_state.h:43
double mean_re
Definition sim_runtime_state.h:42
Runtime parameters and integration state.
Definition sim_runtime_state.h:195
size_t * phase_portrait_metrics_cache_sample_count
Definition sim_runtime_state.h:250
bool * phase_portrait_metrics_cache_valid
Definition sim_runtime_state.h:252
double * field_phase_ema
Definition sim_runtime_state.h:206
uint32_t drift_mode_depth
Definition sim_runtime_state.h:200
uint32_t external_driver_depth
Definition sim_runtime_state.h:282
size_t * drift_field_snapshot_count
Definition sim_runtime_state.h:216
uint32_t current_step_warp_mask
Definition sim_runtime_state.h:266
bool last_loop_progress_valid
Definition sim_runtime_state.h:287
bool measurement_dissipation_valid
Definition sim_runtime_state.h:237
size_t step_index
Definition sim_runtime_state.h:198
bool measurement_energy_valid
Definition sim_runtime_state.h:236
size_t * visual_sample_cache_stride
Definition sim_runtime_state.h:244
double measurement_energy
Definition sim_runtime_state.h:232
SimTimeModel time_model
Definition sim_runtime_state.h:197
SimComplexDouble ** drift_field_snapshots
Definition sim_runtime_state.h:214
bool step_metrics_valid
Definition sim_runtime_state.h:273
bool * drift_field_snapshot_requested
Definition sim_runtime_state.h:219
bool * drift_field_snapshot_valid
Definition sim_runtime_state.h:218
SimRuntimePhasePortraitMetrics * phase_portrait_metrics_cache
Definition sim_runtime_state.h:247
double dt
Definition sim_runtime_state.h:196
size_t * visual_sample_cache_step_index
Definition sim_runtime_state.h:242
double drift_time_override
Definition sim_runtime_state.h:201
size_t * visual_sample_cache_capacity
Definition sim_runtime_state.h:240
size_t * visual_sample_cache_count
Definition sim_runtime_state.h:241
bool * drift_field_stats_requested
Definition sim_runtime_state.h:213
size_t * field_health_inf_counts
Definition sim_runtime_state.h:229
bool drift_time_override_active
Definition sim_runtime_state.h:202
bool * visual_sample_cache_valid
Definition sim_runtime_state.h:245
FluxLensWorkspace flux_workspace
Definition sim_runtime_state.h:268
size_t * field_health_nan_counts
Definition sim_runtime_state.h:228
SimFieldStats * field_stats_cache
Definition sim_runtime_state.h:220
size_t measurement_cache_step_index
Definition sim_runtime_state.h:230
SimRuntimeComplexSample ** visual_sample_cache
Definition sim_runtime_state.h:239
size_t drift_field_stats_step_index
Definition sim_runtime_state.h:211
size_t * waveform_sample_stats_cache_sample_count
Definition sim_runtime_state.h:258
bool measurement_remainder_valid
Definition sim_runtime_state.h:238
size_t * visual_sample_cache_source_count
Definition sim_runtime_state.h:243
size_t continuity_capacity
Definition sim_runtime_state.h:265
bool * waveform_sample_stats_cache_valid
Definition sim_runtime_state.h:260
SimStepMetrics step_metrics[SIM_STEP_METRIC_HISTORY]
Definition sim_runtime_state.h:270
SimRuntimeLoopProgress loop_progress
Definition sim_runtime_state.h:284
size_t measurement_remainder_sources
Definition sim_runtime_state.h:235
uint64_t * field_dirty_counts
Definition sim_runtime_state.h:204
double * field_phase_last_time
Definition sim_runtime_state.h:207
SimFieldStatsRuntimeProfile field_stats_profile
Definition sim_runtime_state.h:225
SimFieldStats * drift_field_stats
Definition sim_runtime_state.h:210
SimFieldStatsComputeConfig field_stats_config
Definition sim_runtime_state.h:223
size_t visual_sample_target_samples
Definition sim_runtime_state.h:263
bool * drift_field_stats_valid
Definition sim_runtime_state.h:212
size_t * field_health_cache_step_index
Definition sim_runtime_state.h:227
size_t * drift_field_snapshot_capacity
Definition sim_runtime_state.h:215
SimFieldTopologyRuntimeState * field_topology_cache
Definition sim_runtime_state.h:226
size_t * drift_field_snapshot_step_index
Definition sim_runtime_state.h:217
size_t * waveform_sample_stats_cache_step_index
Definition sim_runtime_state.h:256
size_t caller_step_streak
Definition sim_runtime_state.h:281
FluxLensState flux_lens
Definition sim_runtime_state.h:267
double measurement_remainder
Definition sim_runtime_state.h:234
uint8_t * field_phase_initialized
Definition sim_runtime_state.h:209
uint8_t * field_phase_lock_state
Definition sim_runtime_state.h:208
SimRuntimeLoopProgress last_loop_progress
Definition sim_runtime_state.h:286
size_t * field_stats_cache_step_index
Definition sim_runtime_state.h:221
SimRuntimeLoopError last_loop_error
Definition sim_runtime_state.h:277
uint64_t * field_stable_counts
Definition sim_runtime_state.h:205
bool measurement_cache_valid
Definition sim_runtime_state.h:231
size_t step_metrics_count
Definition sim_runtime_state.h:272
SimRuntimeLoopStopReason last_stop_reason
Definition sim_runtime_state.h:276
SimRuntimeCallerStepMode last_caller_step_mode
Definition sim_runtime_state.h:279
double time_accumulated
Definition sim_runtime_state.h:199
size_t * phase_portrait_metrics_cache_step_index
Definition sim_runtime_state.h:248
bool pending_cancel
Definition sim_runtime_state.h:275
double measurement_dissipation
Definition sim_runtime_state.h:233
SimRuntimeWaveformSampleStats * waveform_sample_stats_cache
Definition sim_runtime_state.h:255
size_t step_metrics_head
Definition sim_runtime_state.h:271
SimStepMetrics step_metrics_latest
Definition sim_runtime_state.h:274
size_t visual_sample_max_samples
Definition sim_runtime_state.h:264
Min/max summary for downsampled waveform visualization data.
Definition sim_runtime_state.h:58
size_t count
Definition sim_runtime_state.h:62
double max_value
Definition sim_runtime_state.h:60
double max_magnitude
Definition sim_runtime_state.h:61
double min_value
Definition sim_runtime_state.h:59
Aggregated metrics captured once per completed integration step.
Definition sim_runtime_state.h:83
uint64_t operator_wall_ns
Definition sim_runtime_state.h:91
uint32_t integrator_rejection_count
Definition sim_runtime_state.h:99
double requested_dt
Definition sim_runtime_state.h:85
uint32_t active_warp_mask
Definition sim_runtime_state.h:100
uint32_t integrator_attempt_count
Definition sim_runtime_state.h:98
double accepted_dt
Definition sim_runtime_state.h:86
uint64_t step_wall_ns
Definition sim_runtime_state.h:89
double next_dt
Definition sim_runtime_state.h:87
uint64_t integrator_wall_ns
Definition sim_runtime_state.h:90
uint64_t integrator_drift_scratch_bytes
Definition sim_runtime_state.h:96
uint64_t integrator_workspace_bytes
Definition sim_runtime_state.h:94
uint64_t stable_write_count
Definition sim_runtime_state.h:93
size_t step_index
Definition sim_runtime_state.h:84
uint64_t dirty_write_count
Definition sim_runtime_state.h:92
double rms_error
Definition sim_runtime_state.h:88