""" Using simulation trackers ========================= This example illustrates how trackers can be used to analyze simulations. """ 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)
""" Solver comparison ================= This example shows how to set up solvers explicitly and how to extract diagnostic information. """ import pde # initialize the grid, an initial condition, and the PDE grid = pde.UnitGrid([32, 32]) field = pde.ScalarField.random_uniform(grid, -1, 1) eq = pde.DiffusionPDE() # try the explicit solver solver1 = pde.ExplicitSolver(eq) controller1 = pde.Controller(solver1, t_range=1, tracker=None) sol1 = controller1.run(field, dt=1e-3) sol1.label = "explicit solver" print("Diagnostic information from first run:") print(controller1.diagnostics) print() # try the standard scipy solver solver2 = pde.ScipySolver(eq) controller2 = pde.Controller(solver2, t_range=1, tracker=None) sol2 = controller2.run(field) sol2.label = "scipy solver" print("Diagnostic information from second run:") print(controller2.diagnostics)
def eval(self, z): eq = pde.DiffusionPDE(diffusivity=z) result = eq.solve(self.init_state, t_range=self.t) return result