Skip to content

Add Nastran backend#46

Draft
bayswiss wants to merge 4 commits into
scientificcomputing:mainfrom
bayswiss:nastran-backend
Draft

Add Nastran backend#46
bayswiss wants to merge 4 commits into
scientificcomputing:mainfrom
bayswiss:nastran-backend

Conversation

@bayswiss
Copy link
Copy Markdown

@bayswiss bayswiss commented May 6, 2026

Status: Draft - opening for early feedback before adding tests.

Refers #43

Tested manually outside the repo against multiple nastran meshes generated with different commercial preprocessors.

Before polishing I'd like input on where Nastran test inputs should live and what level of testing is needed. Do I commit a small bdf and run a test similar to "test_pyvista.py"?

if not topologies:
raise ValueError(f"No elements found in {filename}.")

elements = []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment here that explains that the main purpose of everything up to Line 329 is to sanity check that we have extracted some elements of a given cell type with a given name.

Copy link
Copy Markdown
Author

@bayswiss bayswiss May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add that

Comment on lines +76 to +86
elements = []
for gmsh_type in topologies:
_, dim, _, n_nodes, *_ = gmsh.model.mesh.getElementProperties(gmsh_type)
elements.append((dim, n_nodes, gmsh_type))

dims = [e[0] for e in elements]
if len(dims) != len(set(dims)):
raise ValueError(
f"Multiple element types share a topological dimension in {filename}."
)
_, num_nodes, gmsh_type = max(elements, key=lambda e: e[0])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is also mainly for error handling/sanity checking perspective?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Nastran mixed meshes (hexa-pyramid-tetra) are very common in some commercial preprocessors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add support for these kinds of meshes, as they are supported in DOLFINx, albeit the interface is very rough. If you have a link to a mixed type mesh I can have a go at improving your API.

@jorgensd
Copy link
Copy Markdown
Member

I think this is a good start. I guess the optimal thing would be to have the nastran grids stored somewhere else (like Zenodo) and fetch them if they are not present on the system. @finsberg what do you think?

@finsberg
Copy link
Copy Markdown
Member

I think this is a good start. I guess the optimal thing would be to have the nastran grids stored somewhere else (like Zenodo) and fetch them if they are not present on the system. @finsberg what do you think?

Nice work @bayswiss. I think this looks very good. Having a test in place where we can test on some real meshes would be good. Perhaps we can just grab some of the meshes from this repo: https://github.com/SteveDoyle2/pyNastran/tree/main/models ?

@bayswiss
Copy link
Copy Markdown
Author

bayswiss commented May 12, 2026

I think this is a good start. I guess the optimal thing would be to have the nastran grids stored somewhere else (like Zenodo) and fetch them if they are not present on the system. @finsberg what do you think?

Nice work @bayswiss. I think this looks very good. Having a test in place where we can test on some real meshes would be good. Perhaps we can just grab some of the meshes from this repo: https://github.com/SteveDoyle2/pyNastran/tree/main/models ?

Thank you @finsberg. I will check 'em out, since pynastran handles complete nastran decks (that contain also simulation instructions). If not present, I can provide a basic one.
Is a test similar to the pyvista one fine?

@finsberg
Copy link
Copy Markdown
Member

I think this is a good start. I guess the optimal thing would be to have the nastran grids stored somewhere else (like Zenodo) and fetch them if they are not present on the system. @finsberg what do you think?

Nice work @bayswiss. I think this looks very good. Having a test in place where we can test on some real meshes would be good. Perhaps we can just grab some of the meshes from this repo: https://github.com/SteveDoyle2/pyNastran/tree/main/models ?

Thank you @finsberg. I will check 'em out, since pynastran handles complete nastran decks (that contain also simulation instructions). If not present, I can provide a basic one. Is a test similar to the pyvista one fine?

A simliar test as the pyvista one if fine. The most important thing is to have a test in place that tests the basic functionality. I don't know if there are a lot of variations in nastran files, but might be good to have some tests that covers the common scenarios. For example if mixed cell types are common it is good to have test for that.

It is also possible to add a step in in the test_workflow.yml which can download the data used by the tests. Whether this is from another repository (like pynastran) or Zenodo doesn't really matter.

@bayswiss
Copy link
Copy Markdown
Author

bayswiss commented May 12, 2026

A simliar test as the pyvista one if fine. The most important thing is to have a test in place that tests the basic functionality. I don't know if there are a lot of variations in nastran files, but might be good to have some tests that covers the common scenarios. For example if mixed cell types are common it is good to have test for that.

It is also possible to add a step in in the test_workflow.yml which can download the data used by the tests. Whether this is from another repository (like pynastran) or Zenodo doesn't really matter.

I will start working on the basic test. Regarding mixed meshes, what am I missing? is dolfinx going to support them soon (I am on 0.10.0 currently)?

@jorgensd
Copy link
Copy Markdown
Member

A simliar test as the pyvista one if fine. The most important thing is to have a test in place that tests the basic functionality. I don't know if there are a lot of variations in nastran files, but might be good to have some tests that covers the common scenarios. For example if mixed cell types are common it is good to have test for that.
It is also possible to add a step in in the test_workflow.yml which can download the data used by the tests. Whether this is from another repository (like pynastran) or Zenodo doesn't really matter.

I will start working on the basic test. Regarding mixed meshes, what am I missing? is dolfinx going to support them soon (I am on 0.10.0 currently)?

There is already partial support for mixed meshes. The PR I opened today makes it possible to read those meshes from gmsh: FEniCS/dolfinx#4214

@bayswiss
Copy link
Copy Markdown
Author

bayswiss commented May 15, 2026

@jorgensd Sorry for the slow reply. Here's an example of what is sometimes called a "hexcore" mesh:
hexacore.zip

The idea is to fill the bulk of the domain with a Cartesian hex grid and use tets only near the boundary to handle geometric complexity, with pyramids as transition elements. The appeal is getting most of the numerical benefits of a structured hex mesh without actually having to build one.

One concern for wave propagation applications: the hex-pyramid-tet interface introduces a local change in dispersion characteristics, which can act as a weak spurious reflector. Not a dealbreaker, but worth keeping in mind depending on the frequency range (I actually don't use it but I've seen it a lot).

image

P.S. The parallelepiped is just to show the element structure, obviously nobody would use a mixed mesh approach on a geometry this simple.

@jorgensd
Copy link
Copy Markdown
Member

@jorgensd Sorry for the slow reply. Here's an example of what is sometimes called a "hexcore" mesh:

hexacore.zip

The idea is to fill the bulk of the domain with a Cartesian hex grid and use tets only near the boundary to handle geometric complexity, with pyramids as transition elements. The appeal is getting most of the numerical benefits of a structured hex mesh without actually having to build one.

One concern for wave propagation applications: the hex-pyramid-tet interface introduces a local change dispersion characteristics, which can act as a weak spurious reflector. Not a dealbreaker, but worth keeping in mind depending on the frequency range (I actually don't use it but I've seen it a lot).

image

P.S. The parallelepiped is just to show the element structure, obviously nobody would use a mixed mesh approach on a geometry this simple.

No worries, as you see, there were some missing pieces in the gmshio code to read such meshes, which should hopefully be resolved with my PR.

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.

3 participants