Skip to content

Commit d949ad9

Browse files
committed
gradually let it successfully build
1 parent cdb5402 commit d949ad9

File tree

9 files changed

+504
-323
lines changed

9 files changed

+504
-323
lines changed

.gitignore

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@
4040
# debug information files
4141
*.dwo
4242

43-
# Build directories
44-
.xmake/
45-
build/
46-
47-
# Example executables
48-
simple_standard_parallelism
49-
standard_parallelism_demo
50-
test_standard_parallelism
43+
# Build directories
44+
.xmake/
45+
.vscode/
46+
build/
47+
48+
# Example executables
49+
simple_standard_parallelism
50+
standard_parallelism_demo
51+
test_standard_parallelism
5152
parallelism_integration_demo

examples/sde_demo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ int main() {
1818
drift_func, diffusion_func, diffeq::sde::NoiseType::DIAGONAL_NOISE);
1919

2020
auto wiener = diffeq::sde::factory::make_wiener_process<std::vector<double>, double>(1, 12345);
21-
auto integrator = diffeq::sde::factory::make_euler_maruyama_integrator<std::vector<double>, double>(problem, wiener);
21+
// auto integrator = diffeq::sde::factory::make_euler_maruyama_integrator<std::vector<double>, double>(problem, wiener);
22+
diffeq::sde::EulerMaruyamaIntegrator<std::vector<double>, double> integrator(problem, wiener);
2223

