Add Nastran backend#46
Conversation
| if not topologies: | ||
| raise ValueError(f"No elements found in {filename}.") | ||
|
|
||
| elements = [] |
There was a problem hiding this comment.
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.
| 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]) |
There was a problem hiding this comment.
I guess this is also mainly for error handling/sanity checking perspective?
There was a problem hiding this comment.
Yes. Nastran mixed meshes (hexa-pyramid-tetra) are very common in some commercial preprocessors
There was a problem hiding this comment.
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.
|
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. |
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 |
|
@jorgensd Sorry for the slow reply. Here's an example of what is sometimes called a "hexcore" mesh: 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).
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. |

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"?