Skip to content

Commit 603489f

Browse files
author
uzerbianati
committed
Minor fixes
Signed-off-by: uzerbianati <zerbinati@maths.ox.ac.uk>
1 parent e099605 commit 603489f

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

ngsPETSc/plex.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class comp:
1717
Mesh = type(None)
1818
try:
1919
from numba import jit
20-
numba = True
21-
except:
20+
numba = True
21+
except: # pylint: disable=bare-except
2222
jit = None
2323
numba = False
2424

@@ -28,7 +28,10 @@ class comp:
2828

2929
if numba:
3030
@jit(nopython=True, cache=True)
31-
def build2DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
31+
def build2DCells(coordinates, sIndicies, cell_indicies, start_end):
32+
"""
33+
JIT Method used to construct 2D cells
34+
"""
3235
cStart = start_end[0]
3336
cEnd = start_end[1]
3437
cells = np.zeros((cell_indicies.shape[0], 3))
@@ -50,7 +53,10 @@ def build2DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
5053
return cells
5154

5255
@jit(nopython=True, cache=True)
53-
def build3DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
56+
def build3DCells(coordinates, sIndicies, cell_indicies, start_end):
57+
"""
58+
JIT Method used to construct 3D cells
59+
"""
5460
cStart = start_end[0]
5561
cEnd = start_end[1]
5662
cells = np.zeros((cell_indicies.shape[0], 4))
@@ -76,7 +82,10 @@ def build3DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
7682
raise RuntimeError("We only support tets.")
7783
return cells
7884
else:
79-
def build2DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
85+
def build2DCells(coordinates, sIndicies, cell_indicies, start_end):
86+
"""
87+
Method used to construct 2D cells
88+
"""
8089
cStart = start_end[0]
8190
cEnd = start_end[1]
8291
cells = np.zeros((cell_indicies.shape[0], 3))
@@ -97,7 +106,10 @@ def build2DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
97106
raise RuntimeError("We only support triangles.")
98107
return cells
99108

100-
def build3DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
109+
def build3DCells(coordinates, sIndicies, cell_indicies, start_end):
110+
"""
111+
Method used to construct 3D cells
112+
"""
101113
cStart = start_end[0]
102114
cEnd = start_end[1]
103115
cells = np.zeros((cell_indicies.shape[0], 4))
@@ -124,16 +136,25 @@ def build3DCells(coordinates, sIndicies, cell_indicies, start_end, vStart):
124136
return cells
125137

