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

Feature: npz export for gustaf objects #149

Closed
wants to merge 3 commits into from

Conversation

Roxana-P
Copy link
Contributor

@Roxana-P Roxana-P commented Aug 4, 2023

Gustaf already has great options for exporting meshes to nutils, mixd and with the help of meshio.
However, what if I want already have a gustaf mesh and just want to save it for later, or another script using gustaf?
This npz extension can save all kinds of gustaf entities - volumes, faces, edges and vertices. It saves not only the vertices and elements, but also the vertex data and boundary information. Thereby it is very suitable for saving meshes for interactive later or repetitive visualization.

Example:

import gustaf
import numpy as np

# Define coordinates
vertices = np.array(
    [
        [0.0, 0.0, 0.0],
        [1.0, 0.0, 0.0],
        [0.0, 1.0, 0.0],
        [1.0, 1.0, 0.0],
        [0.0, 0.0, 1.0],
        [1.0, 0.0, 1.0],
        [0.0, 1.0, 1.0],
        [1.0, 1.0, 1.0],
    ]
)

# Define hexa connectivity
hv = np.array([[0, 1, 3, 2, 4, 5, 7, 6]])

# Init hexa elements
hexa = gustaf.Volumes(
    vertices=vertices,
    volumes=hv,
)

# Create hexa elements and set vertex data
hexa.vertex_data['arange'] = np.arange(len(vertices))
hexa.vertex_data['quad_x'] = [v[0]**2 for v in vertices]
hexa.BC = {'min_z' : np.array([0, 1, 2, 3]),
'max_z' : np.array([4, 5, 6, 7])}

# Export hexa
gustaf.io.npz.export(hexa, 'hexa.npz')

load = gustaf.load('hexa.npz')

@j042
Copy link
Member

j042 commented Sep 7, 2023

thanks for this PR, could you add show_options?

@j042 j042 requested review from clemens-fricke and j042 and removed request for clemens-fricke September 7, 2023 11:31
@j042 j042 closed this Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants