def test_writehex(tmpdir, hex_archive): temp_archive = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(temp_archive, hex_archive.grid) archive_new = pyansys.Archive(temp_archive) assert np.allclose(hex_archive.grid.points, archive_new.grid.points) assert np.allclose(hex_archive.grid.cells, archive_new.grid.cells)
def test_writesector(tmpdir): archive = pyansys.Archive(examples.sector_archive_file) filename = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(filename, archive.grid) archive_new = pyansys.Archive(filename) assert np.allclose(archive.grid.points, archive_new.grid.points) assert np.allclose(archive.grid.cells, archive_new.grid.cells)
def test_writehex_missing_node_num(tmpdir, hex_archive): hex_archive.grid.point_arrays['ansys_node_num'][:-1] = -1 temp_archive = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(temp_archive, hex_archive.grid) archive_new = pyansys.Archive(temp_archive) assert np.allclose(hex_archive.grid.points.shape, archive_new.grid.points.shape) assert np.allclose(hex_archive.grid.cells.size, archive_new.grid.cells.size)
def test_write_non_ansys_grid(tmpdir): grid = pv.UnstructuredGrid(pyvista_examples.hexbeamfile) del grid.point_arrays['sample_point_scalars'] del grid.cell_arrays['sample_cell_scalars'] try: archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) except: archive_file = '/tmp/nblock.cdb' pyansys.save_as_archive(archive_file, grid)
def test_write_non_ansys_grid(tmpdir): grid = vtki.UnstructuredGrid(vtki_examples.hexbeamfile) del grid.point_arrays['ANSYSnodenum'] del grid.cell_arrays['ANSYSelemnum'] try: archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) except: archive_file = '/tmp/nblock.cdb' pyansys.save_as_archive(archive_file, grid)
def test_writehex_missing_elem_num(tmpdir, hex_archive): grid = hex_archive.grid grid.cell_arrays['ansys_elem_num'][:10] = -1 grid.cell_arrays['ansys_etype'] = np.ones(grid.number_of_cells)*-1 grid.cell_arrays['ansys_elem_type_num'] = np.ones(grid.number_of_cells)*-1 filename = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(filename, grid) archive_new = pyansys.Archive(filename) assert np.allclose(hex_archive.grid.points, archive_new.grid.points) assert np.allclose(hex_archive.grid.cells, archive_new.grid.cells)
def test_writehex(tmpdir): archive = pyansys.Archive(examples.hexarchivefile) grid = archive.parse_vtk() temp_archive = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(temp_archive, grid) archive2 = pyansys.Archive(temp_archive) grid2 = archive2.parse_vtk() assert np.allclose(grid.points, grid2.points) assert np.allclose(grid.cells, grid2.cells)
def test_write_lin_archive(tmpdir, celltype, all_solid_cells_archive_linear): linear_grid = all_solid_cells_archive_linear.grid mask = linear_grid.celltypes == celltype assert mask.any() linear_grid = linear_grid.extract_cells(mask) tmp_archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(tmp_archive_file, linear_grid) new_archive = pyansys.Archive(tmp_archive_file) assert new_archive.quality > 0 assert np.allclose(linear_grid.celltypes, new_archive.grid.celltypes)
def test_writehex_missing_node_num(tmpdir): archive = pyansys.Archive(examples.hexarchivefile) grid = archive.parse_vtk() grid.point_arrays['ansys_node_num'][:-1] = -1 temp_archive = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(temp_archive, grid) archive2 = pyansys.Archive(temp_archive) grid2 = archive2.parse_vtk() assert np.allclose(grid.points.shape, grid2.points.shape) assert np.allclose(grid.cells.size, grid2.cells.size)
def test_writehex_missing_elem_num(tmpdir): archive = pyansys.Archive(examples.hexarchivefile) grid = archive.parse_vtk() grid.cell_arrays['ansys_elem_num'][:10] = -1 grid.cell_arrays['ansys_etype'] = np.ones(grid.number_of_cells)*-1 grid.cell_arrays['ansys_elem_type_num'] = np.ones(grid.number_of_cells)*-1 temp_archive = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pyansys.save_as_archive(temp_archive, grid) archive2 = pyansys.Archive(temp_archive) grid2 = archive2.parse_vtk() assert np.allclose(grid.points.shape, grid2.points.shape) assert np.allclose(grid.cells.size, grid2.cells.size)
def test_write_quad_complex_archive(tmpdir, celltype, all_solid_cells_archive): grid = all_solid_cells_archive.grid mask = grid.celltypes == celltype assert mask.any() grid = grid.extract_cells(mask) try: tmp_archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) except: tmp_archive_file = '/tmp/nblock.cdb' pyansys.save_as_archive(tmp_archive_file, grid) new_archive = pyansys.Archive(tmp_archive_file) assert np.allclose(grid.cells, new_archive.grid.cells) assert np.allclose(grid.points, new_archive.grid.points) assert (new_archive.quality > 0.0).all()
def test_write_lin_archive(tmpdir, celltype): archive_file = os.path.join(testfiles_path, 'all_solid_cells.cdb') archive = pyansys.Archive(archive_file) linear_grid = archive.parse_vtk(force_linear=True) mask = linear_grid.celltypes == celltype assert mask.any() linear_grid = linear_grid.extract_cells(mask) try: tmp_archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) except: tmp_archive_file = '/tmp/nblock.cdb' pyansys.save_as_archive(tmp_archive_file, linear_grid) new_archive = pyansys.Archive(tmp_archive_file) new_linear_grid = new_archive.parse_vtk() assert np.allclose(linear_grid.cells, new_linear_grid.cells) assert np.allclose(linear_grid.points, new_linear_grid.points)
def test_write_quad_complex_archive(tmpdir, celltype): # celltype = 24 archive_file = os.path.join(testfiles_path, 'all_solid_cells.cdb') archive = pyansys.Archive(archive_file) grid = archive.parse_vtk() mask = grid.celltypes == celltype assert mask.any() grid = grid.extract_cells(mask) try: tmp_archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) except: tmp_archive_file = '/tmp/nblock.cdb' pyansys.save_as_archive(tmp_archive_file, grid) new_archive = pyansys.Archive(tmp_archive_file) new_grid = new_archive.parse_vtk() assert np.allclose(grid.cells, new_grid.cells) assert np.allclose(grid.points, new_grid.points) assert (new_grid.quality > 0.0).all()
import pyvista as pv import pyansys # launch MAPDL and run a modal analysis os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary for Ubuntu mapdl = pyansys.launch_mapdl(loglevel='WARNING', override=True) # Create a simple plane mesh centered at (0, 0, 0) on the XY plane mesh = pv.Plane(i_resolution=100, j_resolution=100) mesh.plot(color='w', show_edges=True) ############################################################################### # Write the mesh to an archive file archive_filename = os.path.join(mapdl.path, 'tmp.cdb') pyansys.save_as_archive(archive_filename, mesh) ############################################################################### # mapdl = pyansys.launch_mapdl(prefer_pexpect=True, override=True) # Read in the archive file response = mapdl.cdread('db', archive_filename) mapdl.prep7() print(mapdl.shpp('SUMM')) # specify shell thickness mapdl.sectype(1, "shell") mapdl.secdata(0.01) mapdl.emodif('ALL', 'SECNUM', 1) # specify material properties
QUADRATIC_CELL_TYPES = [ VTK_QUADRATIC_TETRA, VTK_QUADRATIC_PYRAMID, VTK_QUADRATIC_WEDGE, VTK_QUADRATIC_HEXAHEDRON ] try: test_path = os.path.dirname(os.path.abspath(__file__)) testfiles_path = os.path.join(test_path, 'test_data') except: testfiles_path = '/home/alex/afrl/python/source/pyansys/tests/archive/test_data' archive_file = os.path.join(testfiles_path, 'all_solid_cells.cdb') archive = pyansys.Archive(archive_file) linear_grid = archive.parse_vtk(force_linear=True) celltype = VTK_TETRA mask = linear_grid.celltypes == celltype assert mask.any() linear_grid = linear_grid.extract_cells(mask) try: tmp_archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) except: tmp_archive_file = '/tmp/nblock.cdb' pyansys.save_as_archive(tmp_archive_file, linear_grid) new_archive = pyansys.Archive(tmp_archive_file) new_linear_grid = new_archive.parse_vtk() assert np.allclose(linear_grid.cells, new_linear_grid.cells) assert np.allclose(linear_grid.points, new_linear_grid.points)