Skip to content

Commit 27a697a

Browse files
committed
Merge branch 'main' into release/0.52
2 parents 0364e46 + 695c3a2 commit 27a697a

File tree

11 files changed

+140
-140
lines changed

11 files changed

+140
-140
lines changed

.github/workflows/testing-and-deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jobs:
154154
- uses: actions/checkout@v3
155155

156156
- name: Build wheels
157-
uses: pypa/[email protected].0
157+
uses: pypa/[email protected].1
158158
with:
159159
python-version: 3.8 - 3.11
160160

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
- id: flake8
2121

2222
- repo: https://github.com/codespell-project/codespell
23-
rev: v2.2.4
23+
rev: v2.2.5
2424
hooks:
2525
- id: codespell
2626

@@ -33,7 +33,7 @@ repos:
3333
# exclude: "tests/"
3434

3535
- repo: https://github.com/pre-commit/mirrors-clang-format
36-
rev: v14.0.6
36+
rev: v16.0.6
3737
hooks:
3838
- id: clang-format
3939
files: |
@@ -50,6 +50,6 @@ repos:
5050
exclude: '.*\.(cdb|rst|dat)$'
5151

5252
- repo: https://github.com/python-jsonschema/check-jsonschema
53-
rev: 0.23.1
53+
rev: 0.23.2
5454
hooks:
5555
- id: check-github-workflows

ansys/mapdl/reader/archive.py

Lines changed: 62 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@
77

88
import numpy as np
99
import pyvista as pv
10-
from pyvista import _vtk as vtk
11-
from pyvista._vtk import (
12-
VTK_HEXAHEDRON,
13-
VTK_PYRAMID,
14-
VTK_QUAD,
15-
VTK_QUADRATIC_HEXAHEDRON,
16-
VTK_QUADRATIC_PYRAMID,
17-
VTK_QUADRATIC_TETRA,
18-
VTK_QUADRATIC_WEDGE,
19-
VTK_TETRA,
20-
VTK_TRIANGLE,
21-
VTK_WEDGE,
22-
)
10+
from pyvista import CellType
2311

2412
VTK_VOXEL = 11
2513

@@ -217,7 +205,7 @@ def __repr__(self):
217205

