Skip to content

Commit 288d835

Browse files
fix parse_coordinate_system (#340)
Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 28119a0 commit 288d835

File tree

3 files changed

+68
-15
lines changed

3 files changed

+68
-15
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ Please see the `PyMAPDL-Reader Documentation
6161
interface using the same software used within Ansys Mechanical, but
6262
via a Python client.
6363

64+
.. note::
65+
66+
Result file compatibility will be greatly improved by disabling result file
67+
compression by setting ``/FCOMP,RST,0``.
68+
69+
DPF does not have this restriction.
70+
6471

6572
Installation
6673
------------

ansys/mapdl/reader/rst.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,15 @@ def _read_result_header(self):
290290
return resultheader
291291

292292
def parse_coordinate_system(self):
293-
"""Reads in coordinate system information from a binary result
294-
file.
293+
"""Reads in coordinate system information from a binary result file.
295294
296295
Returns
297296
-------
298297
c_systems : dict
299-
Dictionary containing one entry for each defined
300-
coordinate system. If no non-standard coordinate systems
301-
have been defined, there will be only one None. First
302-
coordinate system is assumed to be global cartesian.
298+
Dictionary containing one entry for each defined coordinate system.
299+
If no non-standard coordinate systems have been defined, an empty
300+
dictionary will be returned. First coordinate system is assumed to
301+
be global cartesian.
303302
304303
Notes
305304
-----
@@ -325,8 +324,9 @@ def parse_coordinate_system(self):
325324
- 1: Cylindrical (circular or elliptical)
326325
- 2: Spherical (or spheroidal)
327326
- 3: Toroidal
327+
328328
"""
329-
c_systems = [None]
329+
c_systems = {}
330330

331331
# load coordinate system index table
332332
ptr_csy = self._geometry_header["ptrCSY"]
@@ -353,7 +353,7 @@ def parse_coordinate_system(self):
353353
# * Item 22 is the coordinate system reference number.
354354
for csys_record_pointer in csys_record_pointers:
355355
if not csys_record_pointer:
356-
c_system = None
356+
continue
357357
else:
358358
data = self.read_record(ptr_csy + csys_record_pointer)
359359
c_system = {
@@ -365,11 +365,9 @@ def parse_coordinate_system(self):
365365
"theta singularity": data[18],
366366
"phi singularity": data[19],
367367
"type": int(data[20]),
368-
"reference num": int(
369-
data[21],
370-
),
368+
"reference num": int(data[21]),
371369
}
372-
c_systems.append(c_system)
370+
c_systems[c_system["reference num"]] = c_system
373371

374372
return c_systems
375373

@@ -2882,8 +2880,48 @@ def plot_principal_nodal_stress(
28822880
)
28832881

28842882
def cs_4x4(self, cs_cord, as_vtk_matrix=False):
2885-
"""return a 4x4 transformation array for a given coordinate system"""
2886-
# assemble 4 x 4 matrix
2883+
"""Return a 4x4 transformation matrix for a given coordinate system.
2884+
2885+
Parameters
2886+
----------
2887+
cs_cord : int
2888+
Coordinate system index.
2889+
2890+
as_vtk_matrix : bool, default: False
2891+
Return the transformation matrix as a ``vtkMatrix4x4``.
2892+
2893+
Returns
2894+
-------
2895+
np.ndarray | vtk.vtkMatrix4x4
2896+
Matrix or ``vtkMatrix4x4`` depending on the value of ``as_vtk_matrix``.
2897+
2898+
Notes
2899+
-----
2900+
Values 11 and greater correspond to local coordinate systems
2901+
2902+
Examples
2903+
--------
2904+
Return the transformation matrix for coordinate system 1.
2905+
2906+
>>> tmat = rst.cs_4x4(1)
2907+
>>> tmat
2908+
array([[1., 0., 0., 0.],
2909+
[0., 1., 0., 0.],
2910+
[0., 0., 1., 0.],
2911+
[0., 0., 0., 1.]])
2912+
2913+
Return the transformation matrix for coordinate system 5. This
2914+
corresponds to ``CSYS, 5``, the cylindrical with global Cartesian Y as
2915+
the axis of rotation.
2916+
2917+
>>> tmat = rst.cs_4x4(5)
2918+
>>> tmat
2919+
array([[ 1., 0., 0., 0.],
2920+
[ 0., 0., -1., 0.],
2921+
[ 0., 1., 0., 0.],
2922+
[ 0., 0., 0., 1.]])
2923+
2924+
"""
28872925
csys = self._c_systems[cs_cord]
28882926
trans = np.hstack(
28892927
(csys["transformation matrix"], csys["origin"].reshape(-1, 1))
@@ -2892,7 +2930,6 @@ def cs_4x4(self, cs_cord, as_vtk_matrix=False):
28922930

28932931
if as_vtk_matrix:
28942932
return matrix
2895-
28962933
return pv.array_from_vtkmatrix(matrix)
28972934

28982935
def _plot_point_scalars(

tests/test_cyclic.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
from pyvista.plotting import system_supports_plotting
88
from pyvista.plotting.renderer import CameraPosition
9+
from vtkmodules.vtkCommonMath import vtkMatrix4x4
910

1011
from ansys.mapdl import reader as pymapdl_reader
1112
from ansys.mapdl.reader import examples
@@ -492,3 +493,11 @@ def test_nodal_thermal_strain_cyclic(result_x):
492493
@skip_plotting
493494
def test_plot_nodal_thermal_strain(result_x):
494495
result_x.plot_nodal_thermal_strain(0, "X")
496+
497+
498+
def test_cs_4x4(result_x):
499+
assert isinstance(result_x._c_systems, dict)
500+
501+
# expect first CSYS to be cartesian
502+
assert np.allclose(result_x.cs_4x4(1), np.eye(4))
503+
assert isinstance(result_x.cs_4x4(1, as_vtk_matrix=True), vtkMatrix4x4)

0 commit comments

Comments
 (0)