Application of software model management
This example demonstrates one of the model management tools - software management.
Software management 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")
Viewing the name of an open model is performed by the function:
    engee.get_current_model()::Model
    engee.gcm()::Model
m = engee.gcm()
Saving the model using the function save():
engee.save( "model", "$homePath/model.engee"; force=true )
The model was saved using the specified path.:
You can view the list of open models using the function get_all_models():
engee.get_all_models()
Loading the model and changing the simulation parameters
If the model is not yet open in the editor, then we load the model using the function load(). If it is already open, then you need to use the function open(). Then we get the simulation parameters using 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" ) # получение параметров моделирования
The simulation parameters can be changed using 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 the simulation
    run([m::Model]; verbose=false)
Starts the execution of the model. If no model is specified, it starts a simulation of the current model. If the model is not open, a NoModelOpenedException is thrown.
Arguments:
- 
verbose: whether to print progress, by defaultverbose=false. - 
m::Model: the default model for which the operation is performed is 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…
Running the model with simulation progress output:
engee.run(m, verbose=true)
Viewing simulation results
The simulation results can be obtained 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 simulation of the model as a dictionary Dict{String, DataFrame}, where the key is the name of the monitored port.
If the model is not open, an exception is thrown. NoModelOpenedException.
If the simulation is not running, an exception is thrown. ModelIsNotRunningException.
Arguments:
- 
m::Model: the default model for which the operation is performed 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 
Displaying the results obtained during the simulation:
results = engee.get_results( "program_control_model" )
Recording simulation results into 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 значений получившейся таблицы
We plot the changes in the values obtained as a result of the simulation.:
using Plots
plot(table[:,1], table[:,2])
plot!(table[:,1], table[:,3])
plot!(table[:,1], table[:,4])
Conclusion:
In this example, we demonstrated the use of software model control to run a simulation from a script.
During the execution of the code, a new model was created and saved, the finished model was loaded, the simulation parameters were changed, and also, using the graphical library, the simulation results were displayed and transformed into a convenient form.