Skip to content

Commit cde133b

Browse files
authored
Merge pull request #14 from EDG-Acoustics/update_ci_cd_actions
Update ci cd actions
2 parents 9c496a5 + fddee24 commit cde133b

File tree

8 files changed

+68
-29
lines changed

8 files changed

+68
-29
lines changed

.github/workflows/cffconvert.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ on:
44
push:
55
branches:
66
- main
7+
- development
78
pull_request:
89
branches:
910
- main
11+
- development
1012

1113
jobs:
1214

.github/workflows/documentation.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ on:
44
push:
55
branches:
66
- main
7+
- development
78
pull_request:
89
branches:
910
- main
11+
- development
1012

1113
jobs:
1214
build-documentation:
@@ -30,7 +32,7 @@ jobs:
3032
python3 -m pip install --upgrade pip setuptools
3133
python3 -m pip install .[dev,publishing]
3234
- name: Install pandoc using apt
33-
run: sudo apt install pandoc
35+
run: sudo apt install pandoc
3436
- name: Build documentation
3537
run: make coverage doctest html
36-
working-directory: docs
38+
working-directory: docs

.github/workflows/markdown-link-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ on:
44
push:
55
branches:
66
- main
7+
- development
78
pull_request:
89
branches:
910
- main
11+
- development
1012

1113
jobs:
1214

.prospector.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ pyroma:
1717

1818
pycodestyle:
1919
full: true
20+
options:
21+
max-line-length: 300
22+
23+
pylint:
24+
disable:
25+
- line-too-long # Already checked by pycodestyle
26+
- import-self # Giving error on __init__ importing mesh.py
2027

2128
pydocstyle:
2229
disable: [
@@ -27,3 +34,7 @@ pydocstyle:
2734
D213, # Multi-line docstring summary should start at the second line
2835
D404, # First word of the docstring should not be This
2936
]
37+
38+
pyflakes:
39+
disable:
40+
- F401 # Temporarily disabled since it was raising errors in __init__
3.69 MB
Binary file not shown.

edg_acoustics/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"""Documentation about edg_acoustics"""
22
import logging
3-
43
from .mesh import *
54

5+
66
logging.getLogger(__name__).addHandler(logging.NullHandler())
77

88
__author__ = "Huiqing Wang"
99
__email__ = "[email protected]"
1010
__version__ = "0.1.0"
11-
12-

edg_acoustics/mesh.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
Mesh
2222
"""
2323
from __future__ import annotations
24+
import meshio
2425
import numpy
2526

26-
import meshio
2727

2828
__all__ = ['Mesh']
2929

@@ -68,29 +68,31 @@ class Mesh:
6868
N_BC_triangles (dict[str, int]): the number of triangles on the boundary of the domain associated to each
6969
boundary label in self.BC_labels. For example self.N_BC_triangles['my_label'] returns the number of boundary
7070
triangles associated to lable 'my_label'. 'my_label' must be a key of self.BC_labels.
71-
vertices (numpy.ndarray): An (self.N_vertices x M) array containing the M coordinates of the self.N_vertices vertices that make up
72-
the mesh. M specifies the geometric dimension of the mesh, such that the mesh describes an M-dimensional
73-
domain.
71+
vertices (numpy.ndarray): An (self.N_vertices x M) array containing the M coordinates of the self.N_vertices
72+
vertices that make up the mesh. M specifies the geometric dimension of the mesh, such that the mesh
73+
describes an M-dimensional domain.
7474
tets (numpy.ndarray): An (self.N_tets x 4) array containing the 4 indices of the vertices of the self.N_tets
7575
tetrahedra that make up the mesh.
7676
BC_triangles (dict[str, numpy.ndarray]):
7777
7878
Example:
7979
An element of this class can be initialized in the following way
8080
81-
>>> import edg_acoustics
82-
>>> BC_labels = {'CNRBC': 12, 'slip': 11, 'impedance': 33}
83-
>>> filename = "path_to_my_mesh_file/mesh_filename.msh"
84-
>>> mesh = edg_acoustics.Mesh(filename, BC_labels)
81+
>>> import edg_acoustics
82+
>>> BC_labels = {'slip': 11, 'impedance1': 13, 'impedance2': 14, 'impedance3': 15}
83+
>>> filename = "../data/tests/mesh/CoarseMesh.msh"
84+
>>> mesh = edg_acoustics.Mesh(filename, BC_labels)
85+
<BLANKLINE>
86+
>>> mesh.N_BC_triangles
87+
{'slip': 5347, 'impedance1': 400, 'impedance2': 3576, 'impedance3': 3294}
88+
8589
"""
8690

