@@ -4,11 +4,28 @@ import SciMLBase
4
4
import CommonSolve
5
5
import SymbolicIndexingInterface
6
6
7
+ """
8
+ SCCAlg(; nlalg = nothing, linalg = nothing)
9
+
10
+ Algorithm for solving Strongly Connected Component (SCC) problems containing
11
+ both nonlinear and linear subproblems.
12
+
13
+ ### Keyword Arguments
14
+ - `nlalg`: Algorithm to use for solving NonlinearProblem components
15
+ - `linalg`: Algorithm to use for solving LinearProblem components
16
+ """
17
+ struct SCCAlg{N, L}
18
+ nlalg:: N
19
+ linalg:: L
20
+ end
21
+
22
+ SCCAlg (; nlalg = nothing , linalg = nothing ) = SCCAlg (nlalg, linalg)
23
+
7
24
function CommonSolve. solve (prob:: SciMLBase.SCCNonlinearProblem ; kwargs... )
8
- CommonSolve. solve (prob, nothing ; kwargs... )
25
+ CommonSolve. solve (prob, SCCAlg ( nothing , nothing ) ; kwargs... )
9
26
end
10
27
11
- function CommonSolve. solve (prob:: SciMLBase.SCCNonlinearProblem , alg; kwargs... )
28
+ function CommonSolve. solve (prob:: SciMLBase.SCCNonlinearProblem , alg:: SCCAlg ; kwargs... )
12
29
numscc = length (prob. probs)
13
30
sols = [SciMLBase. build_solution (
14
31
prob, nothing , prob. u0, convert (eltype (prob. u0), NaN ) * prob. u0)
@@ -20,9 +37,17 @@ function CommonSolve.solve(prob::SciMLBase.SCCNonlinearProblem, alg; kwargs...)
20
37
for i in 1 : numscc
21
38
prob. explictfuns, sols)
23
- sol = SciMLBase. solve (prob. probs[i], alg; kwargs... )
24
- _sol = SciMLBase. build_solution (
25
- prob. probs[i], nothing , sol. u, sol. resid, retcode = sol. retcode)
40
+
41
+ if prob. probs[i] isa SciMLBase. LinearProblem
42
+ sol = SciMLBase. solve (prob. probs[i], alg. linalg; kwargs... )
43
+ _sol = SciMLBase. build_solution (
44
+ prob. probs[i], nothing , sol. u, zero (sol. u), retcode = sol. retcode)
45
+ else
46
+ sol = SciMLBase. solve (prob. probs[i], alg. nlalg; kwargs... )
47
+ _sol = SciMLBase. build_solution (
48
+ prob. probs[i], nothing , sol. u, sol. resid, retcode = sol. retcode)
49
+ end
50
+
26
51
sols[i] = _sol
27
52
lasti = i
28
53
if ! SciMLBase. successful_retcode (_sol)
@@ -39,4 +64,5 @@ function CommonSolve.solve(prob::SciMLBase.SCCNonlinearProblem, alg; kwargs...)
39
64
SciMLBase. build_solution (prob, alg, u, resid; retcode, original = sols)
40
65
end
41
66
67
+
42
68
end
0 commit comments