Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksagiyam committed Apr 4, 2024
1 parent 4037a9c commit 4a0378f
Show file tree
Hide file tree
Showing 3 changed files with 324 additions and 57 deletions.
88 changes: 81 additions & 7 deletions tests/submesh/test_submesh_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,27 @@ def test_submesh_assemble_mixed_scalar_facet_integral():
mesh.mark_entities(indicator_function, 999)
subm = Submesh(mesh, dmcommon.CELL_SETS_LABEL, 999, mesh.topological_dimension())
subm.init()
V0 = FunctionSpace(mesh, "CG", 1)
V1 = FunctionSpace(subm, "CG", 1)
V0 = FunctionSpace(mesh, "DQ", 1, variant="equispaced")
V1 = FunctionSpace(subm, "DQ", 1, variant="equispaced")
V = V0 * V1
u = TrialFunction(V)
v = TestFunction(V)
u0, u1 = split(u)
v0, v1 = split(v)
dS0 = Measure("dS", domain=mesh)
ds1 = Measure("ds", domain=subm)
a_p = inner(u1('|'), v0('+')) * dS0
a_p = inner(u1('|'), v0('+')) * dS0 + inner(u0('+'), v1('|')) * ds1(5)
A_p = assemble(a_p, mat_type="nest")
print(A_p.M[0][0].values)
print(A_p.M[0][1].values)
print(A_p.M[1][0].values)
print(A_p.M[1][1].values)
assert np.allclose(A_p.M.sparsity[0][0].nnz, [1, 1, 1, 1, 1, 1, 1, 1]) # bc nodes
assert np.allclose(A_p.M.sparsity[0][1].nnz, [4, 4, 4, 4, 4, 4, 4, 4])
assert np.allclose(A_p.M.sparsity[1][0].nnz, [8, 8, 8, 8])
assert np.allclose(A_p.M.sparsity[1][1].nnz, [1, 1, 1, 1]) # bc nodes
M10 = np.array([[0., 0., 0., 0., 0., 0., 1. / 3., 1. / 6.],
[0., 0., 0., 0., 0., 0., 1. / 6., 1. / 3.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.]])
assert np.allclose(A_p.M[0][1].values, np.transpose(M10))
assert np.allclose(A_p.M[1][0].values, M10)
b_p = inner(u1('|'), v0('+')) * ds1(5)
B_p = assemble(b_p, mat_type="nest")
print(B_p.M[0][0].values)
Expand All @@ -72,3 +78,71 @@ def test_submesh_assemble_mixed_scalar_facet_integral():
print(B_m.M[0][1].values)
print(B_m.M[1][0].values)
print(B_m.M[1][1].values)