2324
std::vector<double> state = {1.0}; // Initial condition
2425
double dt = 0.01;
@@ -28,7 +29,7 @@ int main() {
2829
std::cout << "Initial state: " << state[0] << std::endl;
2930

3031
for (int i = 0; i < steps; ++i) {
31-
integrator->step(state, dt);
32+
integrator.step(state, dt);
3233
if (i % 25 == 0) { // Output every quarter
3334
std::cout << "t = " << (i * dt) << ": X = " << state[0] << std::endl;
3435
}

examples/sde_usage_demo.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,39 +96,39 @@ class BlackScholesModel {
9696

9797
// SOSRA
9898
{
99-
auto integrator = diffeq::sde::factory::make_sosra_integrator<std::vector<double>, double>(problem, wiener);
99+
diffeq::sde::SOSRAIntegrator<std::vector<double>, double> integrator(problem, wiener);
100100
std::vector<double> S = {S0};
101-
integrator->set_time(0.0);
101+
integrator.set_time(0.0);
102102
wiener->set_seed(12345);
103103

104104
for (int i = 0; i < steps; ++i) {
105-
integrator->step(S, dt);
105+
integrator.step(S, dt);
106106
}
107107
results.push_back(S[0]);
108108
}
109109

110110
// SRIW1
111111
{
112-
auto integrator = diffeq::sde::factory::make_sriw1_integrator<std::vector<double>, double>(problem, wiener);
112+
diffeq::sde::SRIW1Integrator<std::vector<double>, double> integrator(problem, wiener);
113113
std::vector<double> S = {S0};
114-
integrator->set_time(0.0);
114+
integrator.set_time(0.0);
115115
wiener->set_seed(12345);
116116

117117
for (int i = 0; i < steps; ++i) {
118-
integrator->step(S, dt);
118+
integrator.step(S, dt);
119119
}
120120
results.push_back(S[0]);
121121
}
122122

123123
// SOSRI
124124
{
125-
auto integrator = diffeq::sde::factory::make_sosri_integrator<std::vector<double>, double>(problem, wiener);
125+
diffeq::sde::SOSRIIntegrator<std::vector<double>, double> integrator(problem, wiener);
126126
std::vector<double> S = {S0};
127-
integrator->set_time(0.0);
127+
integrator.set_time(0.0);
128128
wiener->set_seed(12345);
129129

130130
for (int i = 0; i < steps; ++i) {
131-
integrator->step(S, dt);
131+
integrator.step(S, dt);
132132
}
133133
results.push_back(S[0]);
134134
}

include/diffeq.hpp

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <integrators/sde/milstein.hpp> // Milstein method with Lévy area (strong order 1.0)
2222
#include <integrators/sde/sri1.hpp> // Stochastic Runge-Kutta method (strong order 1.0)
2323
#include <integrators/sde/implicit_euler_maruyama.hpp> // Implicit method for stiff SDEs
24-
25-
// Advanced high-order SDE integrators (strong order 1.5)
2624
#include <integrators/sde/sra.hpp> // SRA base implementation
2725
#include <integrators/sde/sra1.hpp> // SRA1 variant for additive noise
2826
#include <integrators/sde/sra2.hpp> // SRA2 variant for additive noise
@@ -319,7 +317,7 @@ namespace diffeq {
319317
using DefaultTime = double;
320318
}
321319

322-
// Optional: Convenience factory functions
320+
// Modern factory functions using std::make_unique
323321
namespace diffeq {
324322

325323
/**
@@ -329,7 +327,7 @@ namespace diffeq {
329327
auto make_rk45(typename AbstractIntegrator<S>::system_function sys,
330328
typename S::value_type rtol = 1e-6,
331329
typename S::value_type atol = 1e-9) {
332-
return integrators::ode::RK45Integrator<S>(std::move(sys), rtol, atol);
330+
return std::make_unique<integrators::ode::RK45Integrator<S>>(std::move(sys), rtol, atol);
333331
}
334332

335333
/**
@@ -339,7 +337,7 @@ namespace diffeq {
339337
auto make_dop853(typename AbstractIntegrator<S>::system_function sys,
340338
typename S::value_type rtol = 1e-10,
341339
typename S::value_type atol = 1e-15) {
342-
return integrators::ode::DOP853Integrator<S>(std::move(sys), rtol, atol);
340+
return std::make_unique<integrators::ode::DOP853Integrator<S>>(std::move(sys), rtol, atol);
343341
}
344342

345343
/**
@@ -349,6 +347,40 @@ namespace diffeq {
349347
auto make_bdf(typename AbstractIntegrator<S>::system_function sys,
350348
typename S::value_type rtol = 1e-6,
351349
typename S::value_type atol = 1e-9) {
352-
return integrators::ode::BDFIntegrator<S>(std::move(sys), rtol, atol);
350+
return std::make_unique<integrators::ode::BDFIntegrator<S>>(std::move(sys), rtol, atol);
351+
}
352+
353+
/**
354+
* Create an RK4 integrator (fixed step)
355+
*/
356+
template<system_state S>
357+
auto make_rk4(typename AbstractIntegrator<S>::system_function sys) {
358+
return std::make_unique<integrators::ode::RK4Integrator<S>>(std::move(sys));
359+
}
360+
361+
/**
362+
* Create an RK23 integrator (adaptive)
363+
*/
364+
template<system_state S>
365+
auto make_rk23(typename AbstractIntegrator<S>::system_function sys,
366+
typename S::value_type rtol = 1e-6,
367+
typename S::value_type atol = 1e-9) {
368+
return std::make_unique<integrators::ode::RK23Integrator<S>>(std::move(sys), rtol, atol);
369+
}
370+
371+
/**
372+
* Create an Euler integrator (fixed step)
373+
*/
374+
template<system_state S>
375+
auto make_euler(typename AbstractIntegrator<S>::system_function sys) {
376+
return std::make_unique<integrators::ode::EulerIntegrator<S>>(std::move(sys));
377+
}
378+
379+
/**
380+
* Create an Improved Euler integrator (fixed step)
381+
*/
382+
template<system_state S>
383+
auto make_improved_euler(typename AbstractIntegrator<S>::system_function sys) {
384+
return std::make_unique<integrators::ode::ImprovedEulerIntegrator<S>>(std::move(sys));
353385
}
354386
}

include/sde/sde_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class AbstractSDEIntegrator {
197197
};
198198

199199
/**
200-
* @brief Factory functions for creating SDE problems and integrators
200+
* @brief Factory functions for creating SDE problems and Wiener processes
201201
*/
202202
namespace factory {
203203

test/integration/test_sde_integration.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <diffeq.hpp>
1313
#include <sde/sde_base.hpp>
14-
#include <sde/sde_solvers.hpp>
1514
#include <iostream>
1615
#include <vector>
1716
#include <array>

0 commit comments

Comments
 (0)