def test_save_and_checkpoint_timeseries(tempdir, encoding, cell_type): mesh = UnitSquareMesh(MPI.comm_world, 16, 16, cell_type) filename = os.path.join(tempdir, "u2_checkpoint.xdmf") FE = FiniteElement("CG", mesh.ufl_cell(), 2) V = FunctionSpace(mesh, FE) times = [0.5, 0.2, 0.1] u_out = [None] * len(times) u_in = [None] * len(times) p = 0.0 def expr_eval(x): return x[0] * p with XDMFFile(mesh.mpi_comm(), filename, encoding=encoding) as file: for i, p in enumerate(times): u_out[i] = Function(V) u_out[i].interpolate(expr_eval) file.write_checkpoint(u_out[i], "u_out", p) with XDMFFile(mesh.mpi_comm(), filename) as file: for i, p in enumerate(times): u_in[i] = file.read_checkpoint(V, "u_out", i) for i, p in enumerate(times): u_in[i].vector.axpy(-1.0, u_out[i].vector) assert u_in[i].vector.norm() < 1.0e-12 # test reading last with XDMFFile(mesh.mpi_comm(), filename) as file: u_in_last = file.read_checkpoint(V, "u_out", -1) u_out[-1].vector.axpy(-1.0, u_in_last.vector) assert u_out[-1].vector.norm() < 1.0e-12
def test_clear_sub_map_data_vector(mesh): mesh = UnitSquareMesh(8, 8) P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1) W = FunctionSpace(mesh, P1 * P1) # Check block size assert W.dofmap.index_map.block_size == 2 W.dofmap.clear_sub_map_data() with pytest.raises(RuntimeError): W0 = W.sub(0) assert (W0) with pytest.raises(RuntimeError): W1 = W.sub(1) assert (W1)
# # Next, various model parameters are defined:: # Model parameters lmbda = 1.0e-02 # surface parameter dt = 5.0e-06 # time step theta = 0.5 # time stepping family, e.g. theta=1 -> backward Euler, theta=0.5 -> Crank-Nicolson # A unit square mesh with 97 (= 96 + 1) vertices in each direction is # created, and on this mesh a # :py:class:`FunctionSpace<dolfinx.function.FunctionSpace>` # ``ME`` is built using a pair of linear Lagrangian elements. :: # Create mesh and build function space mesh = UnitSquareMesh(MPI.COMM_WORLD, 96, 96, CellType.triangle) P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1) ME = FunctionSpace(mesh, P1 * P1) # Trial and test functions of the space ``ME`` are now defined:: # Define trial and test functions du = TrialFunction(ME) q, v = TestFunctions(ME) # .. index:: split functions # # For the test functions, # :py:func:`TestFunctions<dolfinx.functions.function.TestFunctions>` (note # the 's' at the end) is used to define the scalar test functions ``q`` # and ``v``. The # :py:class:`TrialFunction<dolfinx.functions.function.TrialFunction>`