读取和写入 Mapdl Archive Files ======================================= Reading and Writing Mapdl Archive Files 读取 ANSYS Archive ---------------------- 可使用 Archive 加载包含单元(传统和现代单元)的 MAPDL 存档 ``*.cdb`` 和 ``*.dat`` 文件,然后将其转换为 ``vtk`` 对象: .. code:: python from ansys.mapdl import reader as pymapdl_reader from ansys.mapdl.reader import examples # 读取一个示例存档文件 archive = pymapdl_reader.Archive(examples.hexarchivefile) # 打印 cdb 中的各种原始数据 print(archive.nnum, archive.nodes) # 从原始数据访问 vtk 非结构化网格并绘制网格图 grid = archive.grid archive.plot(color='w', show_edges=True) 您还可以启用 ``read_parameters`` 参数,有选择地读取存档文件中存储的任何参数。 .. code:: python from ansys.mapdl import reader as pymapdl_reader archive = pymapdl_reader.Archive('mesh.cdb', read_parameters=True) # 参数以字典形式存储 archive.parameters 有关类方法和属性的更多详情,请参阅下面的 `Archive` 类文档。 写入 ANSYS Archive ---------------------- 使用 VTK 生成的非结构化网格可以转换为 ANSYS APDL 归档文件,并使用 ``pymapdl_reader.save_as_archive`` 加载到任何版本的 ANSYS 中。以下使用内置归档文件的示例演示了这一功能。 .. code:: python import pyvista as pv from pyvista import examples from ansys.mapdl import reader as pymapdl_reader # load in a vtk unstructured grid grid = pv.UnstructuredGrid(examples.hexbeamfile) script_filename = '/tmp/grid.cdb' pymapdl_reader.save_as_archive(script_filename, grid) # 可选择读取 ANSYS 中的存档并生成单元形状质量报告 from ansys.mapdl.core import launch_mapdl mapdl = launch_mapdl() mapdl.cdread('db', script_filename) mapdl.prep7() mapdl.shpp('SUMM') ANSYS 质量报告结果: .. code:: ------------------------------------------------------------------------------ <<<<<< SHAPE TESTING SUMMARY >>>>>> <<<<<< FOR ALL SELECTED ELEMENTS >>>>>> ------------------------------------------------------------------------------ -------------------------------------- | Element count 40 SOLID185 | -------------------------------------- Test Number tested Warning count Error count Warn+Err % ---- ------------- ------------- ----------- ---------- Aspect Ratio 40 0 0 0.00 % Parallel Deviation 40 0 0 0.00 % Maximum Angle 40 0 0 0.00 % Jacobian Ratio 40 0 0 0.00 % Warping Factor 40 0 0 0.00 % Any 40 0 0 0.00 % ------------------------------------------------------------------------------ 将 MAPDL 存档文件转换为用于 Paraview 的 VTK --------------------------------------------------- 包含实体单元(传统单元和现代单元)的 MAPDL 存档文件可使用 Archive 加载,然后转换为 VTK 对象。 .. code:: python from ansys.mapdl import reader as pymapdl_reader from ansys.mapdl.reader import examples # Sample *.cdb filename = examples.hexarchivefile # Read ansys archive file archive = pymapdl_reader.Archive(filename) # Print overview of data read from cdb print(archive) # Create a vtk unstructured grid from the raw data and plot it grid = archive.parse_vtk(force_linear=True) grid.plot(color='w', show_edges=True) # save this as a vtk xml file grid.save('hex.vtu') .. image:: ../images/hexbeam.png 然后,您可以使用 ``pyvista`` 或其他使用 VTK 的程序加载该 vtk 文件。 .. code:: python # Load this from vtk import pyvista as pv grid = pv.read('hex.vtk') grid.plot() 支持的单元 ~~~~~~~~~~~~~~~~~~ 目前, ``save_as_archive`` 函数 **只支持实体单元** ,包括 - ``vtk.VTK_TETRA`` - ``vtk.VTK_QUADRATIC_TETRA`` - ``vtk.VTK_PYRAMID`` - ``vtk.VTK_QUADRATIC_PYRAMID`` - ``vtk.VTK_WEDGE`` - ``vtk.VTK_QUADRATIC_WEDGE`` - ``vtk.VTK_HEXAHEDRON`` - ``vtk.VTK_QUADRATIC_HEXAHEDRON`` 线性单元类型将被写为 SOLID185,二次单元将被写为 SOLID186,但二次四面体除外,它将被写为 SOLID187。 Archive Class ------------- .. autoclass:: ansys.mapdl.reader.archive.Archive :members: :inherited-members: