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