.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\12-fluids\03-fluids_isosurface.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_12-fluids_03-fluids_isosurface.py: .. _ref_fluids_isosurface: Compute iso-surfaces on fluid models ------------------------------------------ This example demonstrates how to compute iso-surfaces on fluid models. .. note:: This example requires DPF 7.0 (ansys-dpf-server-2024-1-pre0) or above. For more information, see :ref:`ref_compatibility`. .. GENERATED FROM PYTHON SOURCE LINES 16-18 Import the ``dpf-core`` module and its examples files. ~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 18-23 .. code-block:: default import ansys.dpf.core as dpf from ansys.dpf.core import examples from ansys.dpf.core.plotter import DpfPlotter .. GENERATED FROM PYTHON SOURCE LINES 24-27 Specify the file path. ~~~~~~~~~~~~~~~~~~ We work on a cas/dat.h5 file with only nodal variables. .. GENERATED FROM PYTHON SOURCE LINES 27-34 .. code-block:: default path = examples.download_cfx_heating_coil() ds = dpf.DataSources() ds.set_result_file_path(path["cas"], "cas") ds.add_file_path(path["dat"], "dat") streams = dpf.operators.metadata.streams_provider(data_sources=ds) .. GENERATED FROM PYTHON SOURCE LINES 35-39 Whole mesh scoping. ~~~~~~~~~~~~~~~~~~ We evaluate the mesh with the mesh_provider operator to scope the mesh_cut operator with the whole mesh. .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: default whole_mesh = dpf.operators.mesh.mesh_provider(streams_container=streams).eval() print(whole_mesh) whole_mesh.plot() .. image-sg:: /examples/12-fluids/images/sphx_glr_03-fluids_isosurface_001.png :alt: 03 fluids isosurface :srcset: /examples/12-fluids/images/sphx_glr_03-fluids_isosurface_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Meshed Region: 25456 nodes 74882 elements Unit: m With solid (3D) elements .. GENERATED FROM PYTHON SOURCE LINES 46-51 Extract the physics variable ~~~~~~~~~~~~~~~~~ Here we choose to work with the static pressure by default which is a scalar and nodal variable without multi-species/phases. With a multi-species case, select one using qualifier ellipsis pins and connecting a LabelSpace "species"/"phase". .. GENERATED FROM PYTHON SOURCE LINES 51-64 .. code-block:: default P_S = dpf.operators.result.static_pressure(streams_container=streams, mesh=whole_mesh).eval() print(P_S[0]) pl = DpfPlotter() pl.add_field(P_S[0]) cpos_mesh_variable = [ (4.256160478475664, 4.73662111240005, 4.00410065817644), (-0.0011924505233764648, 1.8596649169921875e-05, 1.125), (-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), ] pl.show_figure(cpos=cpos_mesh_variable, show_axes=True) .. image-sg:: /examples/12-fluids/images/sphx_glr_03-fluids_isosurface_002.png :alt: 03 fluids isosurface :srcset: /examples/12-fluids/images/sphx_glr_03-fluids_isosurface_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none DPF p_ Field Location: Nodal Unit: Pa 23648 entities Data: 1 components and 23648 elementary data IDs data(Pa) ------------ ---------- 1 6.804220e+01 2 -1.422350e+01 3 2.180406e+02 ... .. GENERATED FROM PYTHON SOURCE LINES 65-69 Evaluate iso-surfaces ~~~~~~~~~~~~~~ We can finally use the mesh_cut operator on this specific variable. We choose to cut the whole with 5 iso-surface equally spaced between min and max. .. GENERATED FROM PYTHON SOURCE LINES 69-105 .. code-block:: default max_pressure = 361.8170 # Pa min_pressure = -153.5356 # Pa number_of_iso_surface = 5 step = (max_pressure - min_pressure) / number_of_iso_surface pl = DpfPlotter() c_pos_iso = [ (4.256160478475664, 4.73662111240005, 4.00410065817644), (-0.0011924505233764648, 1.8596649169921875e-05, 1.125), (-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), ] pl.add_mesh( meshed_region=whole_mesh, style="wireframe", show_edges=True, show_axes=True, color="black", opacity=0.3, ) for i in range(number_of_iso_surface): iso_surface = dpf.operators.mesh.mesh_cut( field=P_S[0], iso_value=min_pressure, closed_surface=0, mesh=whole_mesh, slice_surfaces=True ).eval() P_S_step = dpf.Field(location=dpf.locations.overall, nature=dpf.common.natures.scalar) P_S_step.append([min_pressure], i) P_S_step.name = "static pressure" P_S_step.unit = "Pa" pl.add_field( field=P_S_step, meshed_region=iso_surface, style="surface", show_edges=False, show_axes=True ) min_pressure += step pl.show_figure(show_axes=True, cpos=c_pos_iso) .. image-sg:: /examples/12-fluids/images/sphx_glr_03-fluids_isosurface_003.png :alt: 03 fluids isosurface :srcset: /examples/12-fluids/images/sphx_glr_03-fluids_isosurface_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 106-112 Important note ------------------------------ Iso-surfaces computation through the `mesh_cut` operator are only supported for Nodal Fields. For Elemental variables, you must perform an averaging operation on the Nodes before running the `mesh_cut` operator. This can be done by chaining the `elemental_to_nodal` operator output with the `mesh_cut` operator input. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 3.658 seconds) .. _sphx_glr_download_examples_12-fluids_03-fluids_isosurface.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03-fluids_isosurface.py <03-fluids_isosurface.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03-fluids_isosurface.ipynb <03-fluids_isosurface.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_