Skip to content

hertzforge.io.nastran

nastran

Read and write Nastran bulk data decks (.bdf, .dat, .nas) as geometry.

The bulk data card formats are documented in every Nastran vendor's reference guide, and this reader is written from those card layouts. INCLUDE files are read relative to the deck. Lines before BEGIN BULK (executive and case control) and after ENDDATA are ignored; a file with neither marker is read as all bulk data. Small-field, large-field and free-field (comma) cards are all read.

What is read:

  • GRID points, with their definition (CP) and displacement (CD) coordinate systems. Positions are converted to the basic frame.
  • CORD2R, CORD2C and CORD2S coordinate systems, with chains of references resolved. A system defined in a cylindrical or spherical system is refused.
  • The connection elements CROD, CBAR, CBEAM, CTRIA3, CTRIA6, CQUAD4, CQUAD8, CTETRA, CPENTA, CHEXA and CPYRAM, one element group per property id. The node count picks the variant (CTETRA with 4 grids is a tet4, with 10 a tet10).
  • PSOLID, PSHELL and MAT1, as the properties of each element group: the material, and a shell's thickness. A group whose cards are not all in the deck has no properties.
  • CONM2 point masses, one element group per distinct mass. A CONM2 with an offset or inertia is read as an element with no properties.
  • CELAS1 (with its PELAS) and CELAS2 springs, one element group per distinct stiffness and direction. A spring joining two different components, or acting on a scalar point, is refused.
  • SPC and SPC1 supports, one ground group per distinct set of components. A deck with more than one SPC set, or an SPC that enforces a displacement, is refused.
  • PLOTEL, Nastran's display-only line, as one drawn line.

What is not read:

  • Loads, other property and material cards, and control cards. These describe the analysis, not the mesh, and are skipped by card name without a note.
  • Rigid elements (RBE1, RBE2, RBE3, RBAR, RBAR1, RROD, RTRPLT, RSPLINE), which are constraints with no mesh, and are skipped.
  • CORD1R, CORD1C and CORD1S (systems defined by grid points) are refused with an error that says to redefine them as CORD2 cards, since a guessed frame would place every node in it wrongly.
  • Any other C card shaped like an element is refused with its name, so an element is never dropped without a word.

A deck has no units, so positions and properties are read as written, and the geometry is marked as a deck's (Geometry.from_deck). length_unit declares the length the deck is written in and mass_unit its mass, with seconds: the consistent system a deck uses, from which force, stress and density follow (mm with tonnes is N and MPa, inches with lbf·s²/in is lbf and psi). The mass unit may be left out for the usual one with that length (geometry.DECK_MASS_UNITS). Declared here or later on the geometry (Geometry.define_units), the coordinates and every property value are converted to SI together.

save writes coordinate systems as CORD2 cards, grids as large-field GRID* cards (full precision, where a small field holds about five digits), elements on their own cards and drawn lines as PLOTEL chains. The deck is geometry for interchange: it opens in viewers and preprocessors, and needs property and material cards added before Nastran will run it.

Functions:

Name Description
sniff

True for a .bdf, .dat or .nas file whose first 64 kB holds

load

Read a bulk data deck's mesh as a Geometry.

handles

True for a Geometry, the only thing a deck is written from.

save

Write a geometry as a bulk deck.

Classes

Functions:

sniff

sniff(path: str | PathLike) -> bool

True for a .bdf, .dat or .nas file whose first 64 kB holds BEGIN BULK or a line opening with GRID, CEND or SOL.

Many programs write .dat, so the suffix alone is not enough.

load

load(path: str | PathLike, length_unit: str | None = None, mass_unit: str | None = None) -> Any

Read a bulk data deck's mesh as a Geometry.

length_unit and mass_unit declare the consistent system the deck is written in (see the module docstring); without them the values are read as written, and a mass unit without a length unit is refused. Raises ValueError for the cards the module docstring lists as refused.

handles

handles(obj: Any) -> bool

True for a Geometry, the only thing a deck is written from.

save

save(geometry: Geometry, path: str | PathLike, unit_system: Any = None) -> None

Write a geometry as a bulk deck.

The deck is geometry for interchange, not a runnable analysis. The elements have PID 1 and no PSHELL, PSOLID or MAT cards are written, because properties are the analyst's statement about the structure and writing made-up ones would put a wrong stiffness in a real deck. Masses, springs and supports are written, since their values are part of the geometry: a point mass is a CONM2 with its element group's mass (0.0 when the group has none), a group of springs is one CELAS2 per element and direction with its stiffness, and a ground group is SPC1 cards (set 1) of its components. Grids are written large-field in the coordinate system each one is defined in, for full precision, and drawn lines are written as PLOTEL chains.

Values are written as the geometry stores them: SI when its units are defined. unit_system is accepted and not used.

Raises ValueError for an element type with no bulk card.