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_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_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_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_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()
""" This script convert the file in `gmsh` format to ANSYS `CDB` format. """ import pyvista as pv from ansys.mapdl.reader import save_as_archive filename = 'from_gmsh.msh' mesh = pv.read_meshio(filename) # mesh.plot() # optionally plot the mesh mesh.points /= 1000 save_as_archive('archive.cdb', mesh)
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'] archive_file = str(tmpdir.mkdir("tmpdir").join('tmp.cdb')) pymapdl_reader.save_as_archive(archive_file, grid)
import os import pyvista as pv from ansys.mapdl.reader import save_as_archive from ansys.mapdl.core import launch_mapdl # launch MAPDL as a service mapdl = launch_mapdl(loglevel="ERROR") # 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 a temporary file archive_filename = os.path.join(tempfile.gettempdir(), "tmp.cdb") save_as_archive(archive_filename, mesh) # 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 # using aprox values for AISI 5000 Series Steel # http://www.matweb.com/search/datasheet.aspx?matguid=89d4b891eece40fbbe6b71f028b64e9e mapdl.units("SI") # not necessary, but helpful for book keeping