8791
def __init__(self, filename: str, BC_labels: dict[str, int]):
8892
# Init from file
8993
self.__init_from_file(filename, BC_labels)
9094

9195
def __init_from_file(self, filename: str, BC_labels: dict[str, int]):
92-
print("Init from filename")
93-
9496
# Load mesh data from mesh file
9597
mesh_data = meshio.read(filename)
9698

@@ -101,16 +103,16 @@ def __init_from_file(self, filename: str, BC_labels: dict[str, int]):
101103
self.vertices = mesh_data.points
102104

103105
# Check if all labels provided as input exist in the mesh data and vice versa, if not, raise error
104-
BC_labels_in_mesh = sorted(numpy.unique(mesh_data.cell_data_dict['gmsh:physical']['triangle'])) # get all labels in the mesh, sort for faster comparison below
106+
BC_labels_in_mesh = sorted(numpy.unique(mesh_data.cell_data_dict['gmsh:physical']['triangle'])) # get labels in the mesh, sort for faster comparison below
105107
BC_labels_in_input = sorted(BC_labels.values()) # get all labels specified in input
106108
if not BC_labels_in_input == BC_labels_in_mesh:
107109
raise ValueError(
108110
"[edg_acoustics.Mesh] All BC labels must be present in the mesh and all labels in the mesh must be "
109111
"present in BC_labels.")
110112

111113
# Read the boundary triangles and their definitions separating them into the different boundary condition labels
112-
self.N_BC_triangles = dict()
113-
self.BC_triangles = dict()
114+
self.N_BC_triangles = {}
115+
self.BC_triangles = {}
114116
for BC_label in BC_labels:
115117
triangles_have_label = (mesh_data.cell_data_dict['gmsh:physical']['triangle'] == BC_labels[BC_label]) # array with bools specifying if triangle has BC_label or not
116118
self.N_BC_triangles[BC_label] = triangles_have_label.sum() # number of triangles with label BC_label
@@ -123,6 +125,23 @@ def __init_from_file(self, filename: str, BC_labels: dict[str, int]):
123125
# Compute the mesh connectivity
124126
self.EToE, self.EToF = self.__compute_element_connectivity(self.tets)
125127

128+
# Operators --------------------------------------------------------------------------------------------------------
129+
def __eq__(self, other):
130+
if isinstance(other, type(self)):
131+
# If self and other are mesh objects then check if all properties contain the same data
132+
are_equal = (self.N_vertices == other.N_vertices
133+
and self.N_tets == other.N_tets
134+
and self.N_BC_triangles == other.N_BC_triangles
135+
and numpy.array_equal(self.vertices, other.vertices)
136+
and numpy.array_equal(self.tets, other.tets)
137+
and all(numpy.array_equal(item, other.BC_triangles[key]) for key, item in self.BC_triangles.items()))
138+
else:
139+
# If they are of different types, then they are not the same
140+
are_equal = False
141+
142+
return are_equal
143+
144+
# ------------------------------------------------------------------------------------------------------------------
126145

127146
# Static methods ---------------------------------------------------------------------------------------------------
128147
@staticmethod
@@ -156,7 +175,7 @@ def __compute_element_connectivity(tets: numpy.ndarray):
156175
# Get information on the number of faces, tets, and vertices
157176
N_faces_per_tet = 4 # number of faces per element
158177
N_tets = tets.shape[0] # number of elements in the mesh
159-
N_vertices = tets.max() + 1 # number of vertices in the mesh, +1 because indexing starts at 0
178+
# N_vertices = tets.max() + 1 # number of vertices in the mesh, +1 because indexing starts at 0
160179

