Skip to content

Commit 020c59e

Browse files
committed
Added Documentation
1 parent 047ab7b commit 020c59e

109 files changed

Lines changed: 18171 additions & 90 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Easy2Sim/Easy2Sim.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<SignAssembly>False</SignAssembly>
88
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
99
<Title>Easy2Sim</Title>
10-
<Version>0.2.0</Version>
10+
<Version>0.2.1</Version>
1111
<Authors>AlexanderKinast</Authors>
1212
<Company>RISC Software GmbH</Company>
1313
<Description>Easy2Sim is a simple, modern, and extendable simulation framework.</Description>

Easy2Sim/Easy2SimDocs/custom.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.code-annotation {
2+
position: relative;
3+
}
4+
5+
.code-annotation::before {
6+
content: "Note: ";
7+
position: absolute;
8+
top: -1.5em;
9+
left: 0;
10+
background-color: #ffffcc;
11+
padding: 0.2em;
12+
border: 1px solid #ffd700;
13+
font-size: 0.8em;
14+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Basic concepts in the Framework
2+
3+
To create a new simulation component, the base class SimulationBase should be used.
4+
Once instantiated, the Environment will automatically set a simulation index based on the order of instantiation.
5+
This index defines the execution order of the components in one time step.
6+
If this should be changed the method SimulationBase\SetIndexManually(int index) can be used.
7+
Typically this simulation index starts at 0 and is increased by one per instantiated component.
8+
When setting it manually, even negative values can be used.
9+
10+
=== "Index example - Main "
11+
12+
``` { .csharp .annotate .select }
13+
SimulationEnvironment environment = new SimulationEnvironment();
14+
DiscreteSolver solver = new DiscreteSolver(environment);
15+
16+
Sine sine1 = new(environment, solver); // (1)
17+
Sine sine2 = new(environment, solver); // (2)
18+
19+
sine1.SetIndexManually(3) // (3)
20+
```
21+
{ .annotate }
22+
23+
1. sine1 has the simulation index 0
24+
2. sine2 has the simulation index 1
25+
2. sine1 has the simulation index 3
26+
27+
In a dynamic calculation, each components "DynamicCalculation" method is executed once per time step.
28+
When using a discrete solver, each component is added to time step 0.
29+
Further events have to be added. This are the possible ways to add events:
30+
31+
1. **DiscreteSolver/AddEvent(SimulationBase simulationBase)**
32+
33+
If a component should add a event in the same simulation time the solvers AddEvent can be used.
34+
35+
2. **DiscreteSolver/AddEventAtTime(SimulationBase simulationBase, long simulationTime)**
36+
37+
Similar to the first variant, however, a time can be specified
38+
39+
3. **Connection changed**
40+
41+
If two components are connected and the value changes, an event is automatically added for the connected component.
42+
To recognize a change the C# Equals method is used on the objects.
43+
44+
45+
=== "Simple simulation component - Sine"
46+
47+
``` { .csharp .annotate .select }
48+
using Easy2Sim.Connect.Attributes;
49+
using Easy2Sim.Environment;
50+
using Easy2Sim.Solvers;
51+
using Newtonsoft.Json;
52+
53+
namespace StandardLibrary.Mathematical.Source
54+
{
55+
public class Sine : SimulationBase // (1)
56+
{
57+
[Output] // (2)
58+
[JsonProperty] // (3)
59+
public double Output;
60+
[JsonProperty]
61+
public double Amplitude;
62+
[JsonProperty]
63+
public double Frequency;
64+
[JsonProperty]
65+
public double Offset;
66+
[JsonProperty]
67+
public int NumberOfSamples;
68+
public Sine() // (4)
69+
{
70+
Amplitude = 1.0;
71+
Frequency = 10.0;
72+
Offset = 0;
73+
Output = 0.0;
74+
NumberOfSamples = 100;
75+
}
76+
public Sine(SimulationEnvironment environment, SolverBase solverBase) : base(environment, solverBase) // (5)
77+
{
78+
Amplitude = 1.0;
79+
Frequency = 10.0;
80+
Offset = 0;
81+
Output = 0.0;
82+
NumberOfSamples = 100;
83+
}
84+
public override void DynamicCalculation() // (6)
85+
{
86+
if (Solver == null) return;
87+
88+
double timeInSeconds = (double)Solver.BaseModel.SimulationTime / NumberOfSamples;
89+
double angle = 2 * Math.PI * Frequency * timeInSeconds + Offset;
90+
double sineValue = Amplitude * Math.Sin(angle);
91+
92+
Output = sineValue;
93+
}
94+
public override string SerializeToJson() // (7)
95+
{
96+
return JsonConvert.SerializeObject(this);
97+
}
98+
}
99+
}
100+
```
101+
{ .annotate }
102+
103+
1. Each simulation component needs to implement SimulationBase
104+
2. Output defines, that this Property can be connected to a Input of another component
105+
3. To allow serialization and deserialization, each component needs to be serializable
106+
4. An empty constructor is needed for the serialization framework
107+
5. Use this constructor when you create components, it will register the components in the framework
108+
6. DynamicCalculation is called in every simulated time step in the Dynamic solver
109+
7. The SerializeToJson method needs to be overwritten in order to allow the framework to serialize this component
110+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Easy2Sim
2+
3+
4+
## Description
5+
Easy2Sim is a open source C# simulation framework developed by the RISC Software GmbH. The goal of this framework is, that it allows fast development of simulation libraries and a good connection to other programs. Currently the framework support [continuous](https://en.wikipedia.org/wiki/Continuous_simulation) and [discrete-event](https://en.wikipedia.org/wiki/Discrete-event_simulation) simulation. By default the framework runs deterministically, however, stochastic simulations are possible.
6+
7+
The simulation framework has been build by the RISC Software GmbH in the [Secure Prescriptive Analytics project](https://www.prescriptiveanalytics.at/).
8+

0 commit comments

Comments
 (0)