def test_store_mesh(casedir): pp = PostProcessor(dict(casedir=casedir)) from dolfin import (UnitSquareMesh, CellFunction, FacetFunction, AutoSubDomain, Mesh, HDF5File, assemble, Expression, ds, dx) # Store mesh mesh = UnitSquareMesh(6, 6) celldomains = CellFunction("size_t", mesh) celldomains.set_all(0) AutoSubDomain(lambda x: x[0] < 0.5).mark(celldomains, 1) facetdomains = FacetFunction("size_t", mesh) AutoSubDomain(lambda x, on_boundary: x[0] < 0.5 and on_boundary).mark( facetdomains, 1) pp.store_mesh(mesh, celldomains, facetdomains) # Read mesh back mesh2 = Mesh() f = HDF5File(mpi_comm_world(), os.path.join(pp.get_casedir(), "mesh.hdf5"), 'r') f.read(mesh2, "Mesh", False) celldomains2 = CellFunction("size_t", mesh2) f.read(celldomains2, "CellDomains") facetdomains2 = FacetFunction("size_t", mesh2) f.read(facetdomains2, "FacetDomains") e = Expression("1+x[1]", degree=1) dx1 = dx(1, domain=mesh, subdomain_data=celldomains) dx2 = dx(1, domain=mesh2, subdomain_data=celldomains2) C1 = assemble(e * dx1) C2 = assemble(e * dx2) assert abs(C1 - C2) < 1e-10 ds1 = ds(1, domain=mesh, subdomain_data=facetdomains) ds2 = ds(1, domain=mesh2, subdomain_data=facetdomains2) F1 = assemble(e * ds1) F2 = assemble(e * ds2) assert abs(F1 - F2) < 1e-10
def run_splitting_solver(domain, dt, T): # Create cardiac model problem description cell_model = Tentusscher_panfilov_2006_epi_cell() heart = setup_model(cell_model, domain) # Customize and create monodomain solver ps = SplittingSolver.default_parameters() ps["pde_solver"] = "monodomain" ps["apply_stimulus_current_to_pde"] = True # 2nd order splitting scheme ps["theta"] = 0.5 # Use explicit first-order Rush-Larsen scheme for the ODEs ps["ode_solver_choice"] = "CardiacODESolver" ps["CardiacODESolver"]["scheme"] = "RL1" # Crank-Nicolson discretization for PDEs in time: ps["MonodomainSolver"]["theta"] = 0.5 ps["MonodomainSolver"]["linear_solver_type"] = "iterative" ps["MonodomainSolver"]["algorithm"] = "cg" ps["MonodomainSolver"]["preconditioner"] = "petsc_amg" # Create solver solver = SplittingSolver(heart, params=ps) # Extract the solution fields and set the initial conditions (vs_, vs, vur) = solver.solution_fields() vs_.assign(cell_model.initial_conditions()) solutions = solver.solve((0, T), dt) postprocessor = PostProcessor(dict(casedir="test", clean_casedir=True)) postprocessor.store_mesh(heart.domain()) field_params = dict( save=True, save_as=["hdf5", "xdmf"], plot=False, start_timestep=-1, stride_timestep=1 ) postprocessor.add_field(SolutionField("v", field_params)) theta = ps["theta"] # Solve total = Timer("XXX Total cbcbeat solver time") for i, (timestep, (vs_, vs, vur)) in enumerate(solutions): t0, t1 = timestep current_t = t0 + theta*(t1 - t0) postprocessor.update_all({"v": lambda: vur}, current_t, i) print("Solving on %s" % str(timestep)) # Print memory usage (just for the fun of it) print(memory_usage()) total.stop() # Plot result (as sanity check) #plot(vs[0], interactive=True) # Stop timer and list timings if MPI.rank(mpi_comm_world()) == 0: list_timings(TimingClear_keep, [TimingType_wall])