Skip to content

Commit 328a638

Browse files
authored
Merge branch 'master' into myb/sub
2 parents 9a7ca8a + 166606a commit 328a638

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

.github/workflows/Downstream.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
- {user: SciML, repo: StructuralIdentifiability.jl, group: All}
2727
- {user: SciML, repo: ModelingToolkitStandardLibrary.jl}
2828
- {user: SciML, repo: ModelOrderReduction.jl, group: All}
29+
- {user: SciML, repo: MethodOfLines.jl, group: Interface}
30+
- {user: SciML, repo: MethodOfLines.jl, group: 2D_Diffusion}
31+
- {user: SciML, repo: MethodOfLines.jl, group: DAE}
2932
- {user: ai4energy, repo: Ai4EComponentLib.jl, group: Downstream}
3033
steps:
3134
- uses: actions/checkout@v2

src/ModelingToolkit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ end
162162

163163
export AbstractTimeDependentSystem, AbstractTimeIndependentSystem,
164164
AbstractMultivariateSystem
165-
export ODESystem, ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system
165+
export ODESystem, ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system,
166+
add_accumulations
166167
export DAEFunctionExpr, DAEProblemExpr
167168
export SDESystem, SDEFunction, SDEFunctionExpr, SDEProblemExpr
168169
export SystemStructure

src/systems/diffeqs/odesystem.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,21 @@ function Symbolics.substitute(sys::ODESystem, rules::Union{Vector{<:Pair}, Dict}
442442
collect(rules)))
443443
eqs = fast_substitute(equations(sys), rules)
444444
ODESystem(eqs, get_iv(sys); name = nameof(sys))
445+
446+
"""
447+
$(SIGNATURES)
448+
449+
Add accumulation variables for `vars`.
450+
"""
451+
function add_accumulations(sys::ODESystem, vars = states(sys))
452+
eqs = get_eqs(sys)
453+
accs = filter(x -> startswith(string(x), "accumulation_"), states(sys))
454+
if !isempty(accs)
455+
error("$accs variable names start with \"accumulation_\"")
456+
end
457+
avars = [rename(v, Symbol(:accumulation_, getname(v))) for v in vars]
458+
D = Differential(get_iv(sys))
459+
@set! sys.eqs = [eqs; Equation[D(a) ~ v for (a, v) in zip(avars, vars)]]
460+
@set! sys.states = [get_states(sys); avars]
461+
@set! sys.defaults = merge(get_defaults(sys), Dict(a => 0.0 for a in avars))
445462
end

test/odesystem.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,15 @@ D = Differential(t)
338338
@variables x(t) y(t) z(t)
339339
D = Differential(t)
340340
@named sys = ODESystem([D(x) ~ y, 0 ~ x + z, 0 ~ x - y], t, [z, y, x], [])
341+
asys = add_accumulations(sys)
342+
@variables accumulation_x(t) accumulation_y(t) accumulation_z(t)
343+
eqs = [0 ~ x + z
344+
0 ~ x - y
345+
D(accumulation_x) ~ x
346+
D(accumulation_y) ~ y
347+
D(accumulation_z) ~ z
348+
D(x) ~ y]
349+
@test sort(equations(asys), by = string) == eqs
341350
sys2 = ode_order_lowering(sys)
342351
M = ModelingToolkit.calculate_massmatrix(sys2)
343352
@test M == Diagonal([1, 0, 0])

0 commit comments

Comments
 (0)