.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/00-mapdl-examples/basic_dpf_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_examples_gallery_examples_00-mapdl-examples_basic_dpf_example.py>` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_examples_00-mapdl-examples_basic_dpf_example.py: .. _ref_dpf_basic_example: Basic DPF-Core Usage with PyMAPDL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example is adapted from `Basic DPF-Core Usage Example <https://dpf.docs.pyansys.com/examples/00-basic/00-basic_example.html>`_ and it shows how to open a result file in `DPF <https://dpf.docs.pyansys.com/>`_ and do some basic postprocessing. If you have Ansys 2021 R1 installed, starting DPF is quite easy as DPF-Core takes care of launching all the services that are required for postprocessing Ansys files. First, import the DPF-Core module as ``dpf_core`` and import the included examples file. .. GENERATED FROM PYTHON SOURCE LINES 21-28 .. code-block:: default import tempfile from ansys.dpf import core as dpf from ansys.mapdl.core import launch_mapdl from ansys.mapdl.core.examples import vmfiles .. GENERATED FROM PYTHON SOURCE LINES 29-34 Create model ~~~~~~~~~~~~~~ Running an example from the MAPDL verification manual .. GENERATED FROM PYTHON SOURCE LINES 34-46 .. code-block:: default mapdl = launch_mapdl() vm5 = vmfiles["vm5"] output = mapdl.input(vm5) print(output) # If you are working locally, you don't need to perform the following steps temp_directory = tempfile.gettempdir() # Downloading RST file to the current folder rst_path = mapdl.download_result(temp_directory) .. rst-class:: sphx-glr-script-out .. code-block:: none /INPUT FILE= vm5.dat LINE= 0 ANSYS MEDIA REL. 150 (11/8/2013) REF. VERIF. MANUAL: REL. 150 *** VERIFICATION RUN - CASE VM5 *** OPTION= 4 /SHOW SWITCH PLOTS TO JPEG - RASTER MODE. *****MAPDL VERIFICATION RUN ONLY***** DO NOT USE RESULTS FOR PRODUCTION ***** MAPDL ANALYSIS DEFINITION (PREP7) ***** TITLE= VM5, LATERALLY LOADED TAPERED SUPPORT STRUCTURE (QUAD. ELEMENTS) C*** MECHANICS OF SOLIDS, CRANDALL AND DAHL, 1959, PAGE 342, PROB. 7.18 C*** USING PLANE42 ELEMENTS PERFORM A STATIC ANALYSIS THIS WILL BE A NEW ANALYSIS ELEMENT TYPE 1 IS PLANE182 2-D 4-NODE PLANE STRS SOLID KEYOPT( 1- 6)= 2 0 3 0 0 0 KEYOPT( 7-12)= 0 0 0 0 0 0 KEYOPT(13-18)= 0 0 0 0 0 0 CURRENT NODAL DOF SET IS UX UY TWO-DIMENSIONAL MODEL REAL CONSTANT SET 1 ITEMS 1 TO 6 2.0000 0.0000 0.0000 0.0000 0.0000 0.0000 MATERIAL 1 EX = 0.3000000E+08 MATERIAL 1 NUXY = 0.000000 NODE 1 KCS= 0 X,Y,Z= 25.000 0.0000 0.0000 NODE 7 KCS= 0 X,Y,Z= 75.000 0.0000 0.0000 FILL 5 POINTS BETWEEN NODE 1 AND NODE 7 START WITH NODE 2 AND INCREMENT BY 1 NODE 8 KCS= 0 X,Y,Z= 25.000 -3.0000 0.0000 NODE 14 KCS= 0 X,Y,Z= 75.000 -9.0000 0.0000 FILL 5 POINTS BETWEEN NODE 8 AND NODE 14 START WITH NODE 9 AND INCREMENT BY 1 ELEMENT 1 2 1 8 9 GENERATE 6 TOTAL SETS OF ELEMENTS WITH NODE INCREMENT OF 1 SET IS SELECTED ELEMENTS IN RANGE 1 TO 1 IN STEPS OF 1 MAXIMUM ELEMENT NUMBER= 6 SELECT FOR ITEM=LOC COMPONENT=X BETWEEN 75.000 AND 75.000 KABS= 0. TOLERANCE= 0.375000 2 NODES (OF 14 DEFINED) SELECTED BY NSEL COMMAND. SPECIFIED CONSTRAINT UX FOR SELECTED NODES 1 TO 14 BY 1 REAL= 0.00000000 IMAG= 0.00000000 ADDITIONAL DOFS= UY ALL SELECT FOR ITEM=NODE COMPONENT= IN RANGE 1 TO 14 STEP 1 14 NODES (OF 14 DEFINED) SELECTED BY NSEL COMMAND. SPECIFIED NODAL LOAD FY FOR SELECTED NODES 1 TO 1 BY 1 REAL= -4000.00000 IMAG= 0.00000000 ***** ROUTINE COMPLETED ***** CP = 0.000 ***** MAPDL SOLUTION ROUTINE ***** PRINT BASI ITEMS WITH A FREQUENCY OF 1 FOR ALL APPLICABLE ENTITIES /OUTPUT FILE= .. GENERATED FROM PYTHON SOURCE LINES 47-67 Next, open the generated RST file and print out the :class:`Model <ansys.dpf.core.model.Model>` object. The :class:`Model <ansys.dpf.core.model.Model>` class helps to organize access methods for the result by keeping track of the operators and data sources used by the result file. Printing the model displays: - Analysis type - Available results - Size of the mesh - Number of results Also, note that the first time you create a DPF object, Python automatically attempts to start the server in the background. If you want to connect to an existing server (either local or remote), use :func:`dpf.connect_to_server <ansys.dpf.core.server.connect_to_server>`. In this case, DPF will attempt to connect to a local server at the port 50052 unless another port is specified. .. GENERATED FROM PYTHON SOURCE LINES 67-71 .. code-block:: default dpf.connect_to_server() .. rst-class:: sphx-glr-script-out .. code-block:: none <ansys.dpf.core.server_types.GrpcServer object at 0x7f78b8e2dfa0> .. GENERATED FROM PYTHON SOURCE LINES 72-74 If you are working with a remote server, you might need to upload the ``RST`` file before working with it. .. GENERATED FROM PYTHON SOURCE LINES 74-77 .. code-block:: default server_file_path = dpf.upload_file_in_tmp_folder(rst_path) .. GENERATED FROM PYTHON SOURCE LINES 78-80 Then you can create the :class:`DPF Model <ansys.dpf.core.model.Model>`. .. GENERATED FROM PYTHON SOURCE LINES 80-84 .. code-block:: default model = dpf.Model(server_file_path) print(model) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Model ------------------------------ Static analysis Unit system: SI: m, kg, s, V, A, K Physics Type: Mecanic Available results: - displacement: Nodal Displacement - reaction_force: Nodal Force - element_nodal_forces: ElementalNodal Element nodal Forces - stress: ElementalNodal Stress - elemental_volume: Elemental Volume - stiffness_matrix_energy: Elemental Energy-stiffness matrix - artificial_hourglass_energy: Elemental Hourglass Energy - thermal_dissipation_energy: Elemental thermal dissipation energy - kinetic_energy: Elemental Kinetic Energy - co_energy: Elemental co-energy - incremental_energy: Elemental incremental energy - elastic_strain: ElementalNodal Strain - thermal_strain: ElementalNodal Thermal Strains - thermal_strains_eqv: ElementalNodal Thermal Strains eqv - swelling_strains: ElementalNodal Swelling Strains - structural_temperature: ElementalNodal Temperature ------------------------------ DPF Meshed Region: 33 nodes 6 elements Unit: With shell (2D) elements, shell (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 1 Cumulative Time (s) LoadStep Substep 1 1.000000 1 1 .. GENERATED FROM PYTHON SOURCE LINES 85-91 Model Metadata ~~~~~~~~~~~~~~ Specific metadata can be extracted from the model by referencing the model's :attr:`metadata <ansys.dpf.core.model.Model.metadata>` property. For example, to print only the :attr:`result_info <ansys.dpf.core.model.Metadata.result_info>`: .. GENERATED FROM PYTHON SOURCE LINES 91-95 .. code-block:: default metadata = model.metadata print(metadata.result_info) .. rst-class:: sphx-glr-script-out .. code-block:: none Static analysis Unit system: SI: m, kg, s, V, A, K Physics Type: Mecanic Available results: - displacement: Nodal Displacement - reaction_force: Nodal Force - element_nodal_forces: ElementalNodal Element nodal Forces - stress: ElementalNodal Stress - elemental_volume: Elemental Volume - stiffness_matrix_energy: Elemental Energy-stiffness matrix - artificial_hourglass_energy: Elemental Hourglass Energy - thermal_dissipation_energy: Elemental thermal dissipation energy - kinetic_energy: Elemental Kinetic Energy - co_energy: Elemental co-energy - incremental_energy: Elemental incremental energy - elastic_strain: ElementalNodal Strain - thermal_strain: ElementalNodal Thermal Strains - thermal_strains_eqv: ElementalNodal Thermal Strains eqv - swelling_strains: ElementalNodal Swelling Strains - structural_temperature: ElementalNodal Temperature .. GENERATED FROM PYTHON SOURCE LINES 96-97 To print the :class:`mesh region<ansys.dpf.core.meshed_region.MeshedRegion>`: .. GENERATED FROM PYTHON SOURCE LINES 97-100 .. code-block:: default print(metadata.meshed_region) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Meshed Region: 33 nodes 6 elements Unit: With shell (2D) elements, shell (3D) elements .. GENERATED FROM PYTHON SOURCE LINES 101-103 To print the time or frequency of the results use :class:`time_freq_support <ansys.dpf.core.time_freq_support.TimeFreqSupport>`: .. GENERATED FROM PYTHON SOURCE LINES 103-106 .. code-block:: default print(metadata.time_freq_support) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Time/Freq Support: Number of sets: 1 Cumulative Time (s) LoadStep Substep 1 1.000000 1 1 .. GENERATED FROM PYTHON SOURCE LINES 107-123 Extracting Displacement Results ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All results of the model can be accessed through the :class:`Results <ansys.dpf.core.results.Results>` property, which returns the :class:`ansys.dpf.core.results.Results` class. This class contains the DPF result operators available to a specific result file, which are listed when printing the object with ``print(results)``. Here, the :class:`displacement <ansys.dpf.core.operators.result.displacement.displacement>` operator is connected with :class:`DataSources <ansys.dpf.core.data_sources.DataSources>`, which takes place automatically when running :class:`results.displacement() <ansys.dpf.core.operators.result.displacement.displacement>`. By default, the :class:`displacement <ansys.dpf.core.operators.result.displacement.displacement>` operator is connected to the first result set, which for this static result is the only result. .. GENERATED FROM PYTHON SOURCE LINES 123-132 .. code-block:: default results = model.results displacements = results.displacement() fields = displacements.outputs.fields_container() # Finally, extract the data of the displacement field: disp = fields[0].data disp .. rst-class:: sphx-glr-script-out .. code-block:: none DPFArray([[-1.10106159e-02, -6.60224200e-02, 0.00000000e+00], [-1.20838957e-02, -9.90994350e-02, 0.00000000e+00], [ 3.61860276e-04, -9.88721453e-02, 0.00000000e+00], [ 3.23207196e-03, -6.59380057e-02, 0.00000000e+00], [-1.17563515e-02, -8.18061655e-02, 0.00000000e+00], [-5.82220244e-03, -9.89754713e-02, 0.00000000e+00], [ 2.08036965e-03, -8.18682795e-02, 0.00000000e+00], [-3.87518431e-03, -6.59854725e-02, 0.00000000e+00], [-8.99066833e-03, -3.98506343e-02, 0.00000000e+00], [ 4.27062988e-03, -3.98210573e-02, 0.00000000e+00], [-1.00608366e-02, -5.19510806e-02, 0.00000000e+00], [ 3.92601832e-03, -5.19563394e-02, 0.00000000e+00], [-2.31550786e-03, -3.98370089e-02, 0.00000000e+00], [-6.69683824e-03, -2.11175625e-02, 0.00000000e+00], [ 4.17859820e-03, -2.11057663e-02, 0.00000000e+00], [-7.85485340e-03, -2.95981071e-02, 0.00000000e+00], [ 4.34038437e-03, -2.95942670e-02, 0.00000000e+00], [-1.20792265e-03, -2.11145211e-02, 0.00000000e+00], [-4.38851905e-03, -8.90023185e-03, 0.00000000e+00], [ 3.30502628e-03, -8.89049154e-03, 0.00000000e+00], [-5.53644478e-03, -1.42612890e-02, 0.00000000e+00], [ 3.82436228e-03, -1.42559816e-02, 0.00000000e+00], [-4.90502176e-04, -8.89780417e-03, 0.00000000e+00], [-2.17801557e-03, -2.15151386e-03, 0.00000000e+00], [ 1.82830253e-03, -2.15124124e-03, 0.00000000e+00], [-3.27160527e-03, -4.90756375e-03, 0.00000000e+00], [ 2.63019818e-03, -4.89004246e-03, 0.00000000e+00], [-8.95838911e-05, -2.15503538e-03, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [-1.07316284e-03, -5.41584305e-04, 0.00000000e+00], [ 9.59021573e-04, -5.64429271e-04, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]]) .. GENERATED FROM PYTHON SOURCE LINES 133-137 Plot displacements ~~~~~~~~~~~~~~~~~~ You can plot the previous displacement field using: .. GENERATED FROM PYTHON SOURCE LINES 137-140 .. code-block:: default model.metadata.meshed_region.plot(fields, cpos="xy") .. image-sg:: /examples/gallery_examples/00-mapdl-examples/images/sphx_glr_basic_dpf_example_001.png :alt: basic dpf example :srcset: /examples/gallery_examples/00-mapdl-examples/images/sphx_glr_basic_dpf_example_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 141-143 Or using .. GENERATED FROM PYTHON SOURCE LINES 143-146 .. code-block:: default fields[0].plot(cpos="xy") .. image-sg:: /examples/gallery_examples/00-mapdl-examples/images/sphx_glr_basic_dpf_example_002.png :alt: basic dpf example :srcset: /examples/gallery_examples/00-mapdl-examples/images/sphx_glr_basic_dpf_example_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 147-149 This way is particularly useful if you have used :class:`ansys.dpf.core.scoping.Scoping` on the mesh or results. .. GENERATED FROM PYTHON SOURCE LINES 152-157 Close session ~~~~~~~~~~~~~~ Stop MAPDL session. .. GENERATED FROM PYTHON SOURCE LINES 157-158 .. code-block:: default mapdl.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.463 seconds) .. _sphx_glr_download_examples_gallery_examples_00-mapdl-examples_basic_dpf_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: basic_dpf_example.py <basic_dpf_example.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: basic_dpf_example.ipynb <basic_dpf_example.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_