|
| 1 | +""" |
| 2 | +.. _ref_fluids_isosurface: |
| 3 | +
|
| 4 | +Compute iso-surfaces on fluid models |
| 5 | +------------------------------------------ |
| 6 | +
|
| 7 | +This example demonstrates how to compute iso-surfaces on fluid models. |
| 8 | +""" |
| 9 | + |
| 10 | +############################################################################### |
| 11 | +# Import the ``dpf-core`` module and its examples files. |
| 12 | +# ~~~~~~~~~~~~~~~~~~ |
| 13 | + |
| 14 | +import ansys.dpf.core as dpf |
| 15 | +from ansys.dpf.core import examples |
| 16 | +from ansys.dpf.core.plotter import DpfPlotter |
| 17 | + |
| 18 | +############################################################################### |
| 19 | +# Specify the file path. |
| 20 | +# ~~~~~~~~~~~~~~~~~~ |
| 21 | +# We work on a cas/dat.h5 file with only nodal variables. |
| 22 | + |
| 23 | +path = examples.download_cfx_heating_coil() |
| 24 | +ds = dpf.DataSources() |
| 25 | +ds.set_result_file_path(path["cas"], "cas") |
| 26 | +ds.add_file_path(path["dat"], "dat") |
| 27 | +streams = dpf.operators.metadata.streams_provider(data_sources=ds) |
| 28 | + |
| 29 | +############################################################################### |
| 30 | +# Whole mesh scoping. |
| 31 | +# ~~~~~~~~~~~~~~~~~~ |
| 32 | +# We evaluate the mesh with the mesh_provider operator to scope the mesh_cut operator |
| 33 | +# with the whole mesh. |
| 34 | + |
| 35 | +whole_mesh = dpf.operators.mesh.mesh_provider(streams_container=streams).eval() |
| 36 | +print(whole_mesh) |
| 37 | + |
| 38 | +pl = DpfPlotter() |
| 39 | +pl.add_mesh(whole_mesh) |
| 40 | +cpos_whole_mesh = [ |
| 41 | + (4.256160478475664, 4.73662111240005, 4.00410065817644), |
| 42 | + (-0.0011924505233764648, 1.8596649169921875e-05, 1.125), |
| 43 | + (-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), |
| 44 | +] |
| 45 | +pl.show_figure(cpos=cpos_whole_mesh, show_axes=True) |
| 46 | + |
| 47 | +############################################################################### |
| 48 | +# Extract the physics variable |
| 49 | +# ~~~~~~~~~~~~~~~~~ |
| 50 | +# Here we choose to work with the static pressure by default which is a scalar and |
| 51 | +# nodal variable without multi-species/phases. With a multi-species case, |
| 52 | +# select one using qualifier ellipsis pins and connecting a LabelSpace "species"/"phase". |
| 53 | + |
| 54 | +P_S = dpf.operators.result.static_pressure(streams_container=streams, mesh=whole_mesh).eval() |
| 55 | +print(P_S[0]) |
| 56 | + |
| 57 | +pl = DpfPlotter() |
| 58 | +pl.add_field(P_S[0]) |
| 59 | +cpos_mesh_variable = [ |
| 60 | + (4.256160478475664, 4.73662111240005, 4.00410065817644), |
| 61 | + (-0.0011924505233764648, 1.8596649169921875e-05, 1.125), |
| 62 | + (-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), |
| 63 | +] |
| 64 | +pl.show_figure(cpos=cpos_mesh_variable, show_axes=True) |
| 65 | + |
| 66 | +############################################################################### |
| 67 | +# Evaluate iso-surfaces |
| 68 | +# ~~~~~~~~~~~~~~ |
| 69 | +# We can finally use the mesh_cut operator on this specific variable. |
| 70 | +# We choose to cut the whole with 5 iso-surface equally spaced between min and max. |
| 71 | + |
| 72 | +max_pressure = 361.8170 # Pa |
| 73 | +min_pressure = -153.5356 # Pa |
| 74 | +number_of_iso_surface = 5 |
| 75 | +step = (max_pressure - min_pressure) / number_of_iso_surface |
| 76 | + |
| 77 | +pl = DpfPlotter() |
| 78 | +c_pos_iso = [ |
| 79 | + (4.256160478475664, 4.73662111240005, 4.00410065817644), |
| 80 | + (-0.0011924505233764648, 1.8596649169921875e-05, 1.125), |
| 81 | + (-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), |
| 82 | +] |
| 83 | +pl.add_mesh( |
| 84 | + meshed_region=whole_mesh, |
| 85 | + style="wireframe", |
| 86 | + show_edges=True, |
| 87 | + show_axes=True, |
| 88 | + color="black", |
| 89 | + opacity=0.3, |
| 90 | +) |
| 91 | + |
| 92 | +for i in range(number_of_iso_surface): |
| 93 | + iso_surface = dpf.operators.mesh.mesh_cut( |
| 94 | + field=P_S[0], iso_value=min_pressure, closed_surface=0, mesh=whole_mesh, slice_surfaces=True |
| 95 | + ).eval() |
| 96 | + P_S_step = dpf.Field(location=dpf.locations.overall, nature=dpf.common.natures.scalar) |
| 97 | + P_S_step.append([min_pressure], i) |
| 98 | + P_S_step.name = "static pressure" |
| 99 | + P_S_step.unit = "Pa" |
| 100 | + pl.add_field( |
| 101 | + field=P_S_step, meshed_region=iso_surface, style="surface", show_edges=False, show_axes=True |
| 102 | + ) |
| 103 | + min_pressure += step |
| 104 | + |
| 105 | +pl.show_figure(show_axes=True, cpos=c_pos_iso) |
| 106 | + |
| 107 | +############################################################################### |
| 108 | +# Important note |
| 109 | +# ------------------------------ |
| 110 | +# Iso-surfaces computation through the `mesh_cut` operator are only supported for Nodal Fields. |
| 111 | +# For Elemental variables, you must perform an averaging operation on the Nodes before |
| 112 | +# running the `mesh_cut` operator. This can be done by chaining the `elemental_to_nodal` operator |
| 113 | +# output with the `mesh_cut` operator input. |
0 commit comments