How to use the pyansys.read_binary 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 / tests / elements / shell181 / test_shell181.py View on Github external
def result():
    test_path = os.path.dirname(os.path.abspath(__file__))
    return pyansys.read_binary(os.path.join(test_path, 'shell181.rst'))
github akaszynski / pyansys / tests / test_rst.py View on Github external
try:
    pontoon = pyansys.download_pontoon()
except:
    pontoon = None


test_path = os.path.dirname(os.path.abspath(__file__))
testfiles_path = os.path.join(test_path, 'testfiles')

is16_filename = os.path.join(testfiles_path, 'is16.rst')
is16_known_result = os.path.join(testfiles_path, 'is16.npz')
if os.path.isfile(is16_filename):

    is16 = pyansys.read_binary(is16_filename)
else:
    is16 = None

temperature_rst = os.path.join(testfiles_path, 'temp_v13.rst')
temperature_known_result = os.path.join(testfiles_path, 'temp_v13.npz')

@pytest.fixture(scope='module')
def hex_rst():
    filename = os.path.join(testfiles_path, 'hex_201.rst')
    return pyansys.read_binary(filename)


@pytest.mark.skipif(vm33 is None, reason="Requires example files")
def test_write_tables(tmpdir):
    filename = str(tmpdir.mkdir("tmpdir").join('vm33.txt'))
    vm33.write_tables(filename)
github akaszynski / pyansys / tests / test_pyansys.py View on Github external
def test_loadbeam():
    linkresult_path = os.path.join(testfiles_path, 'link1.rst')
    linkresult = pyansys.read_binary(linkresult_path)
    assert np.any(linkresult.grid.cells)
github akaszynski / pyansys / tests / test_pyansys.py View on Github external
def result():
    return pyansys.read_binary(rstfile)
github akaszynski / pyansys / tests / test_emat.py View on Github external
def emat():
    emat_bin = pyansys.read_binary(emat_filename)
    assert isinstance(emat_bin, EmatFile)
    return emat_bin
github akaszynski / pyansys / tests / elements / shell181 / test_shell181_element_coord.py View on Github external
def test_shell_stress_element_cs():
    result = pyansys.read_binary(result_file_name)
    stress, enum, enode = result.element_stress(0, in_element_coord_sys=True)

    idx = np.where(enum == 118223)[0][0]
    assert np.allclose(KNOWN_RESULT_ENODE, enode[idx][:4])
    assert np.allclose(KNOWN_RESULT_STRESS, stress[idx], rtol=1E-4)
github akaszynski / pyansys / tests / test_cyclic.py View on Github external
ansys.Header('OFF', 'OFF', 'OFF', 'OFF', 'OFF', 'OFF')
    ansys.Format('', 'E', 80, 20)
    ansys.Page(1E9, '', -1)

    msg = ansys.Presol('S').splitlines()
    ansys_element_stress = []
    for line in msg:
        if len(line) == 201:
            ansys_element_stress.append(line)
    ansys_element_stress = np.genfromtxt(ansys_element_stress)
    ansys_enode = ansys_element_stress[:, 0].astype(np.int)
    ansys_element_stress = ansys_element_stress[:, 1:]

    """
    ansys_result_file = os.path.join(cyclic_testfiles_path, 'cyclic_v182.rst')
    result = pyansys.read_binary(ansys_result_file)

    element_stress, elemnum, enode = result.element_stress(0, False, False)
    assert np.allclose(np.sort(elemnum), elemnum), 'elemnum must be sorted'

    element_stress = np.vstack(element_stress)
    enode = np.hstack(enode)

    # cyclic model will only output the master sector
    from_ansys = np.load(os.path.join(cyclic_testfiles_path, 'v182_presol.npz'))
    assert np.allclose(from_ansys['enode'], enode)
    assert np.allclose(from_ansys['element_stress'], element_stress)
github akaszynski / pyansys / pyansys / examples / examples.py View on Github external
def solve_km():
    """Load and solves a mass and stiffness matrix from an ansys full file"""
    try:
        from scipy.sparse import linalg
        from scipy import sparse
    except ImportError:
        print('scipy not installed, aborting')
        return

    # load the mass and stiffness matrices
    full = pyansys.read_binary(pyansys.examples.fullfile)
    dofref, k, m = full.load_km(sort=True)

    # make symmetric
    k += sparse.triu(k, 1).T
    m += sparse.triu(m, 1).T
    k += sparse.diags(np.random.random(k.shape[0])/1E20, shape=k.shape)

    # Solve
    w, v = linalg.eigsh(k, k=20, M=m, sigma=1000)

    # System natural frequencies
    f = (np.real(w))**0.5 / (2 * np.pi)

    # %% Plot result

    # Get the 4th mode shape
github akaszynski / pyansys / pyansys / mapdl.py View on Github external
result_path = self.inquire('RSTFILE')
        except RuntimeError:
            result_path = ''

        if not result_path:
            result_path = os.path.join(self.path, '%s.rst' % self._jobname)
        elif not os.path.dirname(result_path):
            result_path = os.path.join(self.path, '%s.rst' % result_path)

        # there may be multiple result files at this location (if not
        # combining results)
        

        if not os.path.isfile(result_path):
            raise FileNotFoundError('No results found at %s' % result_path)
        return pyansys.read_binary(result_path)
github akaszynski / pyansys / pyansys / examples / examples.py View on Github external
def load_result():
    """Loads a result file and prints out the displacement of all the nodes from
    a modal analysis.
    """

    # Load result file
    result = pyansys.read_binary(rstfile)
    assert result.nsets == 6
    assert len(result.geometry.nnum) == 321
    print('Loaded result file with {:d} result sets'.format(result.nsets))
    print('Contains {:d} nodes'.format(len(result.geometry.nnum)))

    # display result
    nnum, disp = result.nodal_solution(0)

    print('Nodal displacement for nodes 30 to 40 is:')

    for i in range(29, 40):
        node = result.geometry.nnum[i]
        x = disp[i, 0]
        y = disp[i, 1]
        z = disp[i, 2]
        print('{:2d}  {:10.6f}   {:10.6f}   {:10.6f}'.format(node, x, y, z))