Application of programme control of the model
This example demonstrates one of the tools of model management - programme control.
Software control allows you to create, run and save models, as well as change their parameters in the script editor using special commands.
cd( @__DIR__ ) # Переместимся в каталог, где лежит текущий скрипт
homePath = string(@__DIR__)
Creating and saving a model
# Для повторного запуска команды create
if "model" in [m.name for m in engee.get_all_models()]
engee.close("model", force=true)
end
Creating a model:
engee.create("model")
View the name of an open model by using the function:
engee.get_current_model()::Model
engee.gcm()::Model
m = engee.gcm()
Saving a model using the function save()
:
engee.save( "model", "$homePath/model.engee"; force=true )
The model has been saved to the specified path:

You can view the list of open models using the function get_all_models()
:
engee.get_all_models()
Loading a model and changing modelling parameters

If the model is not yet open in the editor, we load the model using the function load()
. If it is already open, we use the function open()
. Then we get the modelling parameters with the command get_param()
:
if "program_control_model" in [m.name for m in engee.get_all_models()]
m = engee.open( "program_control_model" ) # загрузка модели
else
m = engee.load( "$homePath/program_control_model.engee" ) # если модель уже открыта, выполните эту строчку
end
m_param = engee.get_param( "program_control_model" ) # получение параметров моделирования
You can change the simulation parameters with the function set_param!()
:
engee.set_param!("program_control_model", "SolverName" => "Tsit5", "SolverType" => "variable-step") #= меняем постоянный шаг решателя
на переменный и изменяем сам решатель =#
engee.get_param("program_control_model") # выводим параметры с внесёнными изменениями
engee.set_param!("program_control_model", "MinStep" => "auto", "MaxStep" => "auto") #= меняем постоянный шаг решателя
на переменный и изменяем сам решатель =#
engee.get_param("program_control_model") # выводим параметры с внесёнными изменениями
Running a simulation
run([m::Model]; verbose=false)
Runs the execution of the model. If no model is specified, runs a simulation of the current model. If the model is not open, the NoModelOpenedException exception is thrown.
Arguments:
-
verbose
: whether to print the progress, default isverbose=false
. -
m::Model
: the model relative to which the operation is performed, defaults to the current model.Example:
engee> m = engee.load("start/examples/powersystems/models/power_line_apv.engee")
engee> engee.run(m)
Dict{String, DataFrame} with 6 entries:
"Va" => 40001×2 DataFrame....
"Ia" => 40001×2 DataFrame...
"Ib" => 40001×2 DataFrame...
"Ic" => 40001×2 DataFrame...
"Vc" => 40001×2 DataFrame...
"Vb" => 40001×2 DataFrame...
Run the model with simulation progress output:
engee.run(m, verbose=true)
Viewing simulation results
Simulation results can be retrieved using the function get_results()
:
engee.get_results(model_name::String)
engee.get_results(model::Model)
engee.get_results()
Returns the results of the last model simulation as a dictionary Dict{String, DataFrame}
, where key is the name of the port being monitored.
If the model is not open, an exception is printed NoModelOpenedException
.
If the simulation is not running, the exception ModelIsNotRunningException
is thrown.
Arguments:
-
m::Model
: the model against which the operation is performed, default is the current model.Example:
engee> m = engee.load("start/examples/powersystems/models/power_line_apv.engee")
engee> results1 = engee.run(m);
engee> results2 = engee.get_results(m)
Dict{String, DataFrame} with 6 entries:
"Va" => 40001×2 DataFrame....
"Ia" => 40001×2 DataFrame...
"Ib" => 40001×2 DataFrame...
"Ic" => 40001×2 DataFrame...
"Vc" => 40001×2 DataFrame...
"Vb" => 40001×2 DataFrame....
engee> results1 == results2
true
Display the results obtained from the simulation:
results = engee.get_results( "program_control_model" )
Writing simulation results to variables and displaying a summary table with the results:
sin1 = engee.get_results("program_control_model")["Sine Wave.1"]
sin2 = engee.get_results("program_control_model")["Sine Wave-1.1"]
sum_signal = engee.get_results("program_control_model")["Add.1"]
table = hcat(hcat(sin1, sin2[:,2], makeunique=true), sum_signal[:,2], makeunique=true) # используя сложение массивов по горизонтали (hcat()), составляем таблицу
first(table, 10) # выводим первые 10 значений получившейся таблицы
Plot the changes in the values obtained from the simulation:
using Plots
plot(table[:,1], table[:,2])
plot!(table[:,1], table[:,3])
plot!(table[:,1], table[:,4])
Conclusion:
This example demonstrated the use of software model control to run a simulation from a script.
During code execution, a new model was created and saved, the finished model was loaded, the simulation parameters were changed, and, using a graphics library, the results of the simulation were displayed and converted into a usable form.