Skip to content

Commit 868a07d

Browse files
refactor: accept a single op in generate_initializesystem
1 parent 800a509 commit 868a07d

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/systems/nonlinear/initializesystem.jl

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ $(TYPEDSIGNATURES)
1313
Generate `System` of nonlinear equations which initializes a problem from specified initial conditions of an `AbstractTimeDependentSystem`.
1414
"""
1515
function generate_initializesystem_timevarying(sys::AbstractSystem;
16-
u0map = Dict(),
17-
pmap = Dict(),
16+
op = Dict(),
1817
initialization_eqs = [],
1918
guesses = Dict(),
2019
default_dd_guess = Bool(0),
@@ -40,8 +39,16 @@ function generate_initializesystem_timevarying(sys::AbstractSystem;
4039
idxs_diff = isdiffeq.(eqs)
4140

4241
# PREPROCESSING
43-
u0map = copy(anydict(u0map))
44-
pmap = anydict(pmap)
42+
op = anydict(op)
43+
u0map = anydict()
44+
pmap = anydict()
45+
build_operating_point!(sys, op, u0map, pmap, defs, unknowns(sys),
46+
parameters(sys; initial_parameters = true))
47+
for (k, v) in op
48+
if has_parameter_dependency_with_lhs(sys, k) && is_variable_floatingpoint(k)
49+
pmap[k] = v
50+
end
51+
end
4552
initsys_preprocessing!(u0map, defs)
4653

4754
# 1) Use algebraic equations of system as initialization constraints
@@ -177,8 +184,7 @@ $(TYPEDSIGNATURES)
177184
Generate `System` of nonlinear equations which initializes a problem from specified initial conditions of an `AbstractTimeDependentSystem`.
178185
"""
179186
function generate_initializesystem_timeindependent(sys::AbstractSystem;
180-
u0map = Dict(),
181-
pmap = Dict(),
187+
op = Dict(),
182188
initialization_eqs = [],
183189
guesses = Dict(),
184190
algebraic_only = false,
@@ -196,8 +202,16 @@ function generate_initializesystem_timeindependent(sys::AbstractSystem;
196202
guesses = merge(get_guesses(sys), additional_guesses)
197203

198204
# PREPROCESSING
199-
u0map = copy(anydict(u0map))
200-
pmap = anydict(pmap)
205+
op = anydict(op)
206+
u0map = anydict()
207+
pmap = anydict()
208+
build_operating_point!(sys, op, u0map, pmap, defs, unknowns(sys),
209+
parameters(sys; initial_parameters = true))
210+
for (k, v) in op
211+
if has_parameter_dependency_with_lhs(sys, k) && is_variable_floatingpoint(k)
212+
pmap[k] = v
213+
end
214+
end
201215
initsys_preprocessing!(u0map, defs)
202216

203217
# Calculate valid `Initial` parameters. These are unknowns for

0 commit comments

Comments
 (0)