示例#1
0
def test_element_stress_v182_non_cyclic():
    """
    Generated ansys results with:
    ansys.Post1()
    ansys.Set(1, 1)
    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.open_result(ansys_result_file)

    element_stress, elemnum, enode = result.element_stress(0)
    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['element_stress'], element_stress)
    assert np.allclose(from_ansys['enode'], enode)
示例#2
0
class TestLoad181():
    filename = os.path.join(testfiles_path, 'shell181.rst')
    result = pyansys.open_result(filename)

    def test_load(self):
        assert np.any(self.result.grid.cells)
        assert np.any(self.result.grid.points)

    def test_element_stress(self):
        element_stress, elemnum, enode = self.result.element_stress(0)
        element0 = element_stress[0]

        # ansys prints both postiive and negative component values
        if np.sign(element0[0][0]) != np.sign(ANSYS_ELEM[0][0]):
            element0 *= -1

        # wide atol limits considering the 5 sigfig from ASCII tables
        assert np.allclose(element0, np.array(ANSYS_ELEM), atol=1E-6)

    def test_nodal_stress(self):
        nnum, stress = self.result.nodal_stress(0)
        # element0 = element_stress[0]
        if np.sign(stress[0][0]) != np.sign(ANSYS_NODE[0][0]):
            stress *= -1

        # wide atol limits considering the 5 sigfig from ASCII tables
        assert np.allclose(stress, np.array(ANSYS_NODE), atol=1E-6)
示例#3
0
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.open_result(rstfile)
    assert result.nsets == 6
    assert len(result.nnum) == 321
    print('Loaded result file with {:d} result sets'.format(result.nsets))
    print('Contains {:d} nodes'.format(len(result.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.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))
示例#4
0
def show_stress(interactive=True):
    """ Load and plot 1st bend of a hexahedral beam """

    # get location of this file
    result = pyansys.open_result(rstfile)

    print('Displaying node averaged stress in x direction for Mode 6')
    result.plot_nodal_stress(5, 'Sx', interactive=interactive)
示例#5
0
def show_displacement(interactive=True):
    """ Load and plot 1st bend of a hexahedral beam """

    # get location of this file
    fobj = pyansys.open_result(rstfile)

    print('Displaying ANSYS Mode 1')
    fobj.plot_nodal_solution(0, label='Displacement', interactive=interactive)
示例#6
0
def test_animate_nodal_solution(tmpdir):
    result = pyansys.open_result(rstfile)
    temp_movie = str(tmpdir.mkdir("tmpdir").join('tmp.mp4'))
    result.animate_nodal_solution(0,
                                  nangles=20,
                                  movie_filename=temp_movie,
                                  interactive=False)
    assert np.any(result.grid.points)
    assert os.path.isfile(temp_movie)
示例#7
0
def test_plot_component():
    """
    # create example file for component plotting
    ansys = pyansys.ANSYS('/usr/ansys_inc/v182/ansys/bin/ansys182')
    ansys.Cdread('db', examples.hexarchivefile)
    # ansys.open_gui()
    ansys.Esel('S', 'ELEM', vmin=1, vmax=20)
    ansys.Nsle('S', 1)
    ansys.Cm('MY_COMPONENT', 'NODE')

    ansys.Nsel('S', 'NODE', '', 1, 40)
    ansys.Cm('MY_OTHER_COMPONENT', 'NODE')
    
    ansys.Allsel()

    # Aluminum properties (or something)
    ansys.Prep7()
    ansys.Mp('ex', 1, 10e6)
    ansys.Mp('nuxy', 1, 0.3)
    ansys.Mp('dens', 1, 0.1/386.1)
    ansys.Mp('dens', 2, 0)

    ansys.Run("/SOLU")
    ansys.Antype(2, "NEW")
    ansys.Run("BCSOPT,,INCORE")
    ansys.Modopt("LANB", 1)
    ansys.Mxpand(elcalc='YES')
    ansys.Run("/GOPR")
    ansys.Solve()
    ansys.Finish()
    ansys.Exit()
    """

    filename = os.path.join(testfiles_path, 'comp_hex_beam.rst')
    result = pyansys.open_result(filename)

    components = ['MY_COMPONENT', 'MY_OTHER_COMPONENT']
    result.plot_nodal_solution(0,
                               node_components=components,
                               interactive=False,
                               sel_type_all=False)
    result.plot_nodal_stress(0,
                             'Sx',
                             node_components=components,
                             interactive=False)
    result.plot_principal_nodal_stress(0,
                                       'SEQV',
                                       node_components=components,
                                       interactive=False)
示例#8
0
def test_save_as_vtk(tmpdir):
    filename = str(tmpdir.mkdir("tmpdir").join('tmp.vtk'))
    result = pyansys.open_result(examples.rstfile)
    result.save_as_vtk(filename)

    grid = vtki.UnstructuredGrid(filename)
    for i in range(result.nsets):
        assert 'nodal_solution%03d' % i in grid.point_arrays
        arr = grid.point_arrays['nodal_solution%03d' % i]
        assert np.allclose(arr, result.nodal_solution(i)[1], atol=1E-5)

        assert 'nodal_stress%03d' % i in grid.point_arrays
        arr = grid.point_arrays['nodal_stress%03d' % i]
        assert np.allclose(arr,
                           result.nodal_stress(i)[1],
                           atol=1E-5,
                           equal_nan=True)
示例#9
0
class TestResultReader(object):
    result = pyansys.open_result(examples.rstfile)
    archive = pyansys.Archive(examples.hexarchivefile)

    def test_geometry_elements(self):
        r_elem = self.result.geometry['elem'][self.result.sidx_elem]
        a_elem = self.archive.raw['elem']
        assert np.allclose(r_elem, a_elem)

    def test_geometry_nodes(self):
        r_node = self.result.geometry['nodes']
        a_node = self.archive.raw['nodes']
        assert np.allclose(r_node, a_node)

    def test_geometry_nodenum(self):
        r_values = self.result.geometry['nnum']
        a_values = self.archive.raw['nnum']
        assert np.allclose(r_values, a_values)

    def test_results_displacement(self):
        textfile = os.path.join(testfiles_path, 'prnsol_u.txt')
        nnum, r_values = self.result.nodal_solution(0)
        a_values = np.loadtxt(textfile, skiprows=2)[:, 1:4]
        assert np.allclose(r_values, a_values)

    def test_results_stress(self):
        r_nnum, r_values = self.result.nodal_stress(0)
        textfile = os.path.join(testfiles_path, 'prnsol_s.txt')
        a_values = np.loadtxt(textfile, skiprows=2)[:, 1:]

        # ignore nan
        nanmask = ~np.isnan(r_values).any(1)
        assert np.allclose(r_values[nanmask], a_values, atol=1E-1)

    def test_results_pstress(self):
        r_nnum, r_values = self.result.principal_nodal_stress(0)
        textfile = os.path.join(testfiles_path, 'prnsol_s_prin.txt')
        a_values = np.loadtxt(textfile, skiprows=2)[:, 1:]

        # ignore nan
        nanmask = ~np.isnan(r_values).any(1)
        assert np.allclose(r_values[nanmask], a_values, atol=100)
示例#10
0
def test_loadresult():
    result = pyansys.open_result(rstfile)

    # check result is loaded
    assert result.nsets
    assert result.nnum.size

    # check geometry is genreated
    grid = result.grid
    assert grid.points.size
    assert grid.cells.size
    assert 'ansys_node_num' in grid.point_arrays

    # check results can be loaded
    nnum, disp = result.nodal_solution(0)
    assert nnum.size
    assert disp.size

    nnum, disp = result.nodal_solution(0)
    assert nnum.size
    assert disp.size

    nnum, disp = result.principal_nodal_stress(0)
    assert nnum.size
    assert disp.size

    nnum, disp = result.nodal_stress(0)
    assert nnum.size
    assert disp.size

    element_stress, enum, enode = result.element_stress(0)
    assert element_stress[0].size
    assert enum.size
    assert enode[0].size

    element_stress, enum, enode = result.element_stress(0, principal=True)
    assert element_stress[0].size
    assert enum.size
    assert enode[0].size
示例#11
0
from pyansys.examples import sector_result_file, rstfile

try:
    __file__
except:
    __file__ = '/home/alex/afrl/python/source/pyansys/tests/test_cyclic.py'


is_python2 = sys.version_info.major == 2

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

# modal result z axis
result_z = pyansys.open_result(sector_result_file)

# static result x axis
cyclic_x_filename = os.path.join(testfiles_path, 'cyc12.rst')
result_x = pyansys.open_result(cyclic_x_filename)

# static result z axis
cyclic_v182_file = os.path.join(cyclic_testfiles_path, 'cyclic_v182.rst')
cyclic_v182_z = pyansys.open_result(cyclic_v182_file)

# cyclic modal with component
filename = os.path.join(cyclic_testfiles_path, 'cyclic_v182_w_comp.rst')
cyclic_v182_z_with_comp = pyansys.open_result(filename)


def test_non_cyclic():
ANSYS_ELEM = [
    [0.17662E-07, 79.410, -11.979, -0.11843E-02, 4.8423, -0.72216E-04],
    [0.20287E-07, 91.212, 27.364, -0.13603E-02, 4.8423, -0.72216E-04],
    [0.20287E-07, 91.212, 27.364, -0.13603E-02, -4.8423, 0.72216E-04],
    [0.17662E-07, 79.410, -11.979, -0.11843E-02, -4.8423, 0.72216E-04]
]

ANSYS_NODE = [
    [0.20287E-07, 91.212, 27.364, -0.13603E-02, 4.8423, -0.72216E-04],
    [0.17662E-07, 79.410, -11.979, -0.11843E-02, 4.8423, -0.72216E-04],
    [0.17662E-07, 79.410, -11.979, -0.11843E-02, -4.8423, 0.72216E-04],
    [0.20287E-07, 91.212, 27.364, -0.13603E-02, -4.8423, 0.72216E-04]
]

result_file = os.path.join(testfiles_path, 'shell281.rst')
test_result = pyansys.open_result(result_file, valid_element_types=['281'])

# estress, elem, enode = test_result.element_stress(0, in_element_coord_sys=False)
estress, elem, enode = test_result.element_stress(0, in_element_coord_sys=True)
print(estress[23][:4])

# debug
np.any(np.isclose(-50.863, estress[23]))
np.isclose(-50.863, estress[23]).any(1).nonzero()
# np.isclose(-50.863, table).any(1).nonzero()

f.seek(400284 - 8)
table = read_table(f, 'f')
# f.seek(400284)
ncomp = 6
nodstr = 4
示例#13
0
def test_loadbeam():
    linkresult = os.path.join(testfiles_path, 'link1.rst')
    result = pyansys.open_result(linkresult)
    assert np.any(result.grid.cells)
示例#14
0
Test loading results from plane183

Need to add ansys results for verification...

"""
import os
import numpy as np
import pyansys

try:
    testfiles_path = os.path.dirname(os.path.abspath(__file__))
except:
    testfiles_path = '/home/alex/afrl/python/source/pyansys/tests/plane_182_183'

filename = os.path.join(testfiles_path, 'pyansys_182_183_42_82.rst')
result = pyansys.open_result(filename)


def test_load():
    assert np.any(result.grid.cells)
    assert np.any(result.grid.points)


def test_displacement():
    nnum, disp = result.nodal_solution(0)
    ansys_nnum = np.load(os.path.join(testfiles_path, 'prnsol_u_nnum.npy'))
    ansys_disp = np.load(os.path.join(testfiles_path, 'prnsol_u.npy'))
    assert np.allclose(nnum, ansys_nnum)
    assert np.allclose(disp, ansys_disp, rtol=1E-4)  # rounding in text file