Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowshippo committed Aug 27, 2022
2 parents 7c8385d + 80450d3 commit 763f587
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 4 additions & 2 deletions femio/mesh_compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ def compress(self, *,
self.node_pos = recalc_node_pos(self.node_pos_raw, self.node_conv)
if len(self.node_pos) == 0:
print("compressed to 0 elements. try another parameter")
return
return False
self.calculate_compressed_fem_data()
return True

@lru_cache
def calculate_compressed_fem_data(self):
Expand All @@ -101,7 +102,8 @@ def calculate_compressed_fem_data(self):
data=node_pos)
element_data = np.empty(P, object)
for p in range(P):
element_data[p] = collect_vertex(faces[indptr[p]:indptr[p + 1]])
element_data[p] = collect_vertex(
faces[indptr[p]:indptr[p + 1]]) + 1
polyhedron = femio.FEMAttribute(
'polyhedron',
ids=np.arange(len(element_data)) + 1,
Expand Down
21 changes: 17 additions & 4 deletions tests/test_mesh_compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_calc_centers(self):
[0.24, 0.2, 0.48]
])
actual = calc_centers(csr, node_pos)
print(actual)
np.testing.assert_array_equal(desired, actual)

def test_merge_elements(self):
Expand Down Expand Up @@ -55,7 +54,10 @@ def test_brick(self):
fem_data_1.nodes.data)
for P, Q in zip(new_fem_data.elements.data,
fem_data_1.elements.data):
np.testing.assert_array_equal(P, Q - 1)
np.testing.assert_array_equal(P, Q)
for P, Q in zip(new_fem_data.elemental_data['face'].data,
fem_data_1.elemental_data['face'].data):
np.testing.assert_array_equal(P, Q)

def test_merge_vertices(self):
fem_data = femio.read_files(
Expand All @@ -70,7 +72,13 @@ def test_merge_vertices(self):
fem_data_1.nodes.data)
for P, Q in zip(new_fem_data.elements.data,
fem_data_1.elements.data):
np.testing.assert_array_equal(P, Q - 1)
np.testing.assert_array_equal(P, Q)
for P, Q in zip(new_fem_data.elemental_data['face'].data,
fem_data_1.elemental_data['face'].data):
np.testing.assert_array_equal(P, Q)
inc = new_fem_data.calculate_incidence_matrix().toarray()
np.testing.assert_array_equal(np.where(inc[:, 0])[0], np.array(
[4, 5, 7, 8, 11, 12, 17, 18, 20, 21]))

def test_run_without_err(self):
import itertools
Expand All @@ -82,4 +90,9 @@ def test_run_without_err(self):

for e, c, d in itertools.product(es, cs, ds):
compressor = MeshCompressor(fem_data=fem_data)
compressor.compress(elem_num=e, cos_thresh=c, dist_thresh=d)
ok = compressor.compress(elem_num=e, cos_thresh=c, dist_thresh=d)
if not ok:
continue
compressed_data = compressor.calculate_compressed_fem_data()
compressed_data.calculate_incidence_matrix()
compressed_data.calculate_adjacency_matrix()

0 comments on commit 763f587

Please sign in to comment.