Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meshio fix bug netgen .vol import , ignore 'facedescriptors' and 'fac… #1452

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/meshio/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def _read_file(path: Path, file_format: str | None):
if not path.exists():
raise ReadError(f"File {path} not found.")

error_msgs = ""
if file_format:
possible_file_formats = [file_format]
else:
Expand All @@ -102,16 +103,19 @@ def _read_file(path: Path, file_format: str | None):
try:
return reader_map[file_format](str(path))
except ReadError as e:
print(e)
#print(e)
error_msgs += str(e) + "\n"


if len(possible_file_formats) == 1:
msg = f"Couldn't read file {path} as {possible_file_formats[0]}"
else:
lst = ", ".join(possible_file_formats)
msg = f"Couldn't read file {path} as either of {lst}"

error(msg)
sys.exit(1)
# error(msg)
# sys.exit(1)
raise ReadError(msg+":\n"+error_msgs)


def write_points_cells(
Expand Down
53 changes: 53 additions & 0 deletions src/meshio/mdpa/_mdpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,56 @@
"Hexahedra3D20": "hexahedron20",
}

def _guess_element_type_from_MDPA_name(name) :
t = None
element_name=name.split('//')[0]
if element_name=='Sphere3D'or element_name=='SphericContinuumParticle3D' or element_name=='SphericParticle3D':
t="sphere"
elif element_name=='CylinderContinuumParticle2D' or element_name=='CylinderParticle2D':
t="circle"
else:
dim=int(element_name[-4])
nnodes=int(element_name[-2])
if nnodes==1:
t="vertex"
elif nnodes==2:
t="line"
elif nnodes==3:
if dim==1:
t='line3'
else:
t='triangle'
elif nnodes==4:
if dim==2:
t='quad'
else:
t='tetra'
elif nnodes==5:
t='pyramid'
elif nnodes==6:
if dim==2:
t='triangle6'
else:
t='wedge'
elif nnodes==8:
if dim==2:
t='quad8'
else:
t='hexahedron'
elif nnodes==9:
t='quad9'
elif nnodes==10:
t='tetra10'
elif nnodes==13:
t='pyramid13'
elif nnodes==18:
t='wedge18'
elif nnodes==20:
t='hexahedron20'
elif nnodes==27:
t='hexahedron27'
return t

_meshio_to_mdpa_type = {
"line": "Line2D2",
"triangle": "Triangle2D3",
Expand Down Expand Up @@ -137,6 +187,9 @@ def _read_cells(f, cells, is_ascii, cell_tags, environ=None):
if key in entity_name:
t = _mdpa_to_meshio_type[key]
break
if t is None:
t=_guess_element_type_from_MDPA_name(entity_name)

elif environ.startswith("Begin Conditions "):
entity_name = environ[17:]
for key in _mdpa_to_meshio_type:
Expand Down
2 changes: 2 additions & 0 deletions src/meshio/netgen/_netgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ def read_buffer(f):
"singular_face_inside",
"singular_face_outside",
"singular_points",
"facedescriptors",
"face_transparencies",
]:
_skip_block(f)
else:
Expand Down
27 changes: 23 additions & 4 deletions src/meshio/off/_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,29 @@ def read_buffer(f):
verts = np.fromfile(f, dtype=float, count=3 * num_verts, sep=" ").reshape(
num_verts, 3
)
data = np.fromfile(f, dtype=int, count=4 * num_faces, sep=" ").reshape(num_faces, 4)
if not np.all(data[:, 0] == 3):
raise ReadError("Can only read triangular faces")
cells = [CellBlock("triangle", data[:, 1:])]
cells=""
if num_faces :
#identify the number of nodes of the first face (and assume all faces with same amount, but can be false!!)
file_position=f.tell()
line = f.readline().strip()
f.seek(file_position)
num_nodes_face=int(line.split(" ")[0])
element=""
if num_nodes_face==3 :
element="triangle"
elif num_nodes_face==4 :
element="quad"
elif num_nodes_face>0 :
element="polygon"
else :
element=""
if num_nodes_face>0 :
data = np.fromfile(f, dtype=int, count=(num_nodes_face+1)*num_faces, sep=" ").reshape(num_faces, num_nodes_face+1)
if not np.all(data[:, 0] == num_nodes_face):
raise ReadError("Can only read faces with same amount of nodes "+str(num_nodes_face))
cells = [CellBlock(element, data[:, 1:])]
else :
raise ReadError("Unexpected number of nodes by face"+str(num_nodes_face))

return verts, cells

Expand Down