def test_cvt_lloyd(mesh, num_steps, ref): print(num_steps) m = copy.deepcopy(mesh) optimesh.optimize(m, "Lloyd", 1.0e-2, num_steps, verbose=False) assert_norm_equality(m.points, ref, 1.0e-12) # try the other way of calling optimesh X, c = mesh.points.copy(), mesh.cells("points").copy() X, _ = optimesh.optimize_points_cells(X, c, "lloyd", 1.0e-2, num_steps) assert_norm_equality(X, ref, 1.0e-12)
def test_cvt_qnb_boundary(n=10): X, cells = create_random_circle(n=n, radius=1.0) def boundary_step(x): x0 = [0.0, 0.0] r = 1.0 # simply project onto the circle y = (x.T - x0).T r = np.sqrt(np.einsum("ij,ij->j", y, y)) return ((y / r * r).T + x0).T mesh = meshplex.MeshTri(X, cells) optimesh.optimize(mesh, "Lloyd", 1.0e-2, 100, boundary_step=boundary_step) # X, cells = optimesh.cvt.quasi_newton_uniform_lloyd( # X, cells, 1.0e-2, 100, boundary_step=boundary_step # ) # X, cells = optimesh.cvt.quasi_newton_uniform_blocks( # X, cells, 1.0e-2, 100, boundary=Circle() # ) mesh.show()
def test_cvt_qnb(mesh, ref): m = copy.deepcopy(mesh) optimesh.optimize(m, "CVT (block-diagonal)", 1.0e-2, 100) assert_norm_equality(m.points, ref, 1.0e-10)
def test_cvt_lloyd_overrelaxed(mesh, ref): m = copy.deepcopy(mesh) optimesh.optimize(m, "Lloyd", 1.0e-2, 100, omega=2.0) assert_norm_equality(m.points, ref, 1.0e-12)
def test_cvt_qnf(mesh, ref): m = copy.deepcopy(mesh) optimesh.optimize(m, "cvt (full)", 1.0e-2, 100, omega=0.9) m.show() # Assert that we're dealing with the mesh we expect. assert_norm_equality(m.points, ref, 1.0e-12)
def test_nonlinear_optimization(mesh, ref): m = copy.deepcopy(mesh) optimesh.optimize(m, "ODT (BFGS)", 1.0e-5, 100) assert_norm_equality(m.points, ref, 1.0e-12)
def test_fixed_point(mesh, ref): m = copy.deepcopy(mesh) optimesh.optimize(m, "ODT (fixed-point)", 1.0e-3, 100) assert_norm_equality(m.points, ref, 1.0e-12)
def test_fixed_point(mesh, ref): optimesh.optimize(mesh, "laplace", 0.0, 10) assert_norm_equality(mesh.points, ref, 1.0e-12)