|
| 1 | +.. _ref_tutorials_extract_and_explore_results_metadata: |
| 2 | + |
| 3 | +==================================== |
| 4 | +Extract and explore results metadata |
| 5 | +==================================== |
| 6 | + |
| 7 | +:bdg-mapdl:`MAPDL` :bdg-lsdyna:`LS-DYNA` :bdg-fluent:`FLUENT` :bdg-cfx:`CFX` |
| 8 | + |
| 9 | +.. include:: ../../../links_and_refs.rst |
| 10 | +.. |ResultInfo| replace:: :class:`ResultInfo<ansys.dpf.core.result_info.ResultInfo>` |
| 11 | + |
| 12 | +This tutorial shows how to extract and explore results metadata from a result file. |
| 13 | + |
| 14 | +:jupyter-download-script:`Download tutorial as Python script<extract_and_explore_results_metadata>` |
| 15 | +:jupyter-download-notebook:`Download tutorial as Jupyter notebook<extract_and_explore_results_metadata>` |
| 16 | + |
| 17 | +Get the result file |
| 18 | +------------------- |
| 19 | + |
| 20 | +First, import a result file. For this tutorial, you can use one available in the |Examples| module. |
| 21 | +For more information about how to import your own result file in DPF, see the :ref:`ref_tutorials_import_result_file` |
| 22 | +tutorial. |
| 23 | + |
| 24 | +.. jupyter-execute:: |
| 25 | + |
| 26 | + # Import the ``ansys.dpf.core`` module |
| 27 | + from ansys.dpf import core as dpf |
| 28 | + # Import the examples module |
| 29 | + from ansys.dpf.core import examples |
| 30 | + # Import the operators module |
| 31 | + from ansys.dpf.core import operators as ops |
| 32 | + |
| 33 | + # Define the result file path |
| 34 | + result_file_path_1 = examples.download_transient_result() |
| 35 | + # Create the model |
| 36 | + model_1 = dpf.Model(data_sources=result_file_path_1) |
| 37 | + |
| 38 | +Explore the results general metadata |
| 39 | +------------------------------------ |
| 40 | + |
| 41 | +You can explore the general results metadata, before extracting the results, by using |
| 42 | +the |ResultInfo| object and its methods. This metadata includes: |
| 43 | + |
| 44 | +- Analysis type; |
| 45 | +- Physics type; |
| 46 | +- Number of results; |
| 47 | +- Unit system; |
| 48 | +- Solver version, date and time; |
| 49 | +- Job name; |
| 50 | + |
| 51 | +.. jupyter-execute:: |
| 52 | + |
| 53 | + # Define the ResultInfo object |
| 54 | + result_info_1 = model_1.metadata.result_info |
| 55 | + |
| 56 | + # Get the analysis type |
| 57 | + analysis_type = result_info_1.analysis_type |
| 58 | + # Print the analysis type |
| 59 | + print("Analysis type: ",analysis_type, "\n") |
| 60 | + |
| 61 | + # Get the physics type |
| 62 | + physics_type = result_info_1.physics_type |
| 63 | + # Print the physics type |
| 64 | + print("Physics type: ",physics_type, "\n") |
| 65 | + |
| 66 | + # Get the number of available results |
| 67 | + number_of_results = result_info_1.n_results |
| 68 | + # Print the number of available results |
| 69 | + print("Number of available results: ",number_of_results, "\n") |
| 70 | + |
| 71 | + # Get the unit system |
| 72 | + unit_system = result_info_1.unit_system |
| 73 | + # Print the unit system |
| 74 | + print("Unit system: ",unit_system, "\n") |
| 75 | + |
| 76 | + # Get the solver version, data and time |
| 77 | + solver_version = result_info_1.solver_version |
| 78 | + solver_date = result_info_1.solver_date |
| 79 | + solver_time = result_info_1.solver_time |
| 80 | + |
| 81 | + # Print the solver version, data and time |
| 82 | + print("Solver version: ",solver_version, "\n") |
| 83 | + print("Solver date: ", solver_date, "\n") |
| 84 | + print("Solver time: ",solver_time, "\n") |
| 85 | + |
| 86 | + # Get the job name |
| 87 | + job_name = result_info_1.job_name |
| 88 | + # Print the job name |
| 89 | + print("Job name: ",job_name, "\n") |
| 90 | + |
| 91 | +Explore a result metadata |
| 92 | +------------------------- |
| 93 | +When you extract a result from a result file DPF stores it in a |Field|. |
| 94 | +Thus, this |Field| contains the metadata for the result associated with it. |
| 95 | +This metadata includes: |
| 96 | + |
| 97 | +- Location; |
| 98 | +- Scoping (type and quantity of entities); |
| 99 | +- Elementary data count (number of entities, how many data vectors we have); |
| 100 | +- Components count (vectors dimension, here we have a displacement so we expect to have 3 components (X, Y and Z)); |
| 101 | +- Shape of the data stored (tuple with the elementary data count and the components count); |
| 102 | +- Fields size (length of the data entire vector (equal to the number of elementary data times the number of components)); |
| 103 | +- Units of the data. |
| 104 | + |
| 105 | +Here we will explore the metadata of the displacement results. |
| 106 | + |
| 107 | +Start by extracting the displacement results. |
| 108 | + |
| 109 | +.. jupyter-execute:: |
| 110 | + |
| 111 | + # Extract the displacement results |
| 112 | + disp_results = model_1.results.displacement.eval() |
| 113 | + |
| 114 | + # Get the displacement field |
| 115 | + disp_field = disp_results[0] |
| 116 | + |
| 117 | +Explore the displacement results metadata: |
| 118 | + |
| 119 | +.. jupyter-execute:: |
| 120 | + |
| 121 | + # Get the location of the displacement data |
| 122 | + location = disp_field.location |
| 123 | + # Print the location |
| 124 | + print("Location: ", location,'\n') |
| 125 | + |
| 126 | + # Get the displacement Field scoping |
| 127 | + scoping = disp_field.scoping |
| 128 | + # Print the Field scoping |
| 129 | + print("Scoping: ", '\n',scoping, '\n') |
| 130 | + |
| 131 | + # Get the displacement Field scoping ids |
| 132 | + scoping_ids = disp_field.scoping.ids # Available entities ids |
| 133 | + # Print the Field scoping ids |
| 134 | + print("Scoping ids: ", scoping_ids, '\n') |
| 135 | + |
| 136 | + # Get the displacement Field elementary data count |
| 137 | + elementary_data_count = disp_field.elementary_data_count |
| 138 | + # Print the elementary data count |
| 139 | + print("Elementary data count: ", elementary_data_count, '\n') |
| 140 | + |
| 141 | + # Get the displacement Field components count |
| 142 | + components_count = disp_field.component_count |
| 143 | + # Print the components count |
| 144 | + print("Components count: ", components_count, '\n') |
| 145 | + |
| 146 | + # Get the displacement Field size |
| 147 | + field_size = disp_field.size |
| 148 | + # Print the Field size |
| 149 | + print("Size: ", field_size, '\n') |
| 150 | + |
| 151 | + # Get the displacement Field shape |
| 152 | + shape = disp_field.shape |
| 153 | + # Print the Field shape |
| 154 | + print("Shape: ", shape, '\n') |
| 155 | + |
| 156 | + # Get the displacement Field unit |
| 157 | + unit = disp_field.unit |
| 158 | + # Print the displacement Field unit |
| 159 | + print("Unit: ", unit, '\n') |
0 commit comments