Skip to content

Commit 68459ca

Browse files
committed
added option to remove null elements
1 parent 46fd7b2 commit 68459ca

File tree

8 files changed

+174
-81
lines changed

8 files changed

+174
-81
lines changed

doc/ansys_examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ This ANSYS APDL script builds a bar and applies torque to it using SURF154 eleme
9898
SAVE
9999
100100
Read and plot the results within python using:
101+
101102
.. code:: python
102103
103104
import pyansys

pyansys/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# major, minor, patch
2-
version_info = 0, 24, 0
2+
version_info = 0, 24, 1
33

44
# Nice string for the version
55
__version__ = '.'.join(map(str, version_info))

pyansys/archive_reader.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from pyansys import _reader
2323
from pyansys import _relaxmidside
2424
from pyansys import _parser
25+
from pyansys.elements import valid_types
2526

2627
# Attempt to load VTK dependent modules
2728
try:
@@ -48,7 +49,8 @@ def __init__(self, filename):
4849
""" Initializes a cdb object """
4950
self.raw = _reader.Read(filename)
5051

51-
def ParseVTK(self, force_linear=False, allowable_types=None):
52+
def ParseVTK(self, force_linear=False, allowable_types=None,
53+
null_unallowed=False):
5254
"""
5355
Parses raw data from cdb file to VTK format.
5456
@@ -62,8 +64,12 @@ def ParseVTK(self, force_linear=False, allowable_types=None):
6264
Allowable element types. Defaults to:
6365
['45', '95', '185', '186', '92', '187']
6466
65-
Can include:
66-
['45', '95', '185', '186', '92', '187', '154']
67+
See help(pyansys.elements) for available element types.
68+
69+
null_unallowed : bool, optional
70+
Elements types not matching element types will be stored as empty
71+
(null) elements. Useful for debug or tracking element numbers.
72+
Default False.
6773
6874
Returns
6975
-------
@@ -86,8 +92,13 @@ def ParseVTK(self, force_linear=False, allowable_types=None):
8692
else:
8793
assert isinstance(allowable_types, list), \
8894
'allowable_types must be a list'
95+
for eletype in allowable_types:
96+
if eletype not in valid_types:
97+
raise Exception('Element type "%s" ' % eletype +
98+
'cannot be parsed in pyansys')
8999

90-
result = _parser.Parse(self.raw, force_linear, allowable_types)
100+
result = _parser.Parse(self.raw, force_linear, allowable_types,
101+
null_unallowed)
91102
cells, offset, cell_type, numref, enum, etype, rcon = result
92103

93104
# catch bug

pyansys/binary_reader.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pyansys import _parsefull
1414
from pyansys import _rstHelper
1515
from pyansys import _parser
16+
from pyansys.elements import valid_types
1617

1718
try:
1819
import vtk
@@ -848,8 +849,8 @@ def StoreGeometry(self):
848849
'e_rcon': np.ones_like(enum)}
849850

850851
# store the reference array
851-
valid_types = ['45', '95', '185', '186', '92', '187', '154', '181']
852-
result = _parser.Parse(self.geometry, False, valid_types)
852+
# Allow quadradic and null unallowed
853+
result = _parser.Parse(self.geometry, False, valid_types, True)
853854
cells, offset, cell_type, self.numref, _, _, _ = result
854855

855856
# catch -1
@@ -860,11 +861,8 @@ def StoreGeometry(self):
860861

861862
element_type = np.zeros_like(etype)
862863
for key, typekey in ekey:
863-
# if str(typekey) in valid_types:
864864
element_type[etype == key] = typekey
865865

866-
# validmask = element_type != 0
867-
# element_type = element_type[validmask]
868866
nodes = nloc[:, :3]
869867
self.quadgrid = vtkInterface.UnstructuredGrid(offset, cells,
870868
cell_type, nodes)
@@ -920,9 +918,8 @@ def ElementSolutionHeader(self, rnum):
920918
# = 2 - extrapolate always
921919
# print(rxtrap)
922920
if rxtrap == 0:
923-
warnings.warn('Strains and stresses are moved and not ' +
924-
'extrapolated nodal stress calculations will ' +
925-
'be incorrect')
921+
warnings.warn('Strains and stresses are being evaluated at ' +
922+
'gauss points and not extrapolated')
926923

927924
# item 122 64-bit pointer to element solution
928925
f.seek((rpointers[rnum] + 120) * 4)

pyansys/cellquality.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@ def CellQuality(grid):
2020
Elements may be linear or quadradic
2121
2222
"""
23-
# Get cells and points from grid
24-
cells = grid.GetNumpyCells(ctypes.c_long)
23+
cells = grid.GetNumpyCells(ctypes.c_int64)
24+
25+
offset = grid.offset
26+
if offset.dtype != ctypes.c_int64:
27+
offset = offset.astype(ctypes.c_int64)
28+
29+
celltypes = grid.celltypes
30+
2531
points = grid.points
2632
if not points.flags.c_contiguous:
2733
points = np.ascontiguousarray(points)
2834

2935
if points.dtype == ctypes.c_float:
30-
return _cellqualfloat.CompScJac_quad(cells, points)
36+
return _cellqualfloat.CompScJac_quad(cells, points) # TODO: update
3137
elif points.dtype == ctypes.c_double:
32-
return _cellqual.CompScJac_quad(cells, points)
38+
return _cellqual.ComputeQuality(cells, offset, celltypes, points)
3339
else:
3440
raise Exception('Invalid point precision %s. ' % points.dtype +
3541
'Must be either float or double')

0 commit comments

Comments
 (0)