-
Notifications
You must be signed in to change notification settings - Fork 8
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
Redo #143 #151
Closed
Closed
Redo #143 #151
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b35352d
Add meshio load support for all currently gustaf-compartible element …
Roxana-P 93963e4
Add processing of field variable into boundary conditions
Roxana-P 6d434f1
Removemanually set function value
Roxana-P d0ef46b
Add optional keyword arguments to default load function
Roxana-P 2f0e155
Add physical groups for old gmsh format
Roxana-P 41a0463
Add an example of returning all submeshes in meshio.load
Roxana-P da5d333
Add showing the boundary nodes in the example
Roxana-P d11c475
Remove unnessary code
Roxana-P 1208ca5
Review comments gustaf/io/meshio.py
Roxana-P a26f9aa
Update examples/show_gmsh.py
Roxana-P c629255
Formatting
Roxana-P 716dd53
File path change
Roxana-P 15f4409
File path change
Roxana-P 64e73d8
Jae's suggestions
Roxana-P 58eb33a
Jae's suggestions
Roxana-P File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import numpy as np | ||
|
||
from gustaf.edges import Edges | ||
from gustaf.faces import Faces | ||
from gustaf.helpers.raise_if import ModuleImportRaiser | ||
from gustaf.volumes import Volumes | ||
|
@@ -18,58 +19,91 @@ | |
# from meshio import Mesh as MeshioMesh | ||
|
||
|
||
def load(fname): | ||
def load(fname, set_boundary=True): | ||
"""Load mesh in meshio format. Loads vertices and their connectivity. | ||
Currently cannot process boundary. | ||
|
||
Note | ||
----- | ||
This is more or less a direct copy from the original gustav implementation. | ||
A lot of the meshio information are lost. When boundaries and multi-patch | ||
definitions are added this needs to be revisited and extended. | ||
The function reads all gustaf-processable element types from meshio, which | ||
are sorted by the dimensionality of their element types. Different | ||
elements can occur at the same dimensionality, e.g., in mixed meshes, | ||
or as sub-topologies, e.g., as boundaries or interfaces. | ||
|
||
If set_boundary is set true, all (d-1)-dimensional submesh node identifiers | ||
are assigned to MESH_TYPES.BC without check. | ||
|
||
Return_only_one_mesh ensures compatibility with previous gustaf versions. | ||
|
||
Loading physical groups is not supported yet. | ||
|
||
Parameters | ||
------------ | ||
fname: str | pathlib.Path | ||
Input filename | ||
set_boundary : bool, optional, default is False | ||
Assign nodes of lower-dimensional meshes mesh.BC | ||
return_only_one_mesh : bool, optional, default is True | ||
Return only the highest-dimensional mesh, ensures compartibility. | ||
|
||
Returns | ||
-------- | ||
MESH_TYPES | ||
MESH_TYPES or list(MESH_TYPES) | ||
""" | ||
mesh_type = Faces | ||
|
||
fname = pathlib.Path(fname) | ||
if not (fname.exists() and fname.is_file()): | ||
raise ValueError( | ||
"The given file does not point to file. The given path is: " | ||
f"{fname.resolve()}" | ||
) | ||
|
||
# Read mesh | ||
meshio_mesh: meshio.Mesh = meshio.read(fname) | ||
vertices = meshio_mesh.points | ||
|
||
# check for 2D mesh | ||
# Try for triangle grid | ||
cells = meshio_mesh.get_cells_type("triangle") | ||
# If no triangle elements, try for square | ||
if len(cells) == 0: | ||
cells = meshio_mesh.get_cells_type("quad") | ||
if not len(cells) > 0: | ||
# 3D mesh | ||
mesh_type = Volumes | ||
cells = meshio_mesh.get_cells_type("tetra") | ||
if len(cells) == 0: | ||
cells = meshio_mesh.get_cells_type("hexahedron") | ||
|
||
for i, cell in enumerate(cells): | ||
if i == 0: | ||
elements = cell.data | ||
else: | ||
elements = np.vstack((elements, cell.data)) | ||
|
||
mesh = mesh_type(vertices=vertices, elements=elements) | ||
# Maps meshio element types to gustaf types and dimensionality | ||
# Meshio vertex elements are ommited, as they do not follow gustaf logics | ||
meshio_mapping = { | ||
"hexahedron": [Volumes, 3], | ||
"tetra": [Volumes, 3], | ||
"quad": [Faces, 2], | ||
"triangle": [Faces, 2], | ||
"line": [Edges, 1], | ||
} | ||
meshes = [ | ||
[ | ||
meshio_mapping[key][0]( | ||
vertices=vertices, elements=meshio_mesh.cells_dict[key] | ||
), | ||
meshio_mapping[key][1], | ||
] | ||
for key in meshio_mapping.keys() | ||
if key in meshio_mesh.cells_dict.keys() | ||
] | ||
# Sort by decreasing dimensionality | ||
meshes.sort(key=lambda x: -x[1]) | ||
|
||
# Raises exception if the mesh file contains gustaf-incompartible types | ||
for elem_type in meshio_mesh.cells_dict.keys(): | ||
if elem_type not in list(meshio_mapping.keys()) + ["vertex"]: | ||
# Be aware that gustaf currently only supports linear element | ||
# types. | ||
raise NotImplementedError( | ||
f"Sorry, {elem_type} elements currently are not supported." | ||
) | ||
|
||
return mesh | ||
if set_boundary is True: | ||
# mesh.BC is only defined for volumes and faces | ||
for i in range(len(meshes)): | ||
# Indicator for boundary | ||
if meshes[i][1] in [3, 2]: | ||
for j in range(i, len(meshes)): | ||
# Considers only (d-1)-dimensional subspaces | ||
if meshes[j][1] == meshes[i][1] - 1: | ||
meshes[i][0].BC[ | ||
f"{meshes[j][0].whatami}-nodes" | ||
] = np.unique(meshes[j][0].elements) | ||
Comment on lines
+100
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you often have BC for edges or is this some sort of masks for faces/volumes? |
||
|
||
return_value = [mesh[0] for mesh in meshes] | ||
|
||
return return_value | ||
|
||
|
||
def export(mesh, fname, submeshes=None, **kwargs): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please just write a normal for loop here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not resolved