Skip to content

Commit

Permalink
Merge pull request #1219 from nschloe/topo-dim
Browse files Browse the repository at this point in the history
meshio.topological_dimension
  • Loading branch information
nschloe authored Nov 22, 2021
2 parents 38d6679 + 042c537 commit 4b887cb
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = meshio
version = 5.0.3
version = 5.0.4
author = Nico Schlömer et al.
author_email = [email protected]
description = I/O for many mesh formats
Expand Down
2 changes: 2 additions & 0 deletions src/meshio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
xdmf,
)
from .__about__ import __version__
from ._common import topological_dimension
from ._exceptions import ReadError, WriteError
from ._helpers import extension_to_filetype, read, write, write_points_cells
from ._mesh import CellBlock, Mesh
Expand Down Expand Up @@ -76,5 +77,6 @@
"CellBlock",
"ReadError",
"WriteError",
"topological_dimension",
"__version__",
]
2 changes: 1 addition & 1 deletion src/meshio/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"tetra286": 286,
}

_topological_dimension = {
topological_dimension = {
"line": 1,
"triangle": 2,
"quad": 2,
Expand Down
6 changes: 3 additions & 3 deletions src/meshio/_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import npx
import numpy as np

from ._common import _topological_dimension, num_nodes_per_cell
from ._common import num_nodes_per_cell, topological_dimension


class CellBlock(collections.namedtuple("CellBlock", ["type", "data"])):
Expand Down Expand Up @@ -152,13 +152,13 @@ def remove_lower_dimensional_cells(self):
"""
if not self.cells:
return
max_topological_dim = max(_topological_dimension[c.type] for c in self.cells)
maxtopological_dim = max(topological_dimension[c.type] for c in self.cells)
new_cells = []
new_cell_data = {}
new_cell_sets = {}
prune_set = set()
for idx, c in enumerate(self.cells):
if _topological_dimension[c.type] == max_topological_dim:
if topological_dimension[c.type] == maxtopological_dim:
new_cells.append(c)

for name, data in self.cell_data.items():
Expand Down
6 changes: 3 additions & 3 deletions src/meshio/gmsh/_gmsh40.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import numpy as np

from .._common import (
_topological_dimension,
cell_data_from_raw,
num_nodes_per_cell,
raw_from_cell_data,
topological_dimension,
)
from .._exceptions import ReadError
from .._mesh import Mesh
Expand Down Expand Up @@ -323,7 +323,7 @@ def _write_elements(fh, cells, binary):
for cell_type, node_idcs in cells:
# tagEntity(int) dimEntity(int) typeEle(int) numElements(unsigned long)
np.array(
[1, _topological_dimension[cell_type], _meshio_to_gmsh_type[cell_type]],
[1, topological_dimension[cell_type], _meshio_to_gmsh_type[cell_type]],
dtype=c_int,
).tofile(fh)
np.array([node_idcs.shape[0]], dtype=c_ulong).tofile(fh)
Expand Down Expand Up @@ -358,7 +358,7 @@ def _write_elements(fh, cells, binary):
fh.write(
"{} {} {} {}\n".format(
1, # tag
_topological_dimension[cell_type],
topological_dimension[cell_type],
_meshio_to_gmsh_type[cell_type],
node_idcs.shape[0],
).encode()
Expand Down
10 changes: 5 additions & 5 deletions src/meshio/gmsh/_gmsh41.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import numpy as np

from .._common import (
_topological_dimension,
cell_data_from_raw,
num_nodes_per_cell,
raw_from_cell_data,
topological_dimension,
)
from .._exceptions import ReadError, WriteError
from .._mesh import CellBlock, Mesh
Expand Down Expand Up @@ -431,7 +431,7 @@ def _write_entities(fh, cells, tag_data, cell_sets, point_data, binary):
cell_dim_tags = np.empty((len(cells), 2), dtype=int)
for ci in range(len(cells)):
cell_dim_tags[ci] = [
_topological_dimension[cells[ci][0]],
topological_dimension[cells[ci][0]],
tag_data["gmsh:geometrical"][ci][0],
]

Expand Down Expand Up @@ -601,7 +601,7 @@ def _write_nodes(fh, points, cells, point_data, float_fmt, binary):
+ "to deal with more than one cell type. "
)

dim = _topological_dimension[cells[0][0]]
dim = topological_dimension[cells[0][0]]
tag = 0
node_dim_tags = np.array([[dim, tag]])
# All nodes map to the (single) dimension-entity object
Expand Down Expand Up @@ -673,7 +673,7 @@ def _write_elements(fh, cells, tag_data, binary):
# entityDim(int) entityTag(int) elementType(int)
# numElementsBlock(size_t)

dim = _topological_dimension[cell_type]
dim = topological_dimension[cell_type]
# The entity tag should be equal within a CellBlock
if "gmsh:geometrical" in tag_data:
entity_tag = tag_data["gmsh:geometrical"][ci][0]
Expand Down Expand Up @@ -713,7 +713,7 @@ def _write_elements(fh, cells, tag_data, binary):
for ci, (cell_type, node_idcs) in enumerate(cells):
# entityDim(int) entityTag(int) elementType(int) numElementsBlock(size_t)

dim = _topological_dimension[cell_type]
dim = topological_dimension[cell_type]
# The entity tag should be equal within a CellBlock
if "gmsh:geometrical" in tag_data:
entity_tag = tag_data["gmsh:geometrical"][ci][0]
Expand Down
16 changes: 8 additions & 8 deletions src/meshio/netgen/_netgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from ..__about__ import __version__
from .._common import _topological_dimension
from .._common import topological_dimension
from .._files import open_file
from .._helpers import register
from .._mesh import Mesh
Expand Down Expand Up @@ -169,7 +169,7 @@ def _write_cells(f, block, index=None):
if len(block) == 0:
return
pmap = np.array(meshio_to_netgen_pmap[block.type])
dim = _topological_dimension[block.type]
dim = topological_dimension[block.type]
post_data = []
pre_data = []
i_index = 0
Expand Down Expand Up @@ -219,7 +219,7 @@ def _write_codim_domain_data(f, mesh, cells_index, dim, codim):
for block, index in zip(mesh.cells, cells_index):
if index is None:
continue
if _topological_dimension[block.type] == dim - codim:
if topological_dimension[block.type] == dim - codim:
indices = indices.union(set(index))

for idx in indices:
Expand Down Expand Up @@ -385,7 +385,7 @@ def write_buffer(f, mesh, float_fmt):
cells_index = [None] * len(mesh.cells)

for block in mesh.cells:
cells_per_dim[_topological_dimension[block.type]] += len(block)
cells_per_dim[topological_dimension[block.type]] += len(block)

f.write(f"# Generated by meshio {__version__}\n")
f.write("mesh3d\n\n")
Expand All @@ -400,14 +400,14 @@ def write_buffer(f, mesh, float_fmt):
f.write("surfaceelements\n")
f.write(f"{cells_per_dim[2]}\n")
for block, index in zip(mesh.cells, cells_index):
if _topological_dimension[block.type] == 2:
if topological_dimension[block.type] == 2:
_write_cells(f, block, index)

f.write("\n# matnr np p1 p2 p3 p4\n")
f.write("volumeelements\n")
f.write(f"{cells_per_dim[3]}\n")
for block, index in zip(mesh.cells, cells_index):
if _topological_dimension[block.type] == 3:
if topological_dimension[block.type] == 3:
_write_cells(f, block, index)

f.write(
Expand All @@ -416,7 +416,7 @@ def write_buffer(f, mesh, float_fmt):
f.write("edgesegmentsgi2\n")
f.write(f"{cells_per_dim[1]}\n")
for block, index in zip(mesh.cells, cells_index):
if _topological_dimension[block.type] == 1:
if topological_dimension[block.type] == 1:
_write_cells(f, block, index)

f.write("\n# X Y Z\n")
Expand All @@ -434,7 +434,7 @@ def write_buffer(f, mesh, float_fmt):
f.write("pointelements\n")
f.write(f"{cells_per_dim[0]}\n")
for block, index in zip(mesh.cells, cells_index):
if _topological_dimension[block.type] == 0:
if topological_dimension[block.type] == 0:
_write_cells(f, block, index)

# currently, there is no better place for identification data
Expand Down
5 changes: 0 additions & 5 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
from . import helpers


def test_public_attributes():
# Just make sure this is here
meshio.extension_to_filetype


@pytest.mark.parametrize(
"mesh",
[helpers.tri_mesh, helpers.empty_mesh],
Expand Down
7 changes: 7 additions & 0 deletions tests/test_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import meshio


def test_public_attributes():
# Just make sure this is here
meshio.extension_to_filetype
meshio.topological_dimension

0 comments on commit 4b887cb

Please sign in to comment.