Debian Codegraph @

python/test/unit/mesh/test_ghost_mesh.py

raw
1 "Unit tests for ghosted meshes"
2
3 # Copyright (C) 2016 Garth N. Wells
4 #
5 # This file is part of DOLFIN.
6 #
7 # DOLFIN is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # DOLFIN is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19
20 import pytest
21 import numpy
22 from dolfin import *
23 import os
24
25 from dolfin_utils.test import (fixture, skip_in_parallel, xfail_in_parallel, cd_tempdir,
26 pushpop_parameters)
27
28
29 # See https://bitbucket.org/fenics-project/dolfin/issues/579
30 def xtest_ghost_vertex_1d(pushpop_parameters):
31 parameters["ghost_mode"] = "shared_vertex"
32 mesh = UnitIntervalMesh(20)
33 #print("Test: {}".format(MPI.sum(mesh.mpi_comm(), mesh.num_cells())))
34
35
36 def xtest_ghost_facet_1d(pushpop_parameters):
37 parameters["ghost_mode"] = "shared_facet"
38 mesh = UnitIntervalMesh(20)
39
40
41 def test_ghost_2d(pushpop_parameters):
42 modes = ["shared_vertex", "shared_facet"]
43 for mode in modes:
44 parameters["ghost_mode"] = mode
45 N = 8
46 num_cells = 128
47
48 mesh = UnitSquareMesh(N, N)
49 if MPI.size(mesh.mpi_comm()) > 1:
50 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
51
52 parameters["reorder_cells_gps"] = True
53 parameters["reorder_vertices_gps"] = False
54 mesh = UnitSquareMesh(N, N)
55 if MPI.size(mesh.mpi_comm()) > 1:
56 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
57
58 parameters["reorder_cells_gps"] = True
59 parameters["reorder_vertices_gps"] = True
60 mesh = UnitSquareMesh(N, N)
61 if MPI.size(mesh.mpi_comm()) > 1:
62 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
63
64 parameters["reorder_cells_gps"] = False
65 parameters["reorder_vertices_gps"] = True
66 mesh = UnitSquareMesh(N, N)
67 if MPI.size(mesh.mpi_comm()) > 1:
68 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
69
70
71 def test_ghost_3d(pushpop_parameters):
72 modes = ["shared_vertex", "shared_facet"]
73 for mode in modes:
74 parameters["ghost_mode"] = mode
75 N = 2
76 num_cells = 48
77
78 mesh = UnitCubeMesh(N, N, N)
79 if MPI.size(mesh.mpi_comm()) > 1:
80 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
81
82 parameters["reorder_cells_gps"] = True
83 parameters["reorder_vertices_gps"] = False
84 mesh = UnitCubeMesh(N, N, N)
85 if MPI.size(mesh.mpi_comm()) > 1:
86 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
87
88 parameters["reorder_cells_gps"] = True
89 parameters["reorder_vertices_gps"] = True
90 mesh = UnitCubeMesh(N, N, N)
91 if MPI.size(mesh.mpi_comm()) > 1:
92 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
93
94 parameters["reorder_cells_gps"] = False
95 parameters["reorder_vertices_gps"] = True
96 mesh = UnitCubeMesh(N, N, N)
97 if MPI.size(mesh.mpi_comm()) > 1:
98 assert MPI.sum(mesh.mpi_comm(), mesh.num_cells()) > num_cells
99
100
101 @pytest.mark.parametrize('gmode', ['shared_vertex', 'shared_facet', 'none'])
102 def test_ghost_connectivities(gmode, pushpop_parameters):
103 parameters['ghost_mode'] = gmode
104
105 # Ghosted mesh
106 meshG = UnitSquareMesh(MPI.comm_world, 4, 4)
107 meshG.init(1, 2)
108
109 # Reference mesh, not ghosted, not parallel
110 meshR = UnitSquareMesh(MPI.comm_self, 4, 4)
111 meshR.init(1, 2)
112
113 # Create reference mapping from facet midpoint to cell midpoint
114 reference = {}
115 for facet in facets(meshR):
116 fidx = facet.index()
117 facet_mp = tuple(facet.midpoint()[:])
118 reference[facet_mp] = []
119 for cidx in meshR.topology()(1, 2)(fidx):
120 cell = Cell(meshR, cidx)
121 cell_mp = tuple(cell.midpoint()[:])
122 reference[facet_mp].append(cell_mp)
123
124 # Loop through ghosted mesh and check connectivities
125 allowable_cell_indices = [cell.index() for cell in cells(meshG, 'all')]
126 for facet in facets(meshG, 'regular'):
127 fidx = facet.index()
128 facet_mp = tuple(facet.midpoint()[:])
129 assert facet_mp in reference
130
131 for cidx in meshG.topology()(1, 2)(fidx):
132 assert cidx in allowable_cell_indices
133 cell = Cell(meshG, cidx)
134 cell_mp = tuple(cell.midpoint()[:])
135 assert cell_mp in reference[facet_mp]