126138
def create2DNetgenMesh(ngMesh, coordinates, plex, geoInfo):
139+
"""
140+
Method used to generate 2D NetgenMeshes
141+
142+
:arg ngMesh: the netgen mesh to be populated
143+
:arg coordinates: vertices coordinates
144+
:arg plex: PETSc DMPlex
145+
:arg geoInfo: geometric information assosciated with the Netgen mesh
146+
147+
"""
127148
ngMesh.AddPoints(coordinates)
128149
cStart,cEnd = plex.getHeightStratum(0)
129150
vStart, _ = plex.getHeightStratum(2)
130151
# Outside of jitted loop we put all calls to plex
131152
sIndicies = [plex.getCone(i) for i in range(cStart,cEnd)]
132-
cells_indicies = np.vstack([np.hstack([plex.getCone(sIndex[k])-vStart
153+
cells_indicies = np.vstack([np.hstack([plex.getCone(sIndex[k])-vStart
133154
for k in range(len(sIndex))]) for sIndex in sIndicies])
134155
ngMesh.Add(ngm.FaceDescriptor(bc=1))
135156
cells = build2DCells(coordinates, sIndicies,
136-
cells_indicies, (cStart, cEnd), vStart)
157+
cells_indicies, (cStart, cEnd))
137158
if cells.ndim == 2:
138159
ngMesh.AddElements(dim=2, index=1, data=cells, base=0)
139160
for bcLabel in range(1,plex.getLabelSize(FACE_SETS_LABEL)+1):
@@ -149,22 +170,30 @@ def create2DNetgenMesh(ngMesh, coordinates, plex, geoInfo):
149170
ngMesh.Add(edge, project_geominfo=geoInfo)
150171

151172
def create3DNetgenMesh(ngMesh, coordinates, plex, geoInfo):
173+
"""
174+
Method used to generate 3D NetgenMeshes
175+
176+
:arg ngMesh: the netgen mesh to be populated
177+
:arg coordinates: vertices coordinates
178+
:arg plex: PETSc DMPlex
179+
:arg geoInfo: geometric information assosciated with the Netgen mesh
180+
181+
"""
152182
ngMesh.AddPoints(coordinates)
153183
cStart, cEnd = plex.getHeightStratum(0)
154184
vStart, _ = plex.getHeightStratum(3)
155185
# Outside of jitted loop we put all calls to plex
156186
sIndicies = [plex.getCone(i) for i in range(cStart,cEnd)]
157-
158187
f1Indicies = np.array([plex.getCone(s[0]) for s in sIndicies])
159188
f2Indicies = np.array([plex.getCone(s[1]) for s in sIndicies])
160189
fIndicies = np.hstack([f1Indicies,f2Indicies])
161190

162-
cells_indicies = np.vstack([np.hstack([plex.getCone(sIndex[k])-vStart
191+
cells_indicies = np.vstack([np.hstack([plex.getCone(sIndex[k])-vStart
163192
for k in range(len(sIndex))]) for sIndex in fIndicies])
164193
ngMesh.Add(ngm.FaceDescriptor(bc=1))
165194
ngMesh.Add(ngm.FaceDescriptor(bc=plex.getLabelSize(FACE_SETS_LABEL)+1))
166195
cells = build3DCells(coordinates, sIndicies,
167-
cells_indicies, (cStart, cEnd), vStart)
196+
cells_indicies, (cStart, cEnd))
168197
if cells.ndim == 2:
169198
ngMesh.AddElements(dim=3, index=plex.getLabelSize(FACE_SETS_LABEL)+1,
170199
data=cells, base=0)

ngsPETSc/utils/firedrake/hierarchies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
from netgen.meshing import MeshingParameters
1919
from ngsPETSc.plex import MeshMapping
2020
from ngsPETSc.utils.utils import trim_util
21+
from ngsPETSc.utils.firedrake.meshes import geometric_dimension, topological_dimension
2122
logger = logging.getLogger("ngsPETSc")
2223
logging.basicConfig(filename='ngsPETSc.log',
2324
encoding='utf-8',
2425
level=logging.INFO)
2526

27+
2628
def snapToNetgenDMPlex(ngmesh, petscPlex, comm):
2729
'''
2830
This function snaps the coordinates of a DMPlex mesh to the coordinates of a Netgen mesh.

tests/test_plex.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from netgen.csg import unit_cube
88

99
from petsc4py import PETSc
10+
import pytest
1011

1112
from ngsPETSc import MeshMapping
1213

@@ -17,6 +18,7 @@ def _plex_number_of_points(plex, h=0, local=False):
1718
np = plex.getComm().tompi4py().allreduce(np)
1819
return np
1920

21+
@pytest.mark.mpi_skip
2022
def test_ngs_plex_2d():
2123
'''
2224
Testing the conversion from NGSolve mesh to PETSc DMPlex
@@ -27,6 +29,7 @@ def test_ngs_plex_2d():
2729
plex = meshMap.petscPlex
2830
assert _plex_number_of_points(plex) == 2
2931

32+
@pytest.mark.mpi_skip
3033
def test_plex_ngs_2d():
3134
'''
3235
Testing the conversion from PETSc DMPlex to NGSolve mesh
@@ -42,8 +45,9 @@ def test_plex_ngs_2d():
4245
comm=PETSc.COMM_WORLD)
4346
nc = _plex_number_of_points(plex, local=True)
4447
meshMap = MeshMapping(plex)
45-
assert Mesh(meshMap.ngMesh).GetNE(VOL) == nc
48+
assert Mesh (meshMap.ngMesh).GetNE(VOL) == nc
4649

50+
@pytest.mark.mpi_skip
4751
def test_ngs_plex_3d():
4852
'''
4953
Testing the conversion from NGSolve mesh to PETSc DMPlex
@@ -54,6 +58,7 @@ def test_ngs_plex_3d():
5458
plex = meshMap.petscPlex
5559
assert _plex_number_of_points(plex) == 12
5660

61+
@pytest.mark.mpi_skip
5762
def test_plex_ngs_3d():
5863
'''
5964
Testing the conversion from PETSc DMPlex to NGSolve mesh
@@ -72,6 +77,7 @@ def test_plex_ngs_3d():
7277
meshMap = MeshMapping(plex)
7378
assert Mesh(meshMap.ngMesh).GetNE(VOL) == nc
7479

80+
@pytest.mark.mpi_skip
7581
def test_plex_transform_alfeld_2d():
7682
'''
7783
Testing the use of the PETSc Alfeld transform
@@ -88,6 +94,7 @@ def test_plex_transform_alfeld_2d():
8894
meshMap = MeshMapping(newplex)
8995
assert Mesh(meshMap.ngMesh).GetNE(VOL) == nc
9096

97+
@pytest.mark.mpi_skip
9198
def test_plex_transform_alfeld_3d():
9299
'''
93100
Testing the use of the PETSc Alfeld transform

0 commit comments

Comments
 (0)