2.16. Using simulation trackers

This example illustrates how trackers can be used to analyze simulations.

Time: 3
  0%|          | 0/3.0 [00:00<?, ?it/s]
Initializing:   0%|          | 0/3.0 [00:00<?, ?it/s]
  0%|          | 0/3.0 [00:04<?, ?it/s]
  3%|3         | 0.1/3.0 [00:04<02:14, 46.40s/it]
  7%|6         | 0.2/3.0 [00:04<01:04, 23.21s/it]
 20%|#9        | 0.6/3.0 [00:04<00:18,  7.74s/it]
 20%|#9        | 0.6/3.0 [00:04<00:19,  8.10s/it]
100%|##########| 3.0/3.0 [00:04<00:00,  1.62s/it]
100%|##########| 3.0/3.0 [00:04<00:00,  1.62s/it]
502.5301484997568
502.5301484997568
502.5301484997568
502.5301484997568

import pde

grid = pde.UnitGrid([32, 32])  # generate grid
state = pde.ScalarField.random_uniform(grid)  # generate initial condition

storage = pde.MemoryStorage()

trackers = [
    "progress",  # show progress bar during simulation
    "steady_state",  # abort when steady state is reached
    storage.tracker(interval=1),  # store data every simulation time unit
    pde.PlotTracker(show=True),  # show images during simulation
    # print some output every 5 real seconds:
    pde.PrintTracker(interval=pde.RealtimeInterrupts(duration=5)),
]

eq = pde.DiffusionPDE(0.1)  # define the PDE
eq.solve(state, 3, dt=0.1, tracker=trackers)

for field in storage:
    print(field.integral)

Total running time of the script: ( 0 minutes 4.924 seconds)