예제 #1
0
    grid = pv.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)


@pytest.mark.skipif(not system_supports_plotting(),
                    reason="Requires active X Server")
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()
예제 #2
0
z = np.arange(-10, 10, 2)
x, y, z = np.meshgrid(x, y, z)
sgrid = pyvista.StructuredGrid(x, y, z)

try:
    test_path = os.path.dirname(os.path.abspath(__file__))
    test_data_path = os.path.join(test_path, 'test_data')
except:
    test_path = '/home/alex/afrl/python/source/pyvista/tests'


def test_volume():
    assert beam.volume > 0.0


@pytest.mark.skipif(not system_supports_plotting(), reason="Requires system to support plotting")
def test_struct_example():
    # create and plot structured grid
    grid = examples.load_structured()
    cpos = grid.plot(off_screen=True)  # basic plot
    assert isinstance(cpos, pyvista.CameraPosition)

    # Plot mean curvature
    cpos_curv = grid.plot_curvature(off_screen=True)
    assert isinstance(cpos_curv, pyvista.CameraPosition)


def test_init_from_structured():
    unstruct_grid = pyvista.UnstructuredGrid(sgrid)
    assert unstruct_grid.points.shape[0] == x.size
    assert np.all(unstruct_grid.celltypes == 12)
예제 #3
0
import pytest
import sys

import pyvista
from pyvista import examples
from pyvista.plotting import system_supports_plotting

NO_PLOTTING = not system_supports_plotting()

# Widgets cannot be used off screen - they must have an interactive renderer
OFF_SCREEN = False

mesh = examples.load_uniform()


@pytest.mark.skipif(NO_PLOTTING, reason="Requires system to support plotting")
def test_widget_box():
    p = pyvista.Plotter(off_screen=OFF_SCREEN)
    func = lambda box: box  # Does nothing
    p.add_mesh(mesh)
    p.enable_box_widget(callback=func)
    p.disable_box_widget()
    p.close()

    p = pyvista.Plotter(off_screen=OFF_SCREEN)
    p.add_mesh_clip_box(mesh)
    p.close()


@pytest.mark.skipif(NO_PLOTTING, reason="Requires system to support plotting")
def test_widget_plane():
예제 #4
0
# check for a valid MAPDL install with CORBA
valid_rver = ['182', '190', '191', '192', '193', '194', '195', '201']
EXEC_FILE = None
for rver in valid_rver:
    if os.path.isfile(get_ansys_bin(rver)):
        EXEC_FILE = get_ansys_bin(rver)

if 'PYANSYS_IGNORE_ANSYS' in os.environ:
    HAS_ANSYS = False
else:
    HAS_ANSYS = EXEC_FILE is not None

if not HAS_ANSYS:
    pytestmark = pytest.mark.skip("Requires ANSYS installed")

skip_no_xserver = pytest.mark.skipif(not system_supports_plotting(),
                                     reason="Requires active X Server")


@pytest.fixture(scope='function')
def cleared(mapdl):
    mapdl.finish()
    mapdl.clear(
        'NOSTART')  # *MUST* be NOSTART.  With START fails after 20 calls...
    mapdl.prep7()
    yield


@pytest.fixture(scope='function')
def make_block(mapdl, cleared):
    mapdl.block(0, 1, 0, 1, 0, 1)
예제 #5
0
OFF_SCREEN = True
VTK9 = vtk.vtkVersion().GetVTKMajorVersion() >= 9

sphere = pyvista.Sphere()
sphere_b = pyvista.Sphere(1.0)
sphere_c = pyvista.Sphere(2.0)

# Reset image cache with new images
glb_reset_image_cache = False
IMAGE_CACHE_DIR = os.path.join(Path(__file__).parent.absolute(), 'image_cache')
if not os.path.isdir(IMAGE_CACHE_DIR):
    os.mkdir(IMAGE_CACHE_DIR)

skip_no_plotting = pytest.mark.skipif(
    not system_supports_plotting(),
    reason="Test requires system to support plotting")

# IMAGE warning/error thresholds (assumes using use_vtk)
IMAGE_REGRESSION_ERROR = 500  # major differences
IMAGE_REGRESSION_WARNING = 200  # minor differences


# this must be a session fixture to ensure this runs before any other test
@pytest.fixture(scope="session", autouse=True)
def get_cmd_opt(pytestconfig):
    global glb_reset_image_cache, glb_ignore_image_cache
    glb_reset_image_cache = pytestconfig.getoption('reset_image_cache')
    glb_ignore_image_cache = pytestconfig.getoption('ignore_image_cache')

예제 #6
0
@pytest.mark.skipif(vm33 is None, reason="Requires example files")
def nodal_displacement():
    nnum, disp = vm33.nodal_displacement(0)
    assert isinstance(nnum, np.ndarray)
    assert isinstance(disp, np.ndarray)


@pytest.mark.skipif(vm33 is None, reason="Requires example files")
def test_nodal_thermal_strain():
    _, tstrain = vm33.nodal_thermal_strain(0)
    assert np.any(tstrain)
    assert tstrain.shape == (vm33.grid.n_points, 8)


@pytest.mark.skipif(not system_supports_plotting(), reason="Requires active X Server")
@pytest.mark.skipif(vm33 is None, reason="Requires example files")
def test_plot_nodal_thermal_strain():
    vm33.plot_nodal_thermal_strain(0, 'X', off_screen=True)


@pytest.mark.skipif(not system_supports_plotting(), reason="Requires active X Server")
@pytest.mark.skipif(vm33 is None, reason="Requires example files")
def test_plot_nodal_thermal_strain():
    vm33._animate_time_solution('ENS', off_screen=True)


@pytest.mark.skipif(pontoon is None, reason="Requires example files")
def test_nodal_elastic_strain():
    _, estrain = pontoon.nodal_elastic_strain(0)
    assert np.any(estrain)