def test_RefineUnitCubeMesh_keep_partition(): """Refine mesh of unit cube.""" mesh = UnitCubeMesh(MPI.comm_world, 5, 7, 9) mesh = refine(mesh, False) assert mesh.num_entities_global(0) == 3135 assert mesh.num_entities_global(3) == 15120 Q = FunctionSpace(mesh, ("CG", 1)) assert (Q)
# Compute error indicators h = array([c.h() for c in Cells(mesh)]) K = array([c.volume() for c in Cells(mesh)]) R = array([abs(source([c.midpoint()[0], c.midpoint()[1]])) for c in Cells(mesh)]) gamma = h*R*sqrt(K) # Compute error estimate E = sum([g*g for g in gamma]) E = sqrt(MPI.sum(mesh.mpi_comm(), E)) print("Level %d: E = %g (TOL = %g)" % (level, E, TOL)) # Check convergence if E < TOL: print("Success, solution converged after %d iterations" % level) break # Mark cells for refinement cell_markers = MeshFunction("bool", mesh, mesh.topology.dim, False) gamma_0 = sorted(gamma, reverse=True)[int(len(gamma)*REFINE_RATIO)] gamma_0 = MPI.max(mesh.mpi_comm(), gamma_0) for c in Cells(mesh): cell_markers[c] = gamma[c.index()] > gamma_0 # Refine mesh mesh = refine(mesh, cell_markers) mesh.geometry.coord_mapping = dolfin.fem.create_coordinate_map(mesh) # Plot mesh dolfin.plotting.plot(mesh)
def test_RefineUnitSquareMesh(): """Refine mesh of unit square.""" mesh = UnitSquareMesh(MPI.comm_world, 5, 7) mesh = refine(mesh, False) assert mesh.num_entities_global(0) == 165 assert mesh.num_entities_global(2) == 280
def test_RefineUnitCubeMesh(): """Refine mesh of unit cube.""" mesh = UnitCubeMesh(MPI.comm_world, 5, 7, 9) mesh = refine(mesh, False) assert mesh.num_entities_global(0) == 3135 assert mesh.num_entities_global(3) == 15120