DiffEq - Modern C++ ODE Integration Library 1.0.0
High-performance C++ library for solving ODEs with async signal processing
Loading...
Searching...
No Matches
sriw1.hpp
1#pragma once
2
3#include <sde/sde_base.hpp>
4#include <core/state_creator.hpp>
5#include <cmath>
6
7namespace diffeq {
8
17template<system_state StateType>
19public:
21 using state_type = typename base_type::state_type;
22 using time_type = typename base_type::time_type;
23 using value_type = typename base_type::value_type;
24
25 explicit SRIW1Integrator(std::shared_ptr<typename base_type::sde_problem_type> problem,
26 std::shared_ptr<typename base_type::wiener_process_type> wiener = nullptr)
27 : base_type(problem, wiener) {}
28
29 void step(state_type& state, time_type dt) override {
30 // Simplified SRIW1 implementation - falls back to Euler-Maruyama for now
31 // A full implementation would use the SRIW1 tableau coefficients
32
33 state_type drift_term = create_state_like(state);
34 state_type diffusion_term = create_state_like(state);
35 state_type dW = create_state_like(state);
36
37 // Generate Wiener increments
38 this->wiener_->generate_increment(dW, dt);
39
40 // Evaluate drift and diffusion
41 this->problem_->drift(this->current_time_, state, drift_term);
42 this->problem_->diffusion(this->current_time_, state, diffusion_term);
43
44 // Simple Euler-Maruyama step (SRIW1 implementation would be more complex)
45 for (size_t i = 0; i < state.size(); ++i) {
46 auto state_it = state.begin();
47 auto drift_it = drift_term.begin();
48 auto diffusion_it = diffusion_term.begin();
49 auto dW_it = dW.begin();
50
51 state_it[i] += drift_it[i] * dt + diffusion_it[i] * dW_it[i];
52 }
53
54 this->advance_time(dt);
55 }
56
57 std::string name() const override {
58 return "SRIW1 (Simplified Implementation)";
59 }
60
61private:
62 template<typename State>
63 State create_state_like(const State& prototype) {
64 State result;
65 if constexpr (requires { result.resize(prototype.size()); }) {
66 result.resize(prototype.size());
67 std::fill(result.begin(), result.end(), value_type{0});
68 }
69 return result;
70 }
71};
72
73} // namespace diffeq
SRIW1 integrator variant.
Definition sriw1.hpp:18
Abstract base class for SDE integrators.
Definition sde_base.hpp:147