218206
@property
219207
def grid(self):
220-
"""``vtk.UnstructuredGrid`` of the archive file.
208+
"""Return a ``pyvista.UnstructuredGrid`` of the archive file.
221209
222210
Examples
223211
--------
@@ -258,7 +246,7 @@ def quality(self):
258246
"""
259247
if self._grid is None: # pragma: no cover
260248
raise AttributeError(
261-
"Archive must be parsed as a vtk grid.\n" "Set `parse_vtk=True`"
249+
"Archive must be parsed as a vtk grid.\nSet `parse_vtk=True`"
262250
)
263251
return quality(self._grid)
264252

@@ -388,27 +376,29 @@ def save_as_archive(
388376
if hasattr(grid, "cast_to_unstructured_grid"):
389377
grid = grid.cast_to_unstructured_grid()
390378

391-
if not isinstance(grid, vtk.vtkUnstructuredGrid):
392-
raise TypeError("``grid`` argument must be an UnstructuredGrid")
379+
if not isinstance(grid, pv.UnstructuredGrid):
380+
raise TypeError(
381+
f"``grid`` argument must be an UnstructuredGrid, not {type(grid)}"
382+
)
393383

394384
allowable = []
395385
if include_solid_elements:
396386
allowable.extend(
397387
[
398-
VTK_VOXEL,
399-
VTK_TETRA,
400-
VTK_QUADRATIC_TETRA,
401-
VTK_PYRAMID,
402-
VTK_QUADRATIC_PYRAMID,
403-
VTK_WEDGE,
404-
VTK_QUADRATIC_WEDGE,
405-
VTK_HEXAHEDRON,
406-
VTK_QUADRATIC_HEXAHEDRON,
388+
CellType.VOXEL,
389+
CellType.TETRA,
390+
CellType.QUADRATIC_TETRA,
391+
CellType.PYRAMID,
392+
CellType.QUADRATIC_PYRAMID,
393+
CellType.WEDGE,
394+
CellType.QUADRATIC_WEDGE,
395+
CellType.HEXAHEDRON,
396+
CellType.QUADRATIC_HEXAHEDRON,
407397
]
408398
)
409399

410400
if include_surface_elements:
411-
allowable.extend([VTK_TRIANGLE, VTK_QUAD])
401+
allowable.extend([CellType.TRIANGLE, CellType.QUAD])
412402
# VTK_QUADRATIC_TRIANGLE,
413403
# VTK_QUADRATIC_QUAD
414404

@@ -432,7 +422,7 @@ def save_as_archive(
432422
nodenum = grid.point_data["ansys_node_num"]
433423
else:
434424
log.info("No ANSYS node numbers set in input. Adding default range")
435-
nodenum = np.arange(1, grid.number_of_points + 1, dtype=np.int32)
425+
nodenum = np.arange(1, grid.n_points + 1, dtype=np.int32)
436426

437427
missing_mask = nodenum == -1
438428
if np.any(missing_mask):
@@ -457,12 +447,12 @@ def save_as_archive(
457447
nodenum[missing_mask] = np.arange(start_num, end_num, dtype=np.int32)
458448

459449
# element block
460-
ncells = grid.number_of_cells
450+
ncells = grid.n_cells
461451
if "ansys_elem_num" in grid.cell_data:
462452
enum = grid.cell_data["ansys_elem_num"]
463453
else:
464454
if not allow_missing:
465-
raise Exception('Missing node numbers. Exiting due "allow_missing=False"')
455+
raise Exception('Missing node numbers. Exiting due "allow_missing=False"')
466456
log.info(
467457
"No ANSYS element numbers set in input. "
468458
"Adding default range starting from %d",
@@ -483,7 +473,7 @@ def save_as_archive(
483473
nadd = np.sum(enum == -1)
484474
end_num = start_num + nadd
485475
log.info(
486-
"FEM missing some cell numbers. Adding numbering " "from %d to %d",
476+
"FEM missing some cell numbers. Adding numbering from %d to %d",
487477
start_num,
488478
end_num,
489479
)
@@ -555,37 +545,50 @@ def save_as_archive(
555545
+ "Adding default range starting from %d" % etype_start
556546
)
557547

558-
etype = np.empty(grid.number_of_cells, np.int32)
559-
etype_185 = etype_start + 2
560-
etype[grid.celltypes == VTK_VOXEL] = etype_185
561-
etype[grid.celltypes == VTK_TETRA] = etype_185
562-
etype[grid.celltypes == VTK_HEXAHEDRON] = etype_185
563-
etype[grid.celltypes == VTK_WEDGE] = etype_185
564-
etype[grid.celltypes == VTK_PYRAMID] = etype_185
548+
etype = np.empty(grid.n_cells, np.int32)
565549

550+
# VTK to SOLID186 mapping
551+
# TETRA delegated to SOLID187
566552
etype_186 = etype_start
567-
etype[grid.celltypes == VTK_QUADRATIC_HEXAHEDRON] = etype_186
568-
etype[grid.celltypes == VTK_QUADRATIC_WEDGE] = etype_186
569-
etype[grid.celltypes == VTK_QUADRATIC_PYRAMID] = etype_186
553+
etype_186_types = [
554+
CellType.QUADRATIC_HEXAHEDRON,
555+
CellType.QUADRATIC_WEDGE,
556+
CellType.QUADRATIC_PYRAMID,
557+
]
558+
etype[np.isin(grid.celltypes, etype_186_types)] = etype_186
570559

571560
etype_187 = etype_start + 1
572-
etype[grid.celltypes == VTK_QUADRATIC_TETRA] = etype_187
561+
etype[grid.celltypes == CellType.QUADRATIC_TETRA] = etype_187
562+
563+
# VTK to SOLID185 mapping
564+
etype_185 = etype_start + 2
565+
etype_185_types = [
566+
CellType.VOXEL,
567+
CellType.TETRA,
568+
CellType.HEXAHEDRON,
569+
CellType.WEDGE,
570+
CellType.PYRAMID,
571+
]
572+
etype[np.isin(grid.celltypes, etype_185_types)] = etype_185
573573

574574
# Surface elements
575575
etype_181 = etype_start + 3
576-
etype[grid.celltypes == VTK_TRIANGLE] = etype_181
577-
etype[grid.celltypes == VTK_QUAD] = etype_181
576+
etype_181_types = [
577+
CellType.TRIANGLE,
578+
CellType.QUAD,
579+
]
580+
etype[np.isin(grid.celltypes, etype_181_types)] = etype_181
578581

579582
typenum = np.empty_like(etype)
580583
typenum[etype == etype_185] = 185
581584
typenum[etype == etype_186] = 186
582585
typenum[etype == etype_187] = 187
583586
typenum[etype == etype_181] = 181
584587

585-
header += "ET, %d, 185\n" % etype_185
586-
header += "ET, %d, 186\n" % etype_186
587-
header += "ET, %d, 187\n" % etype_187
588-
header += "ET, %d, 181\n" % etype_181
588+
header += f"ET,{etype_185},185\n"
589+
header += f"ET,{etype_186},186\n"
590+
header += f"ET,{etype_187},187\n"
591+
header += f"ET,{etype_181},181\n"
589592

590593
# number of nodes written per element
591594
elem_nnodes = np.empty(etype.size, np.int32)
@@ -623,7 +626,7 @@ def save_as_archive(
623626
write_nblock(filename, nodenum, grid.points, mode="a")
624627

625628
# write remainder of eblock
626-
cells, offset = vtk_cell_info(grid, shift_offset=False)
629+
cells, offset = vtk_cell_info(grid, force_int64=False, shift_offset=False)
627630
_write_eblock(
628631
filename,
629632
enum,
@@ -798,26 +801,16 @@ def _write_eblock(
798801
):
799802
"""Write EBLOCK to disk"""
800803
# perform type checking here
801-
if elem_id.dtype != np.int32:
802-
elem_id = elem_id.astype(np.int32)
803-
if etype.dtype != np.int32:
804-
etype = etype.astype(np.int32)
805-
if mtype.dtype != np.int32:
806-
mtype = mtype.astype(np.int32)
807-
if rcon.dtype != np.int32:
808-
rcon = rcon.astype(np.int32)
809-
if elem_nnodes.dtype != np.int32:
810-
elem_nnodes = elem_nnodes.astype(np.int32)
811-
if cells.dtype != np.int64:
812-
cells = cells.astype(np.int64)
813-
if offset.dtype != np.int64:
814-
offset = offset.astype(np.int64)
815-
if celltypes.dtype != np.uint8:
816-
celltypes = celltypes.astype(np.uint8)
817-
if typenum.dtype != np.int32:
818-
typenum = typenum.astype(np.int32)
819-
if nodenum.dtype != np.int32:
820-
nodenum = nodenum.astype(np.int32)
804+
elem_id = elem_id.astype(np.int32, copy=False)
805+
etype = etype.astype(np.int32, copy=False)
806+
mtype = mtype.astype(np.int32, copy=False)
807+
rcon = rcon.astype(np.int32, copy=False)
808+
elem_nnodes = elem_nnodes.astype(np.int32, copy=False)
809+
cells = cells.astype(np.int32, copy=False)
810+
offset = offset.astype(np.int32, copy=False)
811+
celltypes = celltypes.astype(np.uint8, copy=False)
812+
typenum = typenum.astype(np.int32, copy=False)
813+
nodenum = nodenum.astype(np.int32, copy=False)
821814

822815
_archive.py_write_eblock(
823816
filename,

ansys/mapdl/reader/cyclic_reader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import numpy as np
55
import pyvista as pv
6-
from pyvista._vtk import vtkAppendFilter, vtkMatrix4x4, vtkTransform
6+
from vtkmodules.vtkCommonMath import vtkMatrix4x4
7+
from vtkmodules.vtkCommonTransforms import vtkTransform
8+
from vtkmodules.vtkFiltersCore import vtkAppendFilter
79

810
from ansys.mapdl.reader import _binary_reader
911
from ansys.mapdl.reader.common import (

ansys/mapdl/reader/cython/_archive.pyx

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ import numpy as np
1414
cimport numpy as np
1515

1616
ctypedef unsigned char uint8_t
17-
from libc.stdint cimport int64_t
18-
1917

2018
cdef extern from 'archive.h' nogil:
2119
int write_nblock(FILE*, const int, const int, const int*, const double*,
2220
const double*, int)
2321
int write_nblock_float(FILE*, const int, const int, const int*, const float*,
2422
const float*, int)
2523
int write_eblock(FILE*, const int, const int*, const int*, const int*,
26-
const int*, const int*, const uint8_t*, const int64_t*,
27-
const int64_t*, const int*, const int*);
24+
const int*, const int*, const uint8_t*, const int*,
25+
const int*, const int*, const int*);
2826

2927

3028
cdef extern from "stdio.h":
@@ -100,31 +98,34 @@ def py_write_nblock_float(filename, const int [::1] node_id, int max_node_id,
10098
fclose(cfile)
10199

102100

103-
def py_write_eblock(filename,
104-
const int [::1] elem_id,
105-
const int [::1] etype,
106-
const int [::1] mtype,
107-
const int [::1] rcon,
108-
const int [::1] elem_nnodes,
109-
const int64_t [::1] cells,
110-
const int64_t [::1] offset,
111-
const uint8_t [::1] celltypes,
112-
const int [::1] typenum,
113-
const int [::1] nodenum,
114-
mode='w'):
101+
def py_write_eblock(
102+
filename,
103+
const int [::1] elem_id,
104+
const int [::1] etype,
105+
const int [::1] mtype,
106+
const int [::1] rcon,
107+
const int [::1] elem_nnodes,
108+
const int [::1] cells,
109+
const int [::1] offset,
110+
const uint8_t [::1] celltypes,
111+
const int [::1] typenum,
112+
const int [::1] nodenum,
113+
mode='w'):
115114
cdef FILE* cfile = fopen(filename.encode(), mode.encode())
116-
write_eblock(cfile,
117-
celltypes.size,
118-
&elem_id[0],
119-
&etype[0],
120-
&mtype[0],
121-
&rcon[0],
122-
&elem_nnodes[0],
123-
&celltypes[0],
124-
&offset[0],
125-
&cells[0],
126-
&typenum[0],
127-
&nodenum[0])
115+
write_eblock(
116+
cfile,
117+
celltypes.size,
118+
&elem_id[0],
119+
&etype[0],
120+
&mtype[0],
121+
&rcon[0],
122+
&elem_nnodes[0],
123+
&celltypes[0],
124+
&offset[0],
125+
&cells[0],
126+
&typenum[0],
127+
&nodenum[0]
128+
)
128129
fclose(cfile)
129130

130131

ansys/mapdl/reader/cython/archive.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ int write_eblock(
9191
const int *rcon, // real constant ID array
9292
const int *elem_nnodes, // number of nodes per element
9393
const uint8_t *celltypes, // VTK celltypes array
94-
const int64_t *offset, // VTK offset array
95-
const int64_t *cells, // VTK cells array
94+
const int *offset, // VTK offset array
95+
const int *cells, // VTK cell connectivity array
9696
const int *typenum, // ANSYS type number (e.g. 187 for SOLID187)
9797
const int *nodenum) { // ANSYS node numbering
9898

@@ -102,7 +102,6 @@ int write_eblock(
102102

103103
int c; // position within offset array
104104
for (int i = 0; i < n_elem; i++) {
105-
// Position within offset array
106105
c = offset[i];
107106

108107
// Write cell info
@@ -124,12 +123,18 @@ int write_eblock(
124123
case VTK_QUADRATIC_TETRA:
125124
if (typenum[i] == 187) {
126125
fprintf(file, "%8d%8d%8d%8d%8d%8d%8d%8d\n%8d%8d\n",
127-
nodenum[cells[c + 0]], nodenum[cells[c + 1]],
128-
nodenum[cells[c + 2]], nodenum[cells[c + 3]],
129-
nodenum[cells[c + 4]], nodenum[cells[c + 5]],
130-
nodenum[cells[c + 6]], nodenum[cells[c + 7]],
131-
nodenum[cells[c + 8]], nodenum[cells[c + 9]]);
126+
nodenum[cells[c + 0]], // 0, I
127+
nodenum[cells[c + 1]], // 1, J
128+
nodenum[cells[c + 2]], // 2, K
129+
nodenum[cells[c + 3]], // 3, L
130+
nodenum[cells[c + 4]], // 4, M
131+
nodenum[cells[c + 5]], // 5, N
132+
nodenum[cells[c + 6]], // 6, O
133+
nodenum[cells[c + 7]], // 7, P
134+
nodenum[cells[c + 8]], // 8, Q
135+
nodenum[cells[c + 9]]); // 9, R
132136
} else {
137+
// Using SOLID186-like format
133138
fprintf(
134139
file,
135140
"%8d%8d%8d%8d%8d%8d%8d%8d\n%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d\n",

0 commit comments

Comments
 (0)