How to use the pyansys._reader function in pyansys

To help you get started, we’ve selected a few pyansys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akaszynski / pyansys / pyansys / rst.py View on Github external
# Read through components
        file_ptr = self._geometry_header['ptrCOMP']
        for _ in range(ncomp):
            table, sz = self.read_record(file_ptr, True)
            file_ptr += sz  # increment file_pointer

            name = table[1:9].tobytes().split(b'\x00')[0].decode('utf')
            name = name[:4][::-1] + name[4:8][::-1] + name[8:12][::-1] +\
                   name[12:16][::-1] + name[16:20][::-1] + name[20:24][::-1] +\
                   name[24:28][::-1] + name[28:32][::-1]
            name = name.strip()
            data = table[9:]
            if data.any():
                if table[0] == 1:  # node component
                    node_comp[name] = _reader.component_interperter(data)
                elif table[0] == 2:
                    elem_comp[name] = _reader.component_interperter(data)

        return node_comp, elem_comp
github akaszynski / pyansys / pyansys / rst.py View on Github external
file_ptr = self._geometry_header['ptrCOMP']
        for _ in range(ncomp):
            table, sz = self.read_record(file_ptr, True)
            file_ptr += sz  # increment file_pointer

            name = table[1:9].tobytes().split(b'\x00')[0].decode('utf')
            name = name[:4][::-1] + name[4:8][::-1] + name[8:12][::-1] +\
                   name[12:16][::-1] + name[16:20][::-1] + name[20:24][::-1] +\
                   name[24:28][::-1] + name[28:32][::-1]
            name = name.strip()
            data = table[9:]
            if data.any():
                if table[0] == 1:  # node component
                    node_comp[name] = _reader.component_interperter(data)
                elif table[0] == 2:
                    elem_comp[name] = _reader.component_interperter(data)

        return node_comp, elem_comp
github akaszynski / pyansys / pyansys / geometry.py View on Github external
etype_map[allowable_types] = ETYPE_MAP[allowable_types]

        # ANSYS element type to VTK map
        type_ref = np.empty(2 << 15, np.int32)  # 65536
        type_ref[self._ekey[:, 0]] = etype_map[self._ekey[:, 1]]

        # special treatment for MESH200
        if allowable_types is None or 200 in allowable_types:
            for etype_ind, etype in self._ekey:
                if etype == 200 and etype_ind in self.key_option:
                    # keyoption 1 contains various cell types
                    # map them to the corresponding type (see elements.py)
                    mapped = MESH200_MAP[self.key_option[etype_ind][0][1]]
                    type_ref[etype_ind] = mapped

        offset, celltypes, cells = _reader.ans_vtk_convert(self._elem,
                                                           self._elem_off,
                                                           type_ref,
                                                           self.nnum,
                                                           not VTK9)
        nodes, angles, nnum = self.nodes, self.node_angles, self.nnum

        # fix missing midside
        if np.any(cells == -1):
            if fix_midside:
                nodes, angles, nnum = fix_missing_midside(cells, nodes, celltypes,
                                                          offset, angles, nnum)
            else:
                cells[cells == -1] = 0

        if VTK9:
            grid = pv.UnstructuredGrid(cells, celltypes, nodes, deep=False)
github akaszynski / pyansys / pyansys / mapdl.py View on Github external
name = name.upper()
        # disable logging for this function
        prior_log_level = self._log.level
        self._log.setLevel('CRITICAL')

        idim, jdim, kdim = arr.shape[0], 0, 0
        if arr.ndim >= 2:
            jdim = arr.shape[1]
        if arr.ndim == 3:
            kdim = arr.shape[2]

        # write array from numpy to disk:
        filename = os.path.join(self.path, '_tmp.dat')
        if arr.dtype != np.double:
            arr = arr.astype(np.double)
        pyansys._reader.write_array(filename.encode(), arr.ravel('F'))

        self.dim(name, imax=idim, jmax=jdim, kmax=kdim)
        with self.non_interactive:
            self.vread('%s(1, 1),%s,,,IJK, %d, %d, %d' % (name, filename,
                                                          idim, jdim, kdim))
            self.run('(1F20.12)')

        self._log.setLevel(prior_log_level)
github akaszynski / pyansys / pyansys / archive.py View on Github external
def __init__(self, filename, read_parameters=False,
                 parse_vtk=True, force_linear=False,
                 allowable_types=None, null_unallowed=False, verbose=False):
        """Initializes an instance of the archive class."""
        self._read_parameters = read_parameters
        self._filename = filename
        self._raw = _reader.read(filename, read_parameters=read_parameters,
                                 debug=verbose)
        super().__init__(self._raw['nnum'],
                         self._raw['nodes'],
                         self._raw['elem'],
                         self._raw['elem_off'],
                         self._raw['ekey'],
                         node_comps=self._raw['node_comps'],
                         elem_comps=self._raw['elem_comps'],
                         rdat=self._raw['rdat'],
                         rnum=self._raw['rnum'],
                         keyopt=self._raw['keyopt'])

        if parse_vtk:
            self._grid = self._parse_vtk(allowable_types, force_linear, null_unallowed)
github akaszynski / pyansys / pyansys / mapdl.py View on Github external
# # create a temporary ELEM component so elements can be unselected
            # cname = '__tmp_elem__'
            # self.cm(cname, 'ELEM')
            # self.esel('NONE')

            nblock_filename = os.path.join(self.path, 'tmp.nodes')
            self.nwrite(nblock_filename)
            # self.cdwrite('db', arch_filename)
            # self.cmsel('S', cname, 'ELEM')

            # resume log
            self._log.setLevel(prior_log_level)

            # read in tmp archive file
            nnum, nodes = _reader.read_from_nwrite(nblock_filename.encode(),
                                                   self.n_node)
            self._nblock_cache = pyansys.geometry.Geometry(nnum, nodes)

        return self._nblock_cache
github akaszynski / pyansys / pyansys / archive_reader.py View on Github external
def __init__(self, filename):
        """ Initializes a cdb object """
        self.raw = _reader.Read(filename)