Software processing of simulation results in Engee
In this article we will tell you how to save simulation results using the simout
variable. Let’s consider working with the variable on the basis of a simple example - output of a sine wave using the block Sine Wave Function.
By default, the |
Variable simout in Engee: integration and interaction
Create a model using blocks Sine Wave Function and Terminator. To do this, place them on the workspace, connect them with a signal line and enable signal recording using the context menu of the signal line. (see in Recording signals in Engee).
In this example all parameters (solver and block parameters Sine Wave Function) - remain by default. The graph of the sinusoidal signal simulation will be displayed in graph window.
Enable recording of ![]() |
If the circuit is assembled correctly, the simulation result will be displayed on the graph. After the simulation is finished, the variable simout
will be automatically created in the Engee workspace.
The simout
variable forms DataFrame - a data structure represented as a table. Cells of this table are automatically filled with simulation results data. For convenience, save the table in CSV format (named result.csv
in the example).
The simout
variable can be accessed in two ways:
-
Directly to the DataFrame variable
simout
through calling thetime
andvalue
columns. -
Using the
collect
command to save the simulation results to a new variable and refer to it.
Let’s consider both options. To address the variable directly, use the following code and call values and time from the DataFrame table one by one:
simout["newmodel_1/Sine Wave.1"].value[:] # выведет все значения таблицы из DataFrame
Output
1001-element Vector{Any}:
0.0
0.009999833334166664
0.01999866669333308
0.02999550020249566
0.03998933418663416
0.04997916927067833
0.059964006479444595
0.06994284733753277
0.0799146939691727
0.08987854919801104
0.09983341664682815
0.10977830083717481
0.11971220728891936
⋮
-0.44862125384280294
-0.4575358937753214
-0.4664047804997409
-0.4752270271347798
-0.48400175146312646
-0.49272807601966023
-0.5014051281791974
-0.5100320402437544
-0.5186079495293108
-0.527131998452086
-0.5356033346142913
-0.5440211108893698
After referring to the simout
values directly, similarly refer to the time values:
simout["newmodel_1/Sine Wave.1"].time[:] # выведет все значения времени из таблицы DataFrame
Output
1001-element Vector{Any}:
0.0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.1
0.11
0.12
⋮
9.89
9.9
9.91
9.92
9.93
9.94
9.95
9.96
9.97
9.98
9.99
10.0
Direct reference to simout
is useful when the value of a variable just needs to be retrieved or used in expressions without further processing or modification.
Now let’s consider the collect
invocation and creation of a new variable. The collect
command saves the results of the simulation into Engee RAM. collect
collects data from the simout
variable and saves it to a new variable. To execute the command, create a variable (result
in this example) and save the simulation results by entering the following code on the command line:
result = collect(simout["newmodel_1/Sine Wave.1"])
where:
-
result
is the name of the variable into which the simulation data is saved (can be renamed). -
newmodel_1
- name of the current model. -
Sin Wave
- name of the block that outputs the data. -
1
- number of the port, from the output of which the values for the variablesimout
are read and to which the signal record is added.
The obtained result can be observed as a table in the command line.
Next, record the simulation data into a CSV file. Save the data inside the result
variable to the CSV file result.csv
using the following commands:
using CSV
CSV.write("result.csv", result)
where:
-
using CSV
is a string indicating that the code will use functionality from the CSV library. In Julia, theusing
keyword is used to import functions and types from packages. -
CSV.write("result.csv", result)
- performs writing data to a CSV format file. TheCSV.write
function takes two arguments: a file in CSV format "result.csv" and theresult
variable. As a result, the code takes theresult
variable and writes its contents to the file "result.csv" in CSV format.
The results obtained are saved in the "result.csv" file, which is displayed in the file browser.
The resulting CSV file contains the numerical results of the Sine Wave Function block with the specified parameters (by default in this example). The results are presented in the form of columns time and value, where to each moment of time corresponds the simulation value of the block Sine Wave Function.
A CSV file with simulation results can also be obtained using the block To CSV. |
You can make sure that the data is correctly saved in the simout
variable visually by displaying the graph in the command line or script editor:
using Plots
plot(result.time, result.value)
The resulting graph will coincide with the one obtained earlier in the graph window:
Thus, the article demonstrates how easy it is to save simulation results using the simout
variable and a few lines of code. This approach is easy to use and ensures that the simulation data is saved in a convenient and versatile CSV format.