Skip to content

Commit 3dbf18a

Browse files
committed
Integrate ModelingToolkit DAE test into test suite
- Added ModelingToolkit and KernelAbstractions to test dependencies - Created comprehensive DAE test in proper test directory structure - Test uses CPU backend to avoid GPU array adaptation complexity - Added test to runtests.jl with SafeTestsets - Validates DAE initialization, mass matrix, and constraint satisfaction - All 5 test assertions pass successfully 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 18bd6a4 commit 3dbf18a

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
33
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
44
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
55
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
6+
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
67
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
78
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
89
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
10+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
911
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1012
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
1113
OptimizationOptimisers = "42dfb2eb-d2b4-4451-abcd-913932933ac1"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using ModelingToolkit, DiffEqGPU, OrdinaryDiffEq, LinearAlgebra, Test
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
3+
using KernelAbstractions: CPU
4+
5+
# ModelingToolkit problems are too complex for GPU array adaptation,
6+
# so we use CPU backend for DAE testing
7+
const backend = CPU()
8+
9+
# Define the cartesian pendulum DAE system
10+
@parameters g = 9.81 L = 1.0
11+
@variables x(t) y(t) [state_priority = 10] λ(t)
12+
13+
# The cartesian pendulum DAE system:
14+
# m*ddot(x) = (x/L)*λ (simplified with m=1)
15+
# m*ddot(y) = (y/L)*λ - mg (simplified with m=1)
16+
# x^2 + y^2 = L^2 (constraint equation)
17+
eqs = [D(D(x)) ~ λ * x / L
18+
D(D(y)) ~ λ * y / L - g
19+
x^2 + y^2 ~ L^2]
20+
21+
@named pendulum = ODESystem(eqs, t, [x, y, λ], [g, L])
22+
23+
# Perform structural simplification with index reduction
24+
pendulum_sys = structural_simplify(dae_index_lowering(pendulum))
25+
26+
# Initial conditions: pendulum starts at bottom right position
27+
u0 = [x => 1.0, y => 0.0, λ => -g] # λ initial guess for tension
28+
29+
# Time span
30+
tspan = (0.0f0, 1.0f0)
31+
32+
# Create the ODE problem
33+
prob = ODEProblem(pendulum_sys, u0, tspan, Float32[])
34+
35+
# Verify DAE properties
36+
@test SciMLBase.has_initialization_data(prob.f) == true
37+
@test prob.f.mass_matrix !== nothing
38+
39+
# Create ensemble problem for GPU testing
40+
monteprob = EnsembleProblem(prob, safetycopy = false)
41+
42+
# Test with GPURosenbrock23
43+
sol = solve(monteprob, GPURosenbrock23(), EnsembleGPUKernel(backend),
44+
trajectories = 2,
45+
dt = 0.01f0,
46+
adaptive = false)
47+
48+
@test length(sol.u) == 2
49+
50+
# Check constraint satisfaction: x^2 + y^2 ≈ L^2
51+
final_state = sol.u[1][end]
52+
x_final, y_final = final_state[1], final_state[2]
53+
constraint_error = abs(x_final^2 + y_final^2 - 1.0f0)
54+
@test constraint_error < 0.1f0 # Reasonable tolerance for fixed timestep
55+
56+
# Test with GPURodas4
57+
sol2 = solve(monteprob, GPURodas4(), EnsembleGPUKernel(backend),
58+
trajectories = 2,
59+
dt = 0.01f0,
60+
adaptive = false)
61+
62+
@test length(sol2.u) == 2

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ using SafeTestsets, Test
2222
@time @safetestset "GPU Kernelized Stiff ODE Mass Matrix" begin
2323
include("gpu_kernel_de/stiff_ode/gpu_ode_mass_matrix.jl")
2424
end
25+
@time @safetestset "GPU Kernelized ModelingToolkit DAE" begin
26+
include("gpu_kernel_de/stiff_ode/gpu_ode_modelingtoolkit_dae.jl")
27+
end
2528
@time @testset "GPU Kernelized Non Stiff ODE Regression" begin
2629
include("gpu_kernel_de/gpu_ode_regression.jl")
2730
end

0 commit comments

Comments
 (0)