Commit 39be3dd
committed
Fix stepping past domain error for NoiseGrid when dt doesn't evenly divide time span
When solving a NoiseProblem with a NoiseGrid where the dt doesn't evenly divide
the time span, floating point errors could cause the solver to report "Stepped past
the defined domain for the NoiseGrid".
This occurred because:
1. After many steps with dt=0.01 over tspan [0.0, 10.0], floating point errors
accumulate and W.curt ends up at ~9.9999999999 instead of exactly 10.0
2. The step_setup flag gets set to false when W.curt + dt > W.t[end]
3. The while loop continues because W.curt < prob.tspan[2] (floating point)
4. accept_step! errors because step_setup is false
The fix adds two checks in the solve loop:
1. If we're essentially at the end (within floating point tolerance), exit
2. If the next step would overshoot, take a partial final step to reach exactly
the end, resetting step_setup if necessary
Fixes #136
Co-Authored-By: Claude Opus 4.5 <[email protected]>1 parent d0f998d commit 39be3dd
2 files changed
+46
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
48 | 64 | | |
49 | 65 | | |
50 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
50 | 79 | | |
0 commit comments