1818"""
1919import warnings
2020import numpy as np
21+ import logging
2122
2223# Attempt to load VTK dependent modules
2324try :
4344
4445
4546class ReadArchive (object ):
46- """ FEM object """
47+ """
48+ Initialize cdb object by reading raw cdb from file
4749
48- def __init__ (self , filename = '' , use_cython = True , raw = None ):
49- """
50- Initialize cdb object by reading raw cdb from file
50+ Parameters
51+ ----------
52+ filename : string
53+ Filename of block formatted cdb file
5154
52- INPUTS:
53- filename (string):
54- filename of block formatted cdb file
55-
56- use_cython (bool optional):
57- boolean flag to use cython reader defaults to True
55+ use_cython : bool, optional:
56+ Boolean flag to use cython reader defaults to True
5857
59- raw (dictonary optional):
60- dictionary of raw data
61-
62- """
58+ raw : dictonary, optional
59+ Dictionary of raw data. Used to initialize the cdb object without a
60+ file.
61+
62+ """
63+
64+ def __init__ (self , filename = '' , use_cython = True , raw = None ):
65+ """ Initializes a cdb object """
6366
6467 if raw and not filename :
6568 # Load raw data exterinally
@@ -80,16 +83,15 @@ def ParseVTK(self, use_cython=True, force_linear=False):
8083 Parses raw data from cdb file to VTK format. Creates unstructured grid
8184 as self.uGrid
8285
83- Paramters
84- ---------
86+ Parameters
87+ ----------
8588 use_cython : bool, optional
8689 Select between cython parser vs. python. Default True.
8790
8891 force_linear : bool, optional
8992 This parser creates quadradic elements if available. Set this to
9093 True to always create linear elements. Defaults to False.
9194
92-
9395 Returns
9496 -------
9597 uGrid : vtk.vtkUnstructuredGrid
@@ -183,8 +185,39 @@ def ParseVTK(self, use_cython=True, force_linear=False):
183185 return uGrid
184186
185187
186- def ParseFEM (self , use_cython = True , raw = None ):
187- """ Parses raw data from cdb file to VTK format """
188+ def ParseFEM (self , use_cython = True ):
189+ """
190+ Parses raw data from cdb file to VTK format. Creates unstructured grid
191+ as self.uGrid. Returns additional arrays to be used in downstream FEM
192+ analysis.
193+
194+
195+ Parameters
196+ ----------
197+ use_cython : bool, optional
198+ Select between cython parser and slower python parser.
199+ Default True. Enable for debugging purposes.
200+
201+
202+ Returns
203+ -------
204+ data : dictionary
205+ Dictionary containing arrays useful for interacting with the FEM
206+ without the use of the unstructured grid.
207+
208+ uGrid : vtk.vtkUnstructuredGrid
209+ VTK unstructured grid from archive file.
210+
211+ cellarr : np.int32 numpy.ndarray
212+ Each row of this array contains the points used to construct a
213+ cell. -1 indicates that it is an unused point.
214+
215+ ncellpts : np.int32 numpy.ndarray
216+ Number of points per cell. Indexing corresponds to row numbers in
217+ cellarr.
218+
219+ """
220+
188221 if not vtk_loaded :
189222 raise Exception ('Unable to load VTK module. Cannot parse raw cdb data' )
190223 return
@@ -228,7 +261,17 @@ def AddThickness(self):
228261 """
229262 Adds 'thickness' point scalars to uGrid
230263
231- Assumes that thickness is stored as SURF154 elements
264+ Assumes that thickness is stored as SURF154 elements in the 7th entry
265+ of the RLBLOCK for each item.
266+
267+ Parameters
268+ ----------
269+ None
270+
271+
272+ Returns
273+ -------
274+ None
232275
233276 """
234277 nnum = self .uGrid .GetPointScalars ('ANSYSnodenum' )
@@ -277,6 +320,7 @@ def SaveAsVTK(self, filename, binary=True):
277320
278321 Run ParseFEM before running this to generate the vtk object
279322
323+
280324 Parameters
281325 ----------
282326 filename : str
@@ -285,7 +329,8 @@ def SaveAsVTK(self, filename, binary=True):
285329 while *.vtu will select the PVTK XML writer
286330 binary : bool, optional
287331 Writes as a binary file by default. Set to False to write ASCII
288-
332+
333+
289334 Returns
290335 -------
291336 None
@@ -346,10 +391,15 @@ def ExtractThickness(raw):
346391
347392 idx = idx [idx != - 1 ]
348393
349- # Add thickness
350- t [idx ] += rdat [i ][6 ]
351- a [idx ] += 1
352-
394+ # Attempt to add thickness
395+ try :
396+ t [idx ] += rdat [i ][6 ]
397+ a [idx ] += 1
398+
399+ except :
400+ logging .warning ('Unable to load thickness from RLBLOCK '
401+ 'constant %d. Likely an empty item.' % rnum [i ])
402+
353403 # normalize thickness by number of entires
354404 a [a == 0 ] = 1 # avoid divide by zero
355405 t /= a
0 commit comments