lsdyna-mesh-reader 0.1.4__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. lsdyna_mesh_reader-0.2.1/.gitattributes +6 -0
  2. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/PKG-INFO +7 -4
  3. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/pyproject.toml +19 -10
  4. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/deck.cpp +12 -9
  5. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/_deck.pyi +5 -1
  6. lsdyna_mesh_reader-0.2.1/src/lsdyna_mesh_reader/_version.py +24 -0
  7. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/deck.py +75 -11
  8. lsdyna_mesh_reader-0.2.1/tools/extract-deps.py +8 -0
  9. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/CMakeLists.txt +0 -0
  10. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/LICENSE +0 -0
  11. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/README.md +0 -0
  12. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/_templates/autosummary/base.rst +0 -0
  13. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/_templates/autosummary/class.rst +0 -0
  14. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/_templates/autosummary/module.rst +0 -0
  15. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/_templates/custom-class-template.rst +0 -0
  16. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/_templates/custom-module-template.rst +0 -0
  17. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/api.rst +0 -0
  18. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/conf.py +0 -0
  19. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/docs/source/index.md +0 -0
  20. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/array_support.h +0 -0
  21. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/__init__.py +0 -0
  22. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/examples/EXP_SC_JOINT_SCREW.key +0 -0
  23. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/examples/__init__.py +0 -0
  24. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/examples/bird.k +0 -0
  25. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/examples/birdball.k +0 -0
  26. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/examples/bracket.k +0 -0
  27. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/examples/ex_13_thick_shell_elform_2.k +0 -0
  28. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/examples/wheel.k +0 -0
  29. {lsdyna-mesh-reader-0.1.4 → lsdyna_mesh_reader-0.2.1}/src/lsdyna_mesh_reader/py.typed +0 -0
@@ -0,0 +1,6 @@
1
+ # LS-DYNA keyword decks are fixed-width: a field is identified by its column,
2
+ # so an end-of-line conversion on checkout would put a stray CR inside the last
3
+ # field of every line. Hand them over byte for byte on every platform.
4
+ *.k binary
5
+ *.key binary
6
+ *.dyn binary
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: lsdyna-mesh-reader
3
- Version: 0.1.4
3
+ Version: 0.2.1
4
4
  Summary: Read nodes and elements from LS-DYNA decks.
5
5
  Author-Email: Alex Kaszynski <akascap@gmail.com>
6
6
  Classifier: Development Status :: 4 - Beta
@@ -10,14 +10,14 @@ Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: Microsoft :: Windows
11
11
  Classifier: Operating System :: POSIX
12
12
  Classifier: Operating System :: MacOS
13
- Classifier: Programming Language :: Python :: 3.9
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
18
  Project-URL: Documentation, https://akaszynski.github.io/lsdyna-mesh-reader/
19
19
  Project-URL: Repository, https://github.com/akaszynski/lsdyna-mesh-reader
20
- Requires-Python: >=3.9
20
+ Requires-Python: >=3.10
21
21
  Requires-Dist: numpy>=1.22.4
22
22
  Provides-Extra: docs
23
23
  Requires-Dist: pydata-sphinx-theme; extra == "docs"
@@ -27,6 +27,9 @@ Requires-Dist: sphinx-copybutton; extra == "docs"
27
27
  Requires-Dist: myst-parser; extra == "docs"
28
28
  Provides-Extra: pyvista
29
29
  Requires-Dist: pyvista; extra == "pyvista"
30
+ Provides-Extra: tests
31
+ Requires-Dist: pytest; extra == "tests"
32
+ Requires-Dist: pyvista; extra == "tests"
30
33
  Description-Content-Type: text/markdown
31
34
 
32
35
  # LS-DYNA Mesh Reader
@@ -1,6 +1,6 @@
1
1
  [build-system]
2
2
  build-backend = "scikit_build_core.build"
3
- requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.2"]
3
+ requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.2", "setuptools_scm"]
4
4
 
5
5
  [project]
