Skip to content

Commit

Permalink
fixed RLBLOCK bug
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Sep 11, 2017
1 parent deb8722 commit a3d61b0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 27 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ pyansys/Interface.py

# Testing
Testing/

2 changes: 1 addition & 1 deletion pyansys/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# major, minor, patch
version_info = 0, 18, 0
version_info = 0, 18, 1

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
100 changes: 75 additions & 25 deletions pyansys/archive_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""
import warnings
import numpy as np
import logging

# Attempt to load VTK dependent modules
try:
Expand All @@ -43,23 +44,25 @@


class ReadArchive(object):
""" FEM object """
"""
Initialize cdb object by reading raw cdb from file
def __init__(self, filename='', use_cython=True, raw=None):
"""
Initialize cdb object by reading raw cdb from file
Parameters
----------
filename : string
Filename of block formatted cdb file
INPUTS:
filename (string):
filename of block formatted cdb file
use_cython (bool optional):
boolean flag to use cython reader defaults to True
use_cython : bool, optional:
Boolean flag to use cython reader defaults to True
raw (dictonary optional):
dictionary of raw data
"""
raw : dictonary, optional
Dictionary of raw data. Used to initialize the cdb object without a
file.
"""

def __init__(self, filename='', use_cython=True, raw=None):
""" Initializes a cdb object """

if raw and not filename:
# Load raw data exterinally
Expand All @@ -80,16 +83,15 @@ def ParseVTK(self, use_cython=True, force_linear=False):
Parses raw data from cdb file to VTK format. Creates unstructured grid
as self.uGrid
Paramters
---------
Parameters
----------
use_cython : bool, optional
Select between cython parser vs. python. Default True.
force_linear : bool, optional
This parser creates quadradic elements if available. Set this to
True to always create linear elements. Defaults to False.
Returns
-------
uGrid : vtk.vtkUnstructuredGrid
Expand Down Expand Up @@ -183,8 +185,39 @@ def ParseVTK(self, use_cython=True, force_linear=False):
return uGrid


def ParseFEM(self, use_cython=True, raw=None):
""" Parses raw data from cdb file to VTK format """
def ParseFEM(self, use_cython=True):
"""
Parses raw data from cdb file to VTK format. Creates unstructured grid
as self.uGrid. Returns additional arrays to be used in downstream FEM
analysis.
Parameters
----------
use_cython : bool, optional
Select between cython parser and slower python parser.
Default True. Enable for debugging purposes.
Returns
-------
data : dictionary
Dictionary containing arrays useful for interacting with the FEM
without the use of the unstructured grid.
uGrid : vtk.vtkUnstructuredGrid
VTK unstructured grid from archive file.
cellarr : np.int32 numpy.ndarray
Each row of this array contains the points used to construct a
cell. -1 indicates that it is an unused point.
ncellpts : np.int32 numpy.ndarray
Number of points per cell. Indexing corresponds to row numbers in
cellarr.
"""

if not vtk_loaded:
raise Exception('Unable to load VTK module. Cannot parse raw cdb data')
return
Expand Down Expand Up @@ -228,7 +261,17 @@ def AddThickness(self):
"""
Adds 'thickness' point scalars to uGrid
Assumes that thickness is stored as SURF154 elements
Assumes that thickness is stored as SURF154 elements in the 7th entry
of the RLBLOCK for each item.
Parameters
----------
None
Returns
-------
None
"""
nnum = self.uGrid.GetPointScalars('ANSYSnodenum')
Expand Down Expand Up @@ -277,6 +320,7 @@ def SaveAsVTK(self, filename, binary=True):
Run ParseFEM before running this to generate the vtk object
Parameters
----------
filename : str
Expand All @@ -285,7 +329,8 @@ def SaveAsVTK(self, filename, binary=True):
while *.vtu will select the PVTK XML writer
binary : bool, optional
Writes as a binary file by default. Set to False to write ASCII
Returns
-------
None
Expand Down Expand Up @@ -346,10 +391,15 @@ def ExtractThickness(raw):

idx = idx[idx != -1]

# Add thickness
t[idx] += rdat[i][6]
a[idx] += 1

# Attempt to add thickness
try:
t[idx] += rdat[i][6]
a[idx] += 1

except:
logging.warning('Unable to load thickness from RLBLOCK '
'constant %d. Likely an empty item.'% rnum[i])

# normalize thickness by number of entires
a[a == 0] = 1 # avoid divide by zero
t /= a
Expand Down

0 comments on commit a3d61b0

Please sign in to comment.