161180
# Create a unique identifier for each face based on the vertices that make up the face
162181
# the order of the vertices does not matter.
@@ -201,10 +220,8 @@ def __compute_element_connectivity(tets: numpy.ndarray):
201220
# We now sort the face_ids so that we have the identical faces next to each other
202221
face_ids_sort_indices = numpy.argsort(face_ids) # get the ordering that sorts the face_ids
203222
face_ids = face_ids[face_ids_sort_indices] # sort the face ids
204-
face_vertices = face_vertices[face_ids_sort_indices, :] # reorder the faces so that their corresponding
205-
# face_ids are sorted
206-
face_vertices_idx = face_vertices_idx[face_ids_sort_indices] # reorder the face indices so that their
207-
# corresponding face_ids are sorted
223+
face_vertices = face_vertices[face_ids_sort_indices, :] # reorder the faces so that their corresponding face_ids are sorted
224+
face_vertices_idx = face_vertices_idx[face_ids_sort_indices] # reorder the face indices so that their corresponding face_ids are sorted
208225

209226
# Find the indices of face_ids of all interior faces, i.e., that are shared by two elements
210227
# i.e., faces that appear twice (one time for each element)
@@ -257,5 +274,3 @@ def EToV(self):
257274
tetrahedra that make up the mesh. It returns the value in self.tets, since it is the same data."""
258275
return self.tets
259276
# ------------------------------------------------------------------------------------------------------------------
260-
261-

tests/test_mesh.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
import pytest
44
import numpy
5+
import pickle
56

67
import edg_acoustics
78

@@ -11,7 +12,7 @@ def mesh_file_data_valid():
1112
"""Define valid file input data for mesh generation.
1213
"""
1314
# The valid filename with mesh data
14-
filename = "../data/tests/mesh/CoarseMesh.msh"
15+
filename = "data/tests/mesh/CoarseMesh.msh"
1516

1617
return filename
1718

@@ -56,20 +57,28 @@ def BC_labels_data_missing_invalid():
5657

5758

5859
def test_mesh_file_data_valid_input(mesh_file_data_valid, BC_labels_data_valid):
60+
# Load reference mesh from file
61+
with open('data/tests/mesh/Coarse_mesh_object.dat', 'rb') as mesh_file:
62+
mesh_ref = pickle.load(mesh_file)
63+
64+
# Load mesh data from gmsh file
5965
mesh = edg_acoustics.Mesh(mesh_file_data_valid, BC_labels_data_valid)
6066

67+
# Compare mesh to reference data
68+
assert (mesh == mesh_ref)
69+
6170

6271
def test_mesh_file_extra_label_invalid_input(mesh_file_data_valid, BC_labels_data_extra_invalid):
6372
with pytest.raises(ValueError) as excinfo:
64-
mesh = edg_acoustics.Mesh(mesh_file_data_valid, BC_labels_data_extra_invalid)
73+
_ = edg_acoustics.Mesh(mesh_file_data_valid, BC_labels_data_extra_invalid)
6574

6675
assert "[edg_acoustics.Mesh] All BC labels must be present in the mesh and all labels in the mesh must be " \
6776
"present in BC_labels." in str(excinfo.value)
6877

6978

7079
def test_mesh_file_missing_label_invalid_input(mesh_file_data_valid, BC_labels_data_missing_invalid):
7180
with pytest.raises(ValueError) as excinfo:
72-
mesh = edg_acoustics.Mesh(mesh_file_data_valid, BC_labels_data_missing_invalid)
81+
_ = edg_acoustics.Mesh(mesh_file_data_valid, BC_labels_data_missing_invalid)
7382

7483
assert "[edg_acoustics.Mesh] All BC labels must be present in the mesh and all labels in the mesh must be " \
7584
"present in BC_labels." in str(excinfo.value)
@@ -79,7 +88,7 @@ def test_mesh_connectivity(mesh_file_data_valid, BC_labels_data_valid):
7988
mesh = edg_acoustics.Mesh(mesh_file_data_valid, BC_labels_data_valid)
8089

8190
# Load the reference data
82-
reference_data = numpy.load('../data/tests/mesh/CoarseMesh_connectivity.npz')
91+
reference_data = numpy.load('data/tests/mesh/CoarseMesh_connectivity.npz')
8392

8493
# Check if mesh.EToV was correctly generated
8594
assert numpy.abs(mesh.EToV - reference_data['EToV']).sum() == 0

0 commit comments

Comments
 (0)