Skip to content

Commit 9903120

Browse files
committed
Simplify maybe create
1 parent 344f9a8 commit 9903120

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/model_management.jl

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,8 @@ Create and cache a simplified linear model if it does not exist or if the output
237237
# Returns
238238
- `true` if a new model was created, `false` otherwise.
239239
"""
240-
function maybe_create_simple_lin_model!(sam, outputs; create_simple_lin_model=true,
241-
outputs_changed=false, prn=true)
242-
if create_simple_lin_model &&
243-
(isnothing(sam.simple_lin_model) || outputs_changed)
240+
function maybe_create_simple_lin_model!(sam, outputs; create_simple_lin_model=true, prn=true)
241+
if create_simple_lin_model && isnothing(sam.simple_lin_model)
244242
sys = sam.prob.sys
245243
time = @elapsed slm_attrs = generate_simple_lin_model(sam.sys_struct, sys, outputs)
246244
if !isnothing(slm_attrs.model)
@@ -267,10 +265,8 @@ Create and cache the `LinearizationProblem` if it does not exist or if the outpu
267265
# Returns
268266
- `true` if a new problem was created, `false` otherwise.
269267
"""
270-
function maybe_create_lin_prob!(sam, outputs; create_lin_prob=true,
271-
outputs_changed=false, prn=true)
272-
if create_lin_prob &&
273-
(isnothing(sam.lin_prob) || outputs_changed)
268+
function maybe_create_lin_prob!(sam, outputs; create_lin_prob=true, prn=true)
269+
if create_lin_prob && isnothing(sam.lin_prob)
274270
time = @elapsed @suppress_err begin
275271
lin_fun, lin_sys = linearization_function(sam.full_sys, [sam.inputs...], outputs;
276272
op=sam.defaults, guesses=sam.guesses)
@@ -300,10 +296,8 @@ Create and cache the control functions if they do not exist or if the outputs ha
300296
# Returns
301297
- `true` if new functions were created, `false` otherwise.
302298
"""
303-
function maybe_create_control_functions!(sam, outputs; create_control_func=false,
304-
outputs_changed=false, prn=true)
305-
if create_control_func &&
306-
(isnothing(sam.control_funcs) || outputs_changed)
299+
function maybe_create_control_functions!(sam, outputs; create_control_func=false, prn=true)
300+
if create_control_func && isnothing(sam.control_funcs)
307301
inputs = [sam.inputs...]
308302
time = @elapsed result = generate_control_funcs(sam.full_sys, inputs, outputs)
309303
sam.control_funcs = ControlFuncWithAttributes(; result...)
@@ -398,12 +392,9 @@ function init!(sam::SymbolicAWEModel;
398392
changed |= outputs_changed
399393
changed |= maybe_create_prob!(sam; create_prob, prn)
400394
changed |= maybe_create_simple_lin_model!(sam, outputs;
401-
create_simple_lin_model=create_prob,
402-
outputs_changed, prn)
403-
changed |= maybe_create_lin_prob!(sam, outputs; create_lin_prob,
404-
outputs_changed, prn)
405-
changed |= maybe_create_control_functions!(sam, outputs; create_control_func,
406-
outputs_changed, prn)
395+
create_simple_lin_model=create_prob, prn)
396+
changed |= maybe_create_lin_prob!(sam, outputs; create_lin_prob, prn)
397+
changed |= maybe_create_control_functions!(sam, outputs; create_control_func, prn)
407398

408399
if changed
409400
prn && @info "Serializing model to: \n\t$model_path"

0 commit comments

Comments
 (0)