Skip to content

Lorenz System

Let's use the system class pydykit.systems_dae.Lorenz to simulate the famous Lorenz attractor, which is modelled in terms a quasilinear differential algebraic equations.

 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
import plotly.graph_objects as go

from pydykit.configuration import Configuration
from pydykit.examples import ExampleManager
from pydykit.managers import Manager
from pydykit.plotters import Plotter

####### Simulation
file_content = ExampleManager().get_example(name="lorenz")
configuration = Configuration(**file_content)  # Validate config file content

manager = Manager()
manager.configure(configuration=configuration)

result = manager.manage()  # Run the simulation

####### Plotting
fig = go.Figure()
df = result.to_df()
plotter = Plotter(results_df=df)
plotter.plot_3d_trajectory(
    figure=fig,
    x_components=df["x"],
    y_components=df["y"],
    z_components=df["z"],
    time=df["time"],
)
plotter.fix_scene_bounds_to_extrema(figure=fig, df=df)

####### Show visualization
script_is_executed_on_local_machine = False  # You might want to change this

if script_is_executed_on_local_machine:
    fig.show()
else:
    print(
        fig.to_html(
            full_html=False,
            include_plotlyjs="cdn",
        )
    )

Config File

The configuration file of this simulation reads as

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
name: lorenz
system:
  class_name: Lorenz
  sigma: 10.0
  rho: 28.0
  beta: 2.6666666667
  state:
    state: [2.0, 1.0, 1.0]
simulator:
  class_name: OneStep
  solver_name: NewtonPlainPython
  newton_epsilon: 1.e-07
  max_iterations: 40
integrator:
  class_name: MidpointDAE
time_stepper:
  class_name: FixedIncrement
  step_size: 0.02
  start: 0.0
  end: 4.0

For details on the usage of class_name-variable, see the example Pendulum 3D.