.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/pre-processing/example_cdb_load.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_pre-processing_example_cdb_load.py: Loading a CDB input deck ======================== Show the preferred CDB-reader workflow: load an MAPDL CDB with :mod:`mapdl_archive`, hand the parsed grid to :meth:`femorph_solver.Model.from_grid`, stamp a material, and assemble the global stiffness / mass matrices. The example uses the 15-sector rotor deck that ships with :mod:`mapdl_archive`, so it runs without any user-provided files. .. GENERATED FROM PYTHON SOURCE LINES 13-21 .. code-block:: Python from __future__ import annotations import mapdl_archive import numpy as np import femorph_solver .. GENERATED FROM PYTHON SOURCE LINES 22-24 Parse the CDB ------------- .. GENERATED FROM PYTHON SOURCE LINES 24-35 .. code-block:: Python archive = mapdl_archive.Archive(mapdl_archive.examples.sector_archive_file) print(f"parsed grid: {archive.grid}") print(f"element types present: {sorted(set(archive.etype))}") # The shipped fixture has 101 HEX8 cells plus 4 WEDGE6 tip cells. # femorph-solver's SOLID185 kernel is hex-only, so we drop the wedges # (``VTK_HEXAHEDRON`` is cell type 12). hex_idx = np.where(archive.grid.celltypes == 12)[0] grid = archive.grid.extract_cells(hex_idx).cast_to_unstructured_grid() print(f"hex-only sub-grid: {grid.n_cells} cells, {grid.n_points} nodes") .. rst-class:: sphx-glr-script-out .. code-block:: none parsed grid: UnstructuredGrid (0x78fb962236a0) N Cells: 105 N Points: 655 X Bounds: -1.216e+00, 5.571e-02 Y Bounds: -1.663e+00, -4.353e-01 Z Bounds: -7.875e-01, -2.610e-02 N Arrays: 12 element types present: [np.int32(185)] hex-only sub-grid: 101 cells, 230 nodes .. GENERATED FROM PYTHON SOURCE LINES 36-38 Wrap the grid as a femorph-solver ``Model`` -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python m = femorph_solver.Model.from_grid(grid) m.et(185, "SOLID185") .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/_work/solver/solver/examples/pre-processing/example_cdb_load.py:39: DeprecationWarning: Model.et(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).et(et_id, name)` for line-by-line APDL deck porting, or the native `Model.assign("HEX8", material)` for new code. m.et(185, "SOLID185") .. GENERATED FROM PYTHON SOURCE LINES 42-44 Apply material properties ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 44-49 .. code-block:: Python for mat_id in np.unique(np.asarray(grid.cell_data["ansys_material_type"])): m.mp("EX", int(mat_id), 2.1e11) m.mp("PRXY", int(mat_id), 0.30) m.mp("DENS", int(mat_id), 7850.0) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/_work/solver/solver/examples/pre-processing/example_cdb_load.py:45: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("EX", int(mat_id), 2.1e11) /home/runner/_work/solver/solver/examples/pre-processing/example_cdb_load.py:46: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("PRXY", int(mat_id), 0.30) /home/runner/_work/solver/solver/examples/pre-processing/example_cdb_load.py:47: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("DENS", int(mat_id), 7850.0) .. GENERATED FROM PYTHON SOURCE LINES 50-52 Assemble K and M ---------------- .. GENERATED FROM PYTHON SOURCE LINES 52-57 .. code-block:: Python K = m.stiffness_matrix() M = m.mass_matrix() print(f"K: {K.shape}, nnz = {K.nnz:,}") print(f"M: {M.shape}, nnz = {M.nnz:,}") .. rst-class:: sphx-glr-script-out .. code-block:: none K: (690, 690), nnz = 33,750 M: (690, 690), nnz = 33,750 .. GENERATED FROM PYTHON SOURCE LINES 58-64 That's the full pre-processing loop ----------------------------------- From here, any of the analyses under :doc:`/gallery/analyses/index` can take over — ``m.modal_solve(n_modes=10)``, ``m.solve()``, ``m.transient_solve(...)``, or the free-standing ``solve_*`` functions if you need finer backend control. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.024 seconds) .. _sphx_glr_download_gallery_pre-processing_example_cdb_load.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_cdb_load.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_cdb_load.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_cdb_load.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_