Getting started

In order to explore what numerous and numerous as code is all about we have made this getting started guide that takes you through the basic processes to start developing your own numerous systems and content for the numerous platform.


The concept
numerous as-code uses a declarative way to write your code. This means that you use the code to declare what you want, not how you want something to happen.

The way we have implemented this declarative way of coding in python, is to use context managers, by using the with statement.

For example, we can declare a system representing a bouncing ball to have a parameter H0 for starting height, and an output H for height at a given timestep like so:

with NumerousSystem(“BouncingBall”):
Parameter(“H0”, unit=”m”, default=5)
Output(“H”, unit=”m”)



Step 1 [A minimum example]

Open your python editor and install the numerous as code package:

pip install numerous-as-code



Step 2

Copy the below code into a new .py file


Step 3

Run your .py file to run your first numerous system.


What happened here?

You created a repository with the Repository() statement. Repositories are numerous way of organizing your code. Repositories help numerous access your code and helps you staying organized and version control your systems. If you want to understand repositories better there is some documentation on the concept of repositories here.

You created a new system of the type NumerousSystem. Systems is how numerous represents the code you are adding on the platform. The Parameters, Inputs and Outputs are how your system can interact with other systems.

Finally you have run the system you defined as “simulation” which is a simulation of the ConnectedWaterTanks you have build.


Running the system and connect to the cloud:
As you may have noticed from the output of the code in the console numerous-as-code detected that you where running in your local environment with no data stored in the cloud and not utilizing the cloud to execute your code. This is of course great for experimenting with numerous and exploring how to make your code best interact with numerous.

However, in order to take advantage of the cloud platform for exploring the data generated by your code and sharing it with your collaborators you are suggested to connect your code with a numerous platform environment.

Step 4

Change out the repository and the environment in the code to point to the numerous platform and the numerous code repository.
“from numerous_.as_code.repositories.repository import NumerousRepository as Repository
from numerous_platform.numerous_environment import NumerousEnvironment as Environment ”

Step 5
Run the script again. This time when the code starts running you will be asked to sign-up/login to the numerous platform. After you have signed-up and created a new repository the code in the terminal will continue running - now saving your systems in a repository which can be accessed by the platform and actually running the code in the cloud.

From here you can explore the links printed in the terminal. For instance try to go and visit the repository page on the plaform.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

from numerous_.as_code.basic_objects import Parameter, Input, Output, connect, Description, Constant

from numerous_.as_code.repositories.repository import Repository

from simple_python.python_environment import PythonEnvironment as Environment


from open_modelica_numerous.types import OpenModelicaClass, OpenModelicaComposition, import_open_modelica_class, OpenModelicaSimulation

with Repository() as repository:

Valve = import_open_modelica_class("valve.mo")

with OpenModelicaClass("WaterTank") as Tank:

connect(Tank.modelica_class, Constant("WaterTank"))

Parameter('initial_fill_level', default=20, unit="%")

Parameter('capacity', default=100, unit="m3")


Input('F', unit="m3/s", description="flow rate into tank")

Output('P', unit="kPa", description="Hydrostatic Pressure")

with OpenModelicaClass("WaterPipe") as Pipe:

connect(Pipe.modelica_class, Constant("Pipe"))


Parameter('resistance', default=100, unit="kPa*s/m3")

Input('P1', unit="kPa", description="Pressure of tank 1")

Input('P2', unit="kPa", description="Pressure of tank 2")

Output('F1', unit="m3/s", description="flow to tank 1")

Output('F2', unit="m3/s", description="flow to tank 2")

with OpenModelicaComposition("ConnectedWaterTanks") as ConnectedWaterTanks:

Description(

"System connecting three water tanks together with pipes. The water will equilibrate between the tanks."

)

tank1 = Tank()

tank2 = Tank()

tank3 = Tank()

pipe12 = Pipe()

pipe23 = Pipe()

# Connect tank1 and 2 to pipe12

connect(pipe12.P1, tank1.P)

connect(pipe12.P2, tank2.P)

connect(pipe12.F1, tank1.F)

connect(pipe12.F2, tank2.F)

# Connect tank2 and 3 to pipe23

connect(pipe23.P1, tank2.P)

connect(pipe23.P2, tank3.P)

connect(pipe23.F1, tank2.F)

connect(pipe23.F2, tank3.F)

with OpenModelicaSimulation('simulation') as Simulation:

ConnectedWaterTanks()

if __name__ == '__main__':

with Environment() as environment:

simulation = Simulation()

environment.run(simulation)