|
| 1 | +""" |
| 2 | +.. _ptrace_basic_example: |
| 3 | +
|
| 4 | +Particle Trace (Streamline/Pathline) usage |
| 5 | +========================================== |
| 6 | +
|
| 7 | +Utilze EnSight Particle Trace (aka Streamline/Pathline to visualize a |
| 8 | +vector through the domain.) |
| 9 | +Create Streamline, animate, allow for dynamic change. |
| 10 | +
|
| 11 | +""" |
| 12 | + |
| 13 | +############################################################################### |
| 14 | +# Start an EnSight session |
| 15 | +# ------------------------ |
| 16 | +# Launch and connect to an instance of EnSight. |
| 17 | +# This example uses a local EnSight installation. |
| 18 | +from ansys.pyensight.core import LocalLauncher |
| 19 | + |
| 20 | +ansys_loc = r"""C:\Program Files\ANSYS Inc\v242""" |
| 21 | + |
| 22 | +session = LocalLauncher(ansys_installation=ansys_loc).start() |
| 23 | +# Setup shortcuts for long winded calls. |
| 24 | +eocore = session.ensight.objs.core |
| 25 | +eonums = session.ensight.objs.enums |
| 26 | +eoutil = session.ensight.utils |
| 27 | + |
| 28 | +############################################################################### |
| 29 | +# Load a dataset |
| 30 | +# -------------- |
| 31 | +# Load Shuttle data included in the EnSight installation and render |
| 32 | +# |
| 33 | +# .. image:: /_static/03_ptrace_0.png |
| 34 | + |
| 35 | +xyz_file = f"{session.cei_home}/ensight{session.cei_suffix}/data/plot3d/shuttle.xyz" |
| 36 | +q_file = f"{session.cei_home}/ensight{session.cei_suffix}/data/plot3d/shuttle.q" |
| 37 | +session.load_data( |
| 38 | + data_file=xyz_file, |
| 39 | + result_file=q_file, |
| 40 | + file_format="PLOT3D", |
| 41 | + representation="3D_feature_2D_full", |
| 42 | +) |
| 43 | +session.show("image", width=800, height=600) |
| 44 | + |
| 45 | +############################################################################### |
| 46 | +# The PLOT3D reader only reads the volume by default. Now, extract a |
| 47 | +# particular IJK range for the surface of the shuttle |
| 48 | +# ------------------------------------------------------------------ |
| 49 | +# |
| 50 | + |
| 51 | +session.ensight.data_partbuild.begin() |
| 52 | +session.ensight.case.select("Case 1") |
| 53 | +session.ensight.data_partbuild.data_type("structured") |
| 54 | +session.ensight.data_partbuild.group("OFF") |
| 55 | +session.ensight.data_partbuild.select_begin(1) |
| 56 | +session.ensight.data_partbuild.domain("all") |
| 57 | +session.ensight.data_partbuild.noderange_i(1, 53) |
| 58 | +session.ensight.data_partbuild.noderange_j(1, 63) |
| 59 | +session.ensight.data_partbuild.noderange_k(1, 1) |
| 60 | +session.ensight.data_partbuild.nodestep(1, 1, 1) |
| 61 | +session.ensight.data_partbuild.nodedelta(0, 0, 0) |
| 62 | +session.ensight.data_partbuild.description("Shuttle") |
| 63 | +session.ensight.data_partbuild.create() |
| 64 | +session.ensight.part.select_byname_begin("(CASE:Case 1)Shuttle") |
| 65 | +session.ensight.case.select("Case 1") |
| 66 | +session.ensight.data_partbuild.end() |
| 67 | + |
| 68 | + |
| 69 | +############################################################################### |
| 70 | +# Setup the View |
| 71 | +# ---------------------------------- |
| 72 | +# Set View, Turn on Symmetry, turn off visibility of flow domain. |
| 73 | + |
| 74 | +session.ensight.view_transf.rotate(-109.084335, -1.64276719, 0) |
| 75 | +session.ensight.view_transf.rotate(-2.38553524, 115.462845, 0) |
| 76 | +session.ensight.view_transf.zoom(0.489253074) |
| 77 | +session.ensight.view_transf.look_at(2.4110589, 0.567389309, 0.241451085) |
| 78 | +session.ensight.view_transf.look_from(2.4110589, 0.567389309, 5.69335651) |
| 79 | + |
| 80 | +session.ensight.part.select_all() |
| 81 | +session.ensight.part.modify_begin() |
| 82 | +session.ensight.part.symmetry_type("mirror") |
| 83 | +session.ensight.part.symmetry_mirror_y("ON") |
| 84 | +session.ensight.part.modify_end() |
| 85 | + |
| 86 | +session.ensight.part.select_begin(1) |
| 87 | +session.ensight.part.modify_begin() |
| 88 | +session.ensight.part.visible("OFF") |
| 89 | +session.ensight.part.modify_end() |
| 90 | + |
| 91 | +############################################################################### |
| 92 | +# Create a Particle Trace using the Line Tool Specification |
| 93 | +# --------------------------------------------------------- |
| 94 | +# Using the 3D parts as the parent, with the line tool as the emission type |
| 95 | +# "Momentum" as the vector, and 50 points alone the line as emitter locations. |
| 96 | + |
| 97 | +# .. image:: /_static/03_ptrace_1.png |
| 98 | + |
| 99 | +pt1 = [0.1245, 0.064366, -0.03438] |
| 100 | +pt2 = [1.0018, 0.399756, -0.03258] |
| 101 | +parent_parts = eoutil.parts.select_parts_by_dimension(3) |
| 102 | +npts = 50 # number of emitters |
| 103 | +vector_var = eocore.VARIABLES["Momentum"][0] # Vector variable to use |
| 104 | +strpart = eoutil.parts.create_particle_trace_from_line( |
| 105 | + "Streamline", |
| 106 | + vector_var, |
| 107 | + point1=pt1, |
| 108 | + point2=pt2, |
| 109 | + num_points=npts, |
| 110 | + source_parts=parent_parts, |
| 111 | + direction="+/-", |
| 112 | +) |
| 113 | +session.show("image", width=800, height=600) |
| 114 | + |
| 115 | +############################################################################### |
| 116 | +# Change Visual Attributes |
| 117 | +# ---------------------------------------------------------- |
| 118 | +# Modify the attributes of the Streamline for visual clarity |
| 119 | + |
| 120 | +# .. image:: /_static/03_ptrace_2.png |
| 121 | + |
| 122 | +strpart.REPRESENTATION = eonums.TRACE_TUBE |
| 123 | +strpart.WIDTHSCALEFACTOR = 0.012 |
| 124 | +strpart.COLORBYPALETTE = "Momentum" |
| 125 | +session.show("image", width=800, height=600) |
| 126 | + |
| 127 | +############################################################################### |
| 128 | +# Animate the Streamlines |
| 129 | +# ---------------------------------------------------------- |
| 130 | +# Turn OFF the streamlines (to see the animate under) |
| 131 | +# Turn ON the animate streamlines. |
| 132 | +# Change to Sphere representation, size, and adjust speed and length. |
| 133 | + |
| 134 | +# .. image:: /_static/03_ptrace_3.png |
| 135 | + |
| 136 | +strpart.VISIBLE = False |
| 137 | +strpart.ANIMATE = True |
| 138 | +eocore.HEADTYPE = eonums.ATRACE_HEAD_SPHERE |
| 139 | +eocore.HEADSCALE = 0.03 |
| 140 | +eocore.PARTICLETIME = 2.0 |
| 141 | +eocore.DELTATIME = 0.065 |
| 142 | +eocore.MULTIPLEPULSES = True |
| 143 | +session.show("image", width=800, height=600) |
| 144 | + |
| 145 | +############################################################################### |
| 146 | +# Thumbnail |
| 147 | +# sphinx_gallery_thumbnail_path = '_static/03_ptrace_2.png' |
| 148 | + |
| 149 | + |
| 150 | +session.close() |
0 commit comments