Out of the Box¶
Tutorial¶
Create Project¶
On the menu bar, create a new project.
File
-> New
A pop-up window will appear where project name needs to be provided. Provide a meaningful name for the project (e.g., name of the example name you are currently testing).
Add a Digital Twin¶
On the menu bar, add a digital twin.
Project
-> Add Digital Twin
A pop-up window will appear where project name needs to be provided. Provide a meaningful name for the simulation environment (e.g., name of the example name you are currently testing).
Setup Simulation Parameters¶
For this example, we are not simulating time series, but directly the Wave function. Because of this, set
Save Sim. Endpoints to
False
.Save Sim. Time series to
False
.Time Series to
False
.Simulation Name to a meaningful name.
Add Constant/Simulated variables¶
The purpose of this example is to reproduce the examples goal, where function to simulate is,
From function, we see that z
is our variable to simulate depending on x
and y
values. Add 3 variables within the Constant/Simulated variables panel as follows,
Type |
Name |
Sim. Min. |
Sim. Max. |
Sim. Res. |
---|---|---|---|---|
Constant |
x |
-10 |
10 |
0.1 |
Constant |
y |
-10 |
10 |
0.1 |
Simulated |
z |
NaN |
NaN |
NaN |
Note
z
values are NaN
as they are not provided via the panel but within the custom code. They are calculated at simulation runtime.
Reset/Update Custom Code¶
Because new variable have been added, custom code layout/template needs to be updated.
To do so click either button,
Reset Code, to reset all custom code.
Update mandatory variable to update just mandatory regions of the code.
Because we don’t have any code written so far, we can directly click on Reset Code.
After performing this action, you will be able to see how the mandatory regions have been automatically updated by the digital twin,
ExtendedVariables region now contains the 3 created variables.
MandatoryCodeIni has been updated from
TOBESET
to1.0d
that is because we previously set Time Series toFalse
.MandatoryCodeEval has added the line
this.z.Value = TOBESET
; detecting that variablez
is a simulated one and therefore its value needs to be provided.
Before
#region ExtendedVariables
// Not currently in use
#endregion
...
public override void Initialize()
{
...
#region MandatoryCodeIni
this.XAxis.SimMin = TOBESET; // Start value
this.XAxis.SimRes = TOBESET; // Step (Resolution)
this.XAxis.SimMax = TOBESET; // End value
#endregion
}
public override void EvaluateStep()
{
...
#region MandatoryCodeEval
// Not currently in use
#endregion
}
After
#region ExtendedVariables
// Constant variables
private ExtendedVariable x; // x
private ExtendedVariable y; // y
// Simulated variables
private ExtendedVariable z; // z
#endregion
...
public override void Initialize()
{
...
#region MandatoryCodeIni
this.XAxis.SimMin = 1.0d; // Start value
this.XAxis.SimRes = 1.0d; // Step (Resolution)
this.XAxis.SimMax = 1.0d; // End value
#endregion
}
public override void EvaluateStep()
{
...
#region MandatoryCodeEval
// Simulated variables (ti) - Values.
this.z.Value = TOBESET;
#endregion
}
Provide Simulated variables values¶
If we click on Validate Code, we will get an error similar to,
Error (CS0103). Line: 38, Column: 17. The name 'TOBESET' does not exist in the current context
This indicates that we still need to provide a value four our simulated variable z
to be able to validate (compile) code properly.
To pre-calculate the value of z
depending on x
and y
, we can use the CustomCodeEval region and replace the TOBESET
by calculated value as follows,
public override void EvaluateStep()
{
#region CustomCodeEval
// Custom code can be declared here.
double z_temp = Math.Cos(this.x.Value)*Math.Sin(this.y.Value);
#endregion
#region MandatoryCodeEval
// Simulated variables (ti) - Values.
this.z.Value = z_temp;
#endregion
}
If we click on Validate Code again we will now get a successful code compilation,
Compile succeeded. Code updated.
Simulate¶
After having everything setup, we can proceed to simulate (clicking Sim / Opt
button) the digital twin with all possible combinations (40401
for this example).
Once simulation finishes, a report can be generated (clicking Report
button). This will add a report on the Reports tab ready to be explored.
Note
Current example is not a time series, so in the 2D view of the report, only points will appear on the plots. Switch to the 3D view mode to reproduce the waves plot.
Files¶
Project generated on the previous tutorial section can be downloaded,