def test_submesh_assemble_cell_cell_cell_facet_integral():
# +-------+-------+-------+-------+
# | | | | |
# | | 555 | | mesh
# | | | | |
# +-------+-------+-------+-------+
# +-------+-------+
# | | |
# | | 555 mesh_l
# | | |
# +-------+-------+
# +-------+-------+
# | | |
# 555 | | mesh_r
# | | |
# +-------+-------+
# +-------+
# | |
# 555 | mesh_rl
# | |
# +-------+
mesh = RectangleMesh(4, 1, 4., 1., quadrilateral=True)
x, y = SpatialCoordinate(mesh)
label_int = 555
label_l = 81100
label_r = 80011
label_rl = 80010
HDivTrace0 = FunctionSpace(mesh, "HDiv Trace", 0)
DG0 = FunctionSpace(mesh, "DG", 0)
f_int = Function(HDivTrace0).interpolate(conditional(And(x > 1.9, x < 2.1), 1, 0))
f_l = Function(DG0).interpolate(conditional(x < 2., 1, 0))
f_r = Function(DG0).interpolate(conditional(x > 2., 1, 0))
f_rl = Function(DG0).interpolate(conditional(And(x > 2., x < 3.), 1, 0))
mesh = RelabeledMesh(mesh, [f_int, f_l, f_r, f_rl], [label_int, label_l, label_r, label_rl])
x, y = SpatialCoordinate(mesh)
mesh_l = Submesh(mesh, dmcommon.CELL_SETS_LABEL, label_l, mesh.topological_dimension())
mesh_r = Submesh(mesh, dmcommon.CELL_SETS_LABEL, label_r, mesh.topological_dimension())
mesh_rl = Submesh(mesh_r, dmcommon.CELL_SETS_LABEL, label_rl, mesh.topological_dimension())
dS = Measure("dS", domain=mesh)
ds_l = Measure("ds", domain=mesh_l)
ds_r = Measure("ds", domain=mesh_r)
ds_rl = Measure("ds", domain=mesh_rl)
n_l = FacetNormal(mesh_l)
n_r = FacetNormal(mesh_r)
n_rl = FacetNormal(mesh_rl)
assert assemble(dot(n_rl + n_l, n_rl + n_l) * ds_rl(label_int)) < 1.e-32
assert assemble(dot(n_rl + n_l, n_rl + n_l) * ds_r(label_int)) < 1.e-32
assert assemble(dot(n_rl + n_l, n_rl + n_l) * ds_l(label_int)) < 1.e-32
assert assemble(dot(n_rl + n_l, n_rl + n_l) * dS(label_int)) < 1.e-32
V_l = FunctionSpace(mesh_l, "DQ", 1, variant='equispaced')
V_rl = FunctionSpace(mesh_rl, "DQ", 1, variant='equispaced')
V = V_l * V_rl
u_l, u_rl = TrialFunctions(V)
v_l, v_rl = TestFunctions(V)
a = inner(u_rl('|'), v_l('|')) * ds_l(label_int) + inner(u_l('|'), v_rl('|')) * ds_rl(label_int)
A = assemble(a)
print(A.M[0][0].values)
print(A.M[0][1].values)
print(A.M[1][0].values)
print(A.M[1][1].values)
b = inner(u_rl('|'), v_l('|')) * dS(label_int) + inner(u_l('|'), v_rl('|')) * dS(label_int)
B = assemble(b)
print(B.M[0][0].values)
print(B.M[0][1].values)
print(B.M[1][0].values)
print(B.M[1][1].values)
50 changes: 0 additions & 50 deletions tests/submesh/test_submesh_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,56 +76,6 @@ def test_submesh_interpolate_cell_cell_hex_1_processes(fe_fesub, nelem, condx, c
_test_submesh_interpolate_cell_cell(mesh, cond, fe_fesub)


@pytest.mark.parallel(nprocs=8)
@pytest.mark.parametrize('nelem', [2, 4, 8, None])
@pytest.mark.parametrize('fe_fesub', [[("DQ", 0), ("DQ", 0)],
[("Q", 4), ("DQ", 5)]])
@pytest.mark.parametrize('condx', [LT, GT])
@pytest.mark.parametrize('condy', [LT, GT])
@pytest.mark.parametrize('condz', [LT, GT])
@pytest.mark.parametrize('distribution_parameters', [None, {"overlap_type": (DistributedMeshOverlapType.NONE, 0)}])
def test_submesh_interpolate_cell_cell_hex_8_processes(fe_fesub, nelem, condx, condy, condz, distribution_parameters):
if nelem is None:
mesh = Mesh(join(cwd, "..", "meshes", "cube_hex.msh"), distribution_parameters=distribution_parameters)
else:
mesh = UnitCubeMesh(nelem, nelem, nelem, hexahedral=True, distribution_parameters=distribution_parameters)
x, y, z = SpatialCoordinate(mesh)
cond = conditional(condx(x, .5), 1,
conditional(condy(y, .5), 1, # noqa: E128
conditional(condz(z, .5), 1, 0))) # noqa: E128
_test_submesh_interpolate_cell_cell(mesh, cond, fe_fesub)


@pytest.mark.parallel(nprocs=8)
@pytest.mark.parametrize('fe_fesub', [[("DP", 0), ("DP", 0)],
[("P", 4), ("DP", 5)],
[("BDME", 2), ("BDME", 3)],
[("BDMF", 2), ("BDMF", 3)]])
@pytest.mark.parametrize('condx', [LT, GT])
@pytest.mark.parametrize('condy', [LT, GT])
@pytest.mark.parametrize('distribution_parameters', [None, {"overlap_type": (DistributedMeshOverlapType.NONE, 0)}])
def test_submesh_interpolate_cell_cell_tri_8_processes(fe_fesub, condx, condy, distribution_parameters):
mesh = Mesh("./docs/notebooks/stokes-control.msh", distribution_parameters=distribution_parameters)
x, y = SpatialCoordinate(mesh)
cond = conditional(condx(x, 15.), 1,
conditional(condy(y, 2.5), 1, 0)) # noqa: E128
_test_submesh_interpolate_cell_cell(mesh, cond, fe_fesub)


@pytest.mark.parallel(nprocs=8)
@pytest.mark.parametrize('fe_fesub', [[("DQ", 0), ("DQ", 0)],
[("Q", 4), ("DQ", 5)]])
@pytest.mark.parametrize('condx', [LT, GT])
@pytest.mark.parametrize('condy', [LT, GT])
@pytest.mark.parametrize('distribution_parameters', [None, {"overlap_type": (DistributedMeshOverlapType.NONE, 0)}])
def test_submesh_interpolate_cell_cell_quad_8_processes(fe_fesub, condx, condy, distribution_parameters):
mesh = Mesh(join(cwd, "..", "meshes", "unitsquare_unstructured_quadrilaterals.msh"), distribution_parameters=distribution_parameters)
x, y = SpatialCoordinate(mesh)
cond = conditional(condx(x, 0.5), 1,
conditional(condy(y, 0.5), 1, 0)) # noqa: E128
_test_submesh_interpolate_cell_cell(mesh, cond, fe_fesub)


@pytest.mark.parallel(nprocs=3)
@pytest.mark.parametrize('nelem', [2, 4, 8, None])
@pytest.mark.parametrize('fe_fesub', [[("DQ", 0), ("DQ", 0)],
Expand Down
Loading

0 comments on commit 4a0378f

Please sign in to comment.