def test_writesector(tmpdir): archive = pymapdl_reader.Archive(examples.sector_archive_file) filename = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pymapdl_reader.save_as_archive(filename, archive.grid) archive_new = pymapdl_reader.Archive(filename) assert np.allclose(archive.grid.points, archive_new.grid.points) assert np.allclose(archive.grid.cells, archive_new.grid.cells)
def test_read_parm(): filename = os.path.join(TESTFILES_PATH, 'parm.cdb') archive = pymapdl_reader.Archive(filename) with pytest.raises(AttributeError): archive.parameters archive = pymapdl_reader.Archive(filename, read_parameters=True) assert len(archive.parameters) == 2 for parm in archive.parameters: assert isinstance(archive.parameters[parm], np.ndarray)
def test_write_angle(tmpdir, hex_archive): nblock_filename = str(tmpdir.mkdir("tmpdir").join('nblock.cdb')) pymapdl_reader.write_nblock(nblock_filename, hex_archive.nnum, hex_archive.nodes, hex_archive.node_angles) archive = pymapdl_reader.Archive(nblock_filename, parse_vtk=False) assert np.allclose(archive.nodes, hex_archive.nodes)
def test_invalid_archive(tmpdir, hex_archive): nblock_filename = str(tmpdir.mkdir("tmpdir").join('nblock.cdb')) pymapdl_reader.write_nblock(nblock_filename, hex_archive.nnum, hex_archive.nodes) archive = pymapdl_reader.Archive(nblock_filename) assert archive.grid is None
def test_missing_midside(): allowable_types = [45, 95, 185, 186, 92, 187] archive_file = os.path.join(TESTFILES_PATH, 'mixed_missing_midside.cdb') archive = pymapdl_reader.Archive(archive_file, allowable_types=allowable_types) assert (archive.quality > 0.0).all() assert not np.any(archive.grid.celltypes == VTK_TETRA)
def test_read_wb_nblock(): expected = np.array([[9.89367578e-02, -8.07092192e-04, 8.53764953e+00], [9.65803244e-02, 2.00906704e-02, 8.53744951e+00], [9.19243555e-02, 3.98781615e-02, 8.53723652e+00]]) filename = os.path.join(TESTFILES_PATH, 'workbench_193.cdb') archive = pymapdl_reader.Archive(filename) assert np.allclose(archive.nodes, expected) assert np.allclose(archive.node_angles, 0)
def test_write_component(tmpdir): items = np.array([1, 20, 50, 51, 52, 53]) filename = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) comp_name = 'TEST' pymapdl_reader.write_cmblock(filename, items, comp_name, 'node') archive = pymapdl_reader.Archive(filename) assert np.allclose(archive.node_components[comp_name], items)
def test_writehex_missing_node_num(tmpdir, hex_archive): hex_archive.grid.point_arrays['ansys_node_num'][:-1] = -1 filename = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pymapdl_reader.save_as_archive(filename, hex_archive.grid) archive_new = pymapdl_reader.Archive(filename) 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_read_hypermesh(): expected = np.array([[-6.01203, 2.98129, 2.38556], [-3.03231, 2.98067, 2.38309], [-0.03485, 2.98004, 2.3805], [2.98794, 2.97941, 2.37773], [5.98956, 2.97878, 2.37488], [5.98956, 5.97878, 2.37488]]) filename = os.path.join(TESTFILES_PATH, 'hypermesh.cdb') archive = pymapdl_reader.Archive(filename, verbose=True) assert np.allclose(archive.nodes[:6], expected)
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')) pymapdl_reader.save_as_archive(filename, grid) archive_new = pymapdl_reader.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_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')) pymapdl_reader.save_as_archive(tmp_archive_file, linear_grid) new_archive = pymapdl_reader.Archive(tmp_archive_file) assert new_archive.quality > 0 assert np.allclose(linear_grid.celltypes, new_archive.grid.celltypes)
def test_writehex(tmpdir, hex_archive): filename = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pymapdl_reader.save_as_archive(filename, hex_archive.grid) archive_new = pymapdl_reader.Archive(filename) assert np.allclose(hex_archive.grid.points, archive_new.grid.points) assert np.allclose(hex_archive.grid.cells, archive_new.grid.cells) for node_component in hex_archive.node_components: assert np.allclose(hex_archive.node_components[node_component], archive_new.node_components[node_component]) for element_component in hex_archive.element_components: assert np.allclose(hex_archive.element_components[element_component], archive_new.element_components[element_component])
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' pymapdl_reader.save_as_archive(tmp_archive_file, grid) new_archive = pymapdl_reader.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_cython_write_nblock(hex_archive, tmpdir, angles): nblock_filename = str(tmpdir.mkdir("tmpdir").join('nblock.inp')) if angles: _archive.py_write_nblock(nblock_filename, hex_archive.nnum, hex_archive.nnum[-1], hex_archive.nodes, hex_archive.node_angles) else: _archive.py_write_nblock(nblock_filename, hex_archive.nnum, hex_archive.nnum[-1], hex_archive.nodes, np.empty((0, 0))) tmp_archive = pymapdl_reader.Archive(nblock_filename) assert np.allclose(hex_archive.nnum, tmp_archive.nnum) assert np.allclose(hex_archive.nodes, tmp_archive.nodes) if angles: assert np.allclose(hex_archive.node_angles, tmp_archive.node_angles)
def test_write_nblock(hex_archive, tmpdir, dtype, has_angles): nblock_filename = str(tmpdir.mkdir("tmpdir").join('nblock.inp')) nodes = hex_archive.nodes.astype(dtype) if has_angles: angles = hex_archive.node_angles else: angles = None archive.write_nblock(nblock_filename, hex_archive.nnum, nodes, angles, mode='w') tmp_archive = pymapdl_reader.Archive(nblock_filename) assert np.allclose(hex_archive.nnum, tmp_archive.nnum) assert np.allclose(hex_archive.nodes, tmp_archive.nodes) if has_angles: assert np.allclose(hex_archive.node_angles, tmp_archive.node_angles)
def all_solid_cells_archive_linear(): return pymapdl_reader.Archive(os.path.join(TESTFILES_PATH, 'all_solid_cells.cdb'), force_linear=True)
def all_solid_cells_archive(): return pymapdl_reader.Archive( os.path.join(TESTFILES_PATH, 'all_solid_cells.cdb'))
def hex_archive(): return pymapdl_reader.Archive(examples.hexarchivefile)
def test_rlblock_prior_to_nblock(): # test edge case where RLBLOCK is immediately prior to the NBLOCK filename = os.path.join(TESTFILES_PATH, 'ErnoRadiation.cdb') archive = pymapdl_reader.Archive(filename) assert archive.n_node == 65 assert archive.n_elem == 36
def test_read_mesh200(): archive = pymapdl_reader.Archive( os.path.join(testfiles_path, 'mesh200.cdb')) assert archive.grid.n_cells == 1000
def archive(): filename = os.path.join(testfiles_path, 'archive.cdb') return pymapdl_reader.Archive(filename)
def _download_and_read(filename): saved_file, _ = _download_file(filename) if saved_file[-3:] == 'cdb': return pymapdl_reader.Archive(saved_file) else: return pymapdl_reader.read_binary(saved_file)
def test_load_dat(): arch = pymapdl_reader.Archive(DAT_FILE, read_parameters=True) assert arch.n_node == 1263 # through inspection of the dat file assert arch.n_elem == 160 # through inspection of the dat file assert 'Panelflattern' in arch.parameters['_wb_userfiles_dir']
def all_solid_cells_archive_linear(): return pymapdl_reader.Archive(os.path.join(testfiles_path, 'all_solid_cells.cdb'), force_linear=True)
def test_read_mesh200(): archive = pymapdl_reader.Archive( os.path.join(TESTFILES_PATH, 'mesh200.cdb')) assert archive.grid.n_cells == 1000
def all_solid_cells_archive(): return pymapdl_reader.Archive( os.path.join(testfiles_path, 'all_solid_cells.cdb'))