r""" Writing and reading trajectory data =================================== This example illustrates how to store intermediate data to a file for later post-processing. The storage frequency is an argument to the tracker. """ from tempfile import NamedTemporaryFile import pde # define grid, state and pde grid = pde.UnitGrid([32]) state = pde.FieldCollection([ pde.ScalarField.random_uniform(grid), pde.VectorField.random_uniform(grid) ]) eq = pde.PDE({"s": "-0.1 * s", "v": "-v"}) # get a temporary file to write data to path = NamedTemporaryFile(suffix=".hdf5") # run a simulation and write the results writer = pde.FileStorage(path.name, write_mode="truncate") eq.solve(state, t_range=32, dt=0.01, tracker=writer.tracker(1)) # read the simulation back in again reader = pde.FileStorage(path.name, write_mode="read_only") pde.plot_kymographs(reader)
""" 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)
import pde grid = pde.UnitGrid([64, 64]) # generate grid state = pde.ScalarField.random_uniform(grid) # generate initial condition #eq = pde.DiffusionPDE(diffusivity=0.1) # define the pde eq = pde.PDE({'c': 'laplace(c**3 - c - laplace(c))'}) result = eq.solve(state, t_range=[0, 10]) # solve the pde result.plot() # plot the resulting field
def main(): grid = pde.UnitGrid([64, 64]) field = pde.ScalarField.random_uniform(grid, label="Density") eq = pde.CahnHilliardPDE() eq.solve(field, t_range=1e3, dt=1e-3, tracker=["progress", "interactive"])
def __init__(self, gridscale_x, gridscale_y, init_state_expression, t): self.grid = pde.UnitGrid([gridscale_x, gridscale_y]) self.scale = np.array([gridscale_x, gridscale_y]) self.t = t self.init_state = pde.ScalarField.from_expression( self.grid, init_state_expression)