Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_header(self):
"""Read standard emat file header"""
with open(self.filename, 'rb') as f:
f.seek(103*4)
self.header = parse_header(read_table(f), EMAT_HEADER_KEYS)
>>> import pyansys
>>> rst = pyansys.read_binary('file.rst')
>>> nnum, data = rst.nodal_solution(0)
Notes
-----
Some solution results may not include all node numbers. This
is reflected in the ``result`` and ``nnum`` arrays.
"""
# convert to cumulative index
rnum = self.parse_step_substep(rnum)
# result pointer
ptr_rst = self._resultheader['rpointers'][rnum]
result_solution_header = parse_header(self.read_record(ptr_rst),
solution_data_header_keys)
nnod = result_solution_header['nnod']
numdof = result_solution_header['numdof']
nfldof = result_solution_header['nfldof']
sumdof = numdof + nfldof
ptr_nsl = result_solution_header['ptrNSL']
# Read the nodal solution
result, bufsz = self.read_record(ptr_nsl + ptr_rst, True)
result = result.reshape(-1, sumdof)
# additional entries are sometimes written for no discernible
# reason
if result.shape[0] > nnod:
def _store_geometry(self):
"""Store the geometry from the result file"""
# read geometry header
table = self.read_record(self._resultheader['ptrGEO'])
geometry_header = parse_header(table, geometry_header_keys)
self._geometry_header = geometry_header
# Node information
nnod = geometry_header['nnod']
nnum = np.empty(nnod, np.int32)
nodes = np.empty((nnod, 6), np.float)
_binary_reader.load_nodes(self.filename, geometry_header['ptrLOC'],
nnod, nodes, nnum)
# Element information
nelm = geometry_header['nelm']
maxety = geometry_header['maxety']
# pointer to the element type index table
e_type_table = self.read_record(geometry_header['ptrETY'])
LOG.debug('There are %d result(s) in this file', self.nsets)
# Get indices to resort nodal and element results
self._sidx = np.argsort(self._resultheader['neqv'])
self._sidx_elem = np.argsort(self._resultheader['eeqv'])
# Store node numbering in ANSYS
self._neqv = self._resultheader['neqv']
self._eeqv = self._resultheader['eeqv'] # unsorted
# store geometry for later retrival
self.geometry = None
if read_geometry:
self._store_geometry()
self.header = parse_header(self.read_record(103), result_header_keys)
self._geometry_header = {}
self._materials = None
self._section_data = None
Array containing the number of nodes with values for each element.
etype : np.ndarray
Element type array
element_rst_ptr : int
Offset to the start of the element result table.
"""
# Get the header information from the header dictionary
rpointers = self._resultheader['rpointers']
nodstr = self.element_table['nodstr']
# read result solution header
record = self.read_record(rpointers[rnum])
solution_header = parse_header(record, solution_data_header_keys)
# key to extrapolate integration
# = 0 - move
# = 1 - extrapolate unless active
# non-linear
# = 2 - extrapolate always
if solution_header['rxtrap'] == 0:
warnings.warn('Strains and stresses are being evaluated at ' +
'gauss points and not extrapolated')
# 64-bit pointer to element solution
if not solution_header['ptrESL']:
raise ValueError('No element solution in result set %d\n'
% (rnum + 1) + 'Try running with "MXPAND,,,,YES"')
# Seek to element result header
records will be nmrow*nmrow. If the matrix is symmetric, only
the lower triangular terms are written and the length of the
records will be ``(nmrow)*(nmrow+1)/2``
Records are written relative to the dof_idx. The index is
calculated as (N-1)*NUMDOF+DOF, where N is the position number
of the node in the nodal equivalence table and DOF is the DOF
reference number given by ``dof_idx``.
"""
element_data = {}
with open(self.filename, 'rb') as fobj:
# seek to the position of the element table in the file
fobj.seek(self.element_matrices_index_table[index]*4)
# matrix header
element_header = parse_header(read_table(fobj), ELEMENT_HEADER_KEYS)
nmrow = abs(element_header['nmrow'])
lower_tri = element_header['nmrow'] < 0
if lower_tri:
nread = nmrow*(nmrow + 1)//2
else:
nread = nmrow*nmrow
# Read DOF index table. This record specifies the DOF locations
# of this element matrix in relation to the global
# matrix. The index is calculated as (N-1)*NUMDOF+DOF,
# where N is the position number of the node in the nodal
# equivalence table and DOF is the DOF reference number
# given above
dof_idx = read_table(fobj) - 1 # adj one based indexing
# read stress matrix
nnod = solution_header['nnod']
numdof = solution_header['numdof']
nfldof = solution_header['nfldof']
sumdof = numdof + nfldof
#numvdof = solution_header['numvdof'] # does not seem to be set in transient analysis
#if not numvdof: numvodf = sumdof
#numadof = solution_header['numadof'] # does not seem to be set in transient analysis
#if not numadof: numadof = sumdof
# iterate over all loadsteps
results = np.zeros((nsets, nnod, sumdof))
for rnum in range(self.nsets):
# Seek to result table and to get pointer to DOF
# results of result table
rsol_header = parse_header(self.read_record(rpointers[rnum]),
solution_data_header_keys)
if solution_type == 'NSL': # Nodal Displacements
ptr_sl = rsol_header['ptrNSL']
elif solution_type == 'VEL': # Nodal Velocities
ptr_sl = rsol_header['ptrVSL']
elif solution_type == 'ACC': # Nodal Accelerations
ptr_sl = rsol_header['ptrASL']
record, sz = self.read_record(rpointers[rnum] + ptr_sl,
return_bufsize=True)
# nitems = record.size
result = record.reshape((-1, sumdof))
# PDBN should be set if only a subset of nodes was output
# PDBN is set only when solution type: nodal solution/displacement
# PDBN is not set when solution type: acceleration, velocities