Skip to content

Commit d4d5563

Browse files
Add extended initialization algorithms from OrdinaryDiffEq to DiffEqBase
This moves the parameterized versions of BrownBasicInit and ShampineCollocationInit from OrdinaryDiffEq to DiffEqBase, making them the standard implementations: - BrownBasicInit now accepts optional abstol (default: 1e-10) and nlsolve parameters - ShampineCollocationInit now accepts optional initdt and nlsolve parameters - Added BrownFullBasicInit as an alias for BrownBasicInit for consistency This eliminates the need for separate extended types in OrdinaryDiffEq, simplifying the ecosystem by having a single set of initialization algorithms that can handle both simple and advanced use cases. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 026e812 commit d4d5563

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

src/dae_initialization.jl

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For Sundials, this will use:
2020
struct DefaultInit <: DAEInitializationAlgorithm end
2121

2222
"""
23-
struct BrownBasicInit <: DAEInitializationAlgorithm
23+
struct BrownBasicInit{T, F} <: DAEInitializationAlgorithm
2424
2525
The Brown basic initialization algorithm for DAEs. This implementation
2626
is based on the algorithm described in:
@@ -37,11 +37,26 @@ fixed. It uses Newton's method to solve for consistent initial values.
3737
This is the default initialization for many DAE solvers when `differential_vars`
3838
is provided, allowing the solver to distinguish between differential and algebraic
3939
variables.
40+
41+
## Parameters
42+
43+
- `abstol`: Absolute tolerance for the nonlinear solver (default: 1e-10)
44+
- `nlsolve`: Custom nonlinear solver to use (optional)
4045
"""
41-
struct BrownBasicInit <: DAEInitializationAlgorithm end
46+
struct BrownBasicInit{T, F} <: DAEInitializationAlgorithm
47+
abstol::T
48+
nlsolve::F
49+
end
50+
function BrownBasicInit(; abstol = 1e-10, nlsolve = nothing)
51+
BrownBasicInit(abstol, nlsolve)
52+
end
53+
BrownBasicInit(abstol) = BrownBasicInit(; abstol = abstol, nlsolve = nothing)
54+
55+
# Alias for consistency with OrdinaryDiffEq naming
56+
const BrownFullBasicInit = BrownBasicInit
4257

4358
"""
44-
struct ShampineCollocationInit <: DAEInitializationAlgorithm
59+
struct ShampineCollocationInit{T, F} <: DAEInitializationAlgorithm
4560
4661
The Shampine collocation initialization algorithm for DAEs. This implementation
4762
is based on the algorithm described in:
@@ -57,7 +72,21 @@ expensive computationally.
5772
5873
This method is useful when you need to modify all variables (both differential
5974
and algebraic) to achieve consistency, rather than just the algebraic ones.
60-
"""
61-
struct ShampineCollocationInit <: DAEInitializationAlgorithm end
6275
63-
export DefaultInit, BrownBasicInit, ShampineCollocationInit
76+
## Parameters
77+
78+
- `initdt`: Initial time step to use in the collocation method (optional)
79+
- `nlsolve`: Custom nonlinear solver to use (optional)
80+
"""
81+
struct ShampineCollocationInit{T, F} <: DAEInitializationAlgorithm
82+
initdt::T
83+
nlsolve::F
84+
end
85+
function ShampineCollocationInit(; initdt = nothing, nlsolve = nothing)
86+
ShampineCollocationInit(initdt, nlsolve)
87+
end
88+
function ShampineCollocationInit(initdt)
89+
ShampineCollocationInit(; initdt = initdt, nlsolve = nothing)
90+
end
91+
92+
export DefaultInit, BrownBasicInit, BrownFullBasicInit, ShampineCollocationInit

0 commit comments

Comments
 (0)