Exemple #1
0
def test_material_conservation_tracker():
    """ test the MaterialConservationTracker """
    state = ScalarField.random_uniform(UnitGrid([8, 8]), 0, 1)

    solver = ExplicitSolver(CahnHilliardPDE())
    controller = Controller(solver, t_range=1, tracker=["material_conservation"])
    controller.run(state, dt=1e-3)
    assert controller.info["t_final"] >= 1

    solver = ExplicitSolver(AllenCahnPDE())
    controller = Controller(solver, t_range=1, tracker=["material_conservation"])
    controller.run(state, dt=1e-3)
    assert controller.info["t_final"] <= 1
Exemple #2
0
def test_runtime_tracker():
    """ test the RuntimeTracker """
    s = ScalarField.random_uniform(UnitGrid([128]))
    tracker = trackers.RuntimeTracker("0:01")
    sol = ExplicitSolver(DiffusionPDE())
    con = Controller(sol, t_range=1e4, tracker=["progress", tracker])
    con.run(s, dt=1e-3)
Exemple #3
0
def test_consistency_tracker():
    """ test the ConsistencyTracker """
    s = ScalarField.random_uniform(UnitGrid([128]))
    sol = ExplicitSolver(DiffusionPDE(1e3))
    con = Controller(sol, t_range=1e5, tracker=["consistency"])
    with np.errstate(all="ignore"):
        con.run(s, dt=1)
    assert con.info["t_final"] < con.info["t_end"]
=================

This example shows how to set up solvers explicitly and how to extract
diagnostic information.
"""

from pde import (UnitGrid, ScalarField, FieldCollection, DiffusionPDE,
                 ExplicitSolver, ScipySolver, Controller) 

# initialize the grid, an initial condition, and the PDE
grid = UnitGrid([32, 32])
field = ScalarField.random_uniform(grid, -1, 1)
eq = DiffusionPDE()

# try the explicit solver
solver1 = ExplicitSolver(eq)
controller1 = 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 = ScipySolver(eq)
controller2 = Controller(solver2, t_range=1, tracker=None)
sol2 = controller2.run(field)
sol2.label = 'scipy solver'
print('Diagnostic information from second run:')
print(controller2.diagnostics)
print()