6
6
  authors = [
@@ -14,24 +14,25 @@ classifiers = [
14
14
  "Operating System :: Microsoft :: Windows",
15
15
  "Operating System :: POSIX",
16
16
  "Operating System :: MacOS",
17
- "Programming Language :: Python :: 3.9",
18
17
  "Programming Language :: Python :: 3.10",
19
18
  "Programming Language :: Python :: 3.11",
20
19
  "Programming Language :: Python :: 3.12",
21
- "Programming Language :: Python :: 3.13"
20
+ "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Python :: 3.14"
22
22
  ]
23
23
  dependencies = [
24
24
  "numpy>=1.22.4"
25
25
  ]
26
26
  description = "Read nodes and elements from LS-DYNA decks."
27
+ dynamic = ["version"]
27
28
  name = "lsdyna-mesh-reader"
28
29
  readme = "README.md"
29
- requires-python = ">=3.9"
30
- version = "0.1.4"
30
+ requires-python = ">=3.10"
31
31
 
32
32
  [project.optional-dependencies]
33
33
  docs = ["pydata-sphinx-theme", "numpydoc", "sphinx", "sphinx-copybutton", "myst-parser"]
34
34
  pyvista = ["pyvista"]
35
+ tests = ["pytest", "pyvista"]
35
36
 
36
37
  [project.urls]
37
38
  Documentation = "https://akaszynski.github.io/lsdyna-mesh-reader/"
@@ -39,9 +40,10 @@ Repository = "https://github.com/akaszynski/lsdyna-mesh-reader"
39
40
 
40
41
  [tool.cibuildwheel]
41
42
  archs = ["auto64"] # 64-bit only
42
- skip = "cp38-* cp314-* pp* *musllinux*" # 3.9-3.13 and no PyPy and musl-based wheels
43
- test-command = "pytest {project}/tests -v"
44
- test-requires = "pytest pyvista"
43
+ build = "cp310-* cp311-* cp312-*" # Only build Python 3.10 - 3.12 since 3.12 is ABI3
44
+ skip = "*musllinux*"
45
+ test-command = "pytest {project}/tests -vv"
46
+ test-extras = ["tests"]
45
47
 
46
48
  [tool.cibuildwheel.macos]
47
49
  archs = ["native"]
@@ -75,6 +77,13 @@ extend-select = ["I"]
75
77
  [tool.scikit-build]
76
78
  # Setuptools-style build caching in a local directory
77
79
  build-dir = "build/{wheel_tag}"
78
- minimum-version = "0.4"
80
+ metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
79
81
  sdist.exclude = [".github", "*.png", "tests", ".mypy_cache", ".pre-commit-config.yaml", "*_cache", "CONTRIBUTING.md", ".gitignore"]
80
- sdist.include = ["*.cpp"]
82
+ sdist.include = ["*.cpp", "*.h", "src/lsdyna_mesh_reader/_version.py"]
83
+ wheel.py-api = "cp312"
84
+
85
+ [tool.setuptools_scm]
86
+ fallback_version = "0.0.0.dev0"
87
+ git_describe_command = "git describe --dirty --tags --long --match v*"
88
+ tag_regex = "^v(?P<version>[0-9]+\\.[0-9]+\\.[0-9]+(?:[abrc][0-9]+)?(?:\\.post[0-9]+)?(?:\\.dev[0-9]+)?)$"
89
+ version_file = "src/lsdyna_mesh_reader/_version.py"
@@ -534,7 +534,13 @@ struct ElementSolidSection : public ElementSection {
534
534
  }
535
535
 
536
536
  // convert cells, offset, and celltypes to vtk style arrays
537
- nb::tuple ToVTK() {
537
+ nb::tuple ToVTK(const bool vtk_97_wedges) {
538
+ // Select the LS-DYNA-to-VTK node mapping once, before assembling cells.
539
+ // https://docs.vtk.org/en/latest/release_details/9.7/fix-wedge-point-ordering.html
540
+ static constexpr int legacy_wedge_nodes[6] = {0, 1, 4, 3, 2, 5};
541
+ static constexpr int vtk_97_wedge_nodes[6] = {0, 4, 1, 3, 5, 2};
542
+ const int *wedge_nodes =
543
+ vtk_97_wedges ? vtk_97_wedge_nodes : legacy_wedge_nodes;
538
544
  NDArray<uint8_t, 1> celltypes_arr = MakeNDArray<uint8_t, 1>({(int)n_elem});
539
545
  NDArray<int64_t, 1> offsets_arr =
540
546
  MakeNDArray<int64_t, 1>({(int)(n_elem + 1)});
@@ -566,13 +572,9 @@ struct ElementSolidSection : public ElementSection {
566
572
  el_sz = 4;
567
573
  } else if (node_ids_data[offset + 5] == node_ids_data[offset + 6]) {
568
574
  celltypes[i] = VTK_WEDGE;
569
- // map to vtk style
570
- cells[c++] = node_ids_data[offset + 0];
571
- cells[c++] = node_ids_data[offset + 1];
572
- cells[c++] = node_ids_data[offset + 4];
573
- cells[c++] = node_ids_data[offset + 3];
574
- cells[c++] = node_ids_data[offset + 2];
575
- cells[c++] = node_ids_data[offset + 5];
575
+ for (int j = 0; j < 6; ++j) {
576
+ cells[c++] = node_ids_data[offset + wedge_nodes[j]];
577
+ }
576
578
  el_sz = 6;
577
579
  } else {
578
580
  celltypes[i] = VTK_HEXAHEDRON;
@@ -985,7 +987,8 @@ NB_MODULE(_deck, m) {
985
987
  .def(nb::init())
986
988
  .def("__repr__", &ElementSolidSection::ToString)
987
989
  .def("__len__", &ElementSolidSection::Length)
988
- .def("to_vtk", &ElementSolidSection::ToVTK)
990
+ .def("to_vtk", &ElementSolidSection::ToVTK,
991
+ nb::arg("vtk_97_wedges") = false)
989
992
  .def_ro("eid", &ElementSolidSection::eid, nb::rv_policy::automatic)
990
993
  .def_ro("pid", &ElementSolidSection::pid, nb::rv_policy::automatic)
991
994
  .def_ro("node_ids", &ElementSolidSection::node_ids,
@@ -38,7 +38,11 @@ class ElementSection:
38
38
  def to_vtk(self) -> Tuple[LongArray1D, LongArray1D, Uint8Array1D]: ...
39
39
 
40
40
  class ElementShellSection(ElementSection): ...
41
- class ElementSolidSection(ElementSection): ...
41
+
42
+ class ElementSolidSection(ElementSection):
43
+ def to_vtk(
44
+ self, vtk_97_wedges: bool = False
45
+ ) -> Tuple[LongArray1D, LongArray1D, Uint8Array1D]: ...
42
46
 
43
47
  class _Deck:
44
48
  def __init__(self, fname: str) -> None: ...
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.2.1'
22
+ __version_tuple__ = version_tuple = (0, 2, 1)
23
+
24
+ __commit_id__ = commit_id = 'g9f6cabd'
@@ -21,6 +21,43 @@ if TYPE_CHECKING:
21
21
  pass
22
22
 
23
23
 
24
+ #: Largest value ``int32`` cell arrays can hold. VTK stores 32-bit offsets and
25
+ #: connectivity natively, at half the memory of the 64-bit ``ID_TYPE``, so the
26
+ #: grid is built from ``int32`` whenever the deck indexes fewer points than
27
+ #: this.
28
+ _INT32_MAX = np.iinfo(np.int32).max
29
+
30
+
31
+ def _uniform_cell_width(offsets: NDArray[np.integer]) -> Union[int, None]:
32
+ """Return the points per cell when every cell is the same width.
33
+
34
+ Parameters
35
+ ----------
36
+ offsets : numpy.ndarray
37
+ ``(n_cells + 1,)`` offsets into the connectivity.
38
+
39
+ Returns
40
+ -------
41
+ int | None
42
+ Points per cell, or ``None`` when the widths vary or there are no
43
+ cells. Every cell has to be the same width, so a deck of quads alone
44
+ or hexahedra alone is uniform, while one mixing quads with triangles,
45
+ or shells with solids, is not.
46
+
47
+ """
48
+ if offsets.size < 2:
49
+ return None
50
+
51
+ width = int(offsets[1] - offsets[0])
52
+
53
+ # a single subtraction rejects the mixed case before scanning every offset
54
+ if width * (offsets.size - 1) != int(offsets[-1] - offsets[0]):
55
+ return None
56
+ if (np.diff(offsets) != width).any():
57
+ return None
58
+ return width
59
+
60
+
24
61
  class Deck:
25
62
  r"""LS-DYNA deck.
26
63
 
@@ -194,19 +231,26 @@ class Deck:
194
231
  try:
195
232
  import pyvista as pv
196
233
  from pyvista import ID_TYPE, CellArray
234
+ from pyvista._vtk import numpy_to_vtk, vtkCellArray
197
235
  from pyvista.core.pointset import UnstructuredGrid
198
- from vtkmodules.util.numpy_support import numpy_to_vtk
199
- except ImportError:
200
- pass
236
+ except ImportError as exc:
237
+ msg = "Deck.to_grid requires PyVista. Install it with: pip install pyvista"
238
+ raise ImportError(msg) from exc
201
239
 
202
240
  if not self.node_sections:
203
241
  raise RuntimeError("Missing node sections. Unable to generate UnstructuredGrid.")
204
242
 
205
243
  node_section = self.node_sections[0]
206
244
 
245
+ n_points = len(node_section)
246
+
247
+ # Point indices only have to reach n_points, so int32 covers any deck
248
+ # short of 2**31 nodes and keeps the connectivity half the size.
249
+ index_dtype = np.int32 if n_points <= _INT32_MAX else ID_TYPE
250
+
207
251
  # map between the node ids and a sequential index
208
- id_map = np.empty(node_section.nid[-1] + 1, dtype=ID_TYPE)
209
- id_map[node_section.nid] = np.arange(len(node_section), dtype=ID_TYPE)
252
+ id_map = np.empty(node_section.nid[-1] + 1, dtype=index_dtype)
253
+ id_map[node_section.nid] = np.arange(n_points, dtype=index_dtype)
210
254
 
211
255
  element_sections = self.element_shell_sections + self.element_solid_sections
212
256
 
@@ -214,12 +258,18 @@ class Deck:
214
258
  raise NotImplementedError("Deck missing element sections")
215
259
 
216
260
  # add shell sections
217
- offsets: List[NDArray[np.int64]] = []
261
+ offsets: List[NDArray[np.integer]] = []
218
262
  celltypes: List[NDArray[np.uint8]] = []
219
- cells: List[NDArray[np.int64]] = []
263
+ cells: List[NDArray[np.integer]] = []
220
264
  part_ids = []
265
+ vtk_97_wedges = pv.vtk_version_info >= (9, 7)
221
266
  for section in element_sections:
222
- section_cells, section_offset, section_celltypes = section.to_vtk()
267
+ if isinstance(section, ElementSolidSection):
268
+ section_cells, section_offset, section_celltypes = section.to_vtk(
269
+ vtk_97_wedges=vtk_97_wedges
270
+ )
271
+ else:
272
+ section_cells, section_offset, section_celltypes = section.to_vtk()
223
273
  if offsets:
224
274
  # we need to shift by the last value of the last offset
225
275
  offsets.append(section_offset[1:] + offsets[-1][-1])
@@ -230,14 +280,28 @@ class Deck:
230
280
  cells.append(id_map[section_cells])
231
281
  part_ids.append(section.pid)
232
282
 
233
- offsets_arr = np.hstack(offsets, dtype=ID_TYPE)
234
- cells_arr = np.hstack(cells, dtype=ID_TYPE)
283
+ cells_arr = np.hstack(cells, dtype=index_dtype)
284
+
285
+ # Offsets index the connectivity rather than the points, so they get
286
+ # their own check. VTK only drops to 32-bit storage when both arrays
287
+ # are int32, and a mismatch is promoted back to ID_TYPE.
288
+ offset_dtype = index_dtype if cells_arr.size <= _INT32_MAX else ID_TYPE
289
+ offsets_arr = np.hstack(offsets, dtype=offset_dtype)
235
290
  celltypes_arr = np.hstack(celltypes, dtype=np.uint8)
236
291
 
237
292
  grid = UnstructuredGrid()
238
293
  grid.points = pv.pyvista_ndarray(node_section.coordinates)
239
294
 
240
- vtk_cells = CellArray.from_arrays(offsets_arr, cells_arr, deep=False)
295
+ # VTK 9.6.2 can store one cell width in place of an offset per cell,
296
+ # which is an array shorter by n_cells + 1 to build and to hold. Decks
297
+ # of one cell type qualify; ones mixing widths keep the offsets.
298
+ width = _uniform_cell_width(offsets_arr)
299
+ if width is None:
300
+ vtk_cells = CellArray.from_arrays(offsets_arr, cells_arr, deep=False)
301
+ else:
302
+ vtk_cells = vtkCellArray()
303
+ vtk_cells.SetData(width, numpy_to_vtk(cells_arr, deep=False))
304
+
241
305
  vtk_cell_type = numpy_to_vtk(celltypes_arr, deep=False)
242
306
  grid.SetCells(vtk_cell_type, vtk_cells)
243
307
 
@@ -0,0 +1,8 @@
1
+ """Create a requirements_testing.txt file directly from a pyproject.toml."""
2
+
3
+ import tomli
4
+
5
+ data = tomli.load(open("pyproject.toml", "rb"))
6
+ deps = data["project"]["optional-dependencies"]["tests"]
7
+ with open("requirements-tests.txt", "w") as f:
8
+ f.write("\n".join(deps))