Skip to content

Commit 4786dbc

Browse files
anslpaJennaPaikowskyPProfizi
authored
Add "plot streamlines" capabilities (#1036)
* Add "add_streamlines" methods * Add plot streamlines example * field as field only (no list) * Use download files * Correctly compute streamlines field name * Docstring added * filter kwargs * Add time report (to revert) * Update example with better values for elbow * Revert "Add time report (to revert)" This reverts commit 55f8ae1. * Add permissive * Surface streamline example * show_plane argument * Style check * Style check * show_plane replaced by plane * Update docstring plane * Update examples/06-plotting/08_plot_3d_streamlines.py Co-authored-by: JennaPaikowsky <[email protected]> * Update examples/06-plotting/08_plot_3d_streamlines.py Co-authored-by: JennaPaikowsky <[email protected]> * Update examples/06-plotting/08_plot_3d_streamlines.py Co-authored-by: JennaPaikowsky <[email protected]> * Update examples/06-plotting/08_plot_3d_streamlines.py Co-authored-by: JennaPaikowsky <[email protected]> * Update examples/06-plotting/08_plot_3d_streamlines.py Co-authored-by: JennaPaikowsky <[email protected]> * Update examples/06-plotting/09_plot_surface_streamlines.py Co-authored-by: JennaPaikowsky <[email protected]> * Update examples/06-plotting/09_plot_surface_streamlines.py Co-authored-by: JennaPaikowsky <[email protected]> * Update src/ansys/dpf/core/plotter.py Co-authored-by: JennaPaikowsky <[email protected]> * Remove * style check * Helpers: compute streamlines (#1062) * Add helpers * enhance descr * Prepare "compute_streamlines" method and adapt the examples/plot code. Remaining is the implementation. * try pyvista import * protoype working return pv.DataSets and pv.PolyData * fix raising * create helpers module as folder * update src * use translation methods * typo * first tries for creating pvDataSet * Add streamlines and streamlinessource classes * Remove meshed_region and field attributes from add_streamline, update all examples to use "compute_streamline" * replace computed_streamlines and computed_source * update docstring * update docstring and fix computed_streamlines * style check * style check * use pv_data_set * Fix doc * 12 to 13 (examples folder) * Streamlines: add base class for Streamlines and StreamlinesSource objects (#1070) * Implement base class for streamlines object, to prepare the conversion of the _pv_data_set to the _fc * fix faces * style check * style check * style check * Update examples/13-streamlines/README.txt Co-authored-by: Paul Profizi <[email protected]> * fix comment * Set permissive default value to True * Update max_time --------- Co-authored-by: JennaPaikowsky <[email protected]> Co-authored-by: Paul Profizi <[email protected]>
1 parent 1ea13de commit 4786dbc

File tree

8 files changed

+613
-29
lines changed

8 files changed

+613
-29
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
"""
2+
.. _plot_3d_streamlines:
3+
4+
Compute and plot 3D streamlines
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
This example shows you how to compute and
7+
plot streamlines of fluid simulation results,
8+
for 3D models.
9+
10+
"""
11+
12+
###############################################################################
13+
# Compute and plot streamlines from single source
14+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
###############################################################################
17+
# Import modules, create the data sources and the model
18+
# -----------------------------------------------------
19+
# Import modules:
20+
21+
from ansys.dpf import core as dpf
22+
from ansys.dpf.core import examples
23+
from ansys.dpf.core.helpers.streamlines import compute_streamlines
24+
from ansys.dpf.core.plotter import DpfPlotter
25+
26+
###############################################################################
27+
# Create data sources for fluids simulation result:
28+
fluent_files = examples.download_fluent_mixing_elbow_steady_state()
29+
ds_fluent = dpf.DataSources()
30+
ds_fluent.set_result_file_path(fluent_files["cas"][0], "cas")
31+
ds_fluent.add_file_path(fluent_files["dat"][1], "dat")
32+
33+
###############################################################################
34+
# Create model from fluid simulation result data sources:
35+
m_fluent = dpf.Model(ds_fluent)
36+
37+
###############################################################################
38+
# Get meshed region and velocity data
39+
# -----------------------------------
40+
# Meshed region is used as geometric base to compute the streamlines.
41+
# Velocity data is used to compute the streamlines. The velocity data must be nodal.
42+
43+
###############################################################################
44+
# Get the meshed region:
45+
meshed_region = m_fluent.metadata.meshed_region
46+
47+
###############################################################################
48+
# Get the velocity result at nodes:
49+
velocity_op = m_fluent.results.velocity()
50+
fc = velocity_op.outputs.fields_container()
51+
field = dpf.operators.averaging.to_nodal_fc(fields_container=fc).outputs.fields_container()[0]
52+
53+
###############################################################################
54+
# Compute and plot the streamlines adjusting the request
55+
# ------------------------------------------------------
56+
# The following steps show you how to create streamlines using DpfPlotter, with several sets
57+
# of parameters. It demonstrates the issues that can happen and the adjustments that you can make.
58+
59+
###############################################################################
60+
# First, Streamlines and StreamlinesSource objects are created. The
61+
# StreamlinesSource is available using the 'return_source' argument.
62+
# Then, you can correctly set the source coordinates using the
63+
# "source_center" argument that moves the source center, and
64+
# "permissive" option that allows you to display the source even, if the computed
65+
# streamline size is zero. Default value for "permissive" argument is True. If permissive
66+
# is set to False, the "add_streamlines" method throws.
67+
streamline_obj, source_obj = compute_streamlines(
68+
meshed_region=meshed_region,
69+
field=field,
70+
return_source=True,
71+
source_center=(0.1, 0.1, 0.2),
72+
)
73+
pl1 = DpfPlotter()
74+
pl1.add_mesh(meshed_region=meshed_region, opacity=0.3)
75+
pl1.add_streamlines(
76+
streamlines=streamline_obj,
77+
source=source_obj,
78+
permissive=True,
79+
)
80+
pl1.show_figure(show_axes=True)
81+
82+
###############################################################################
83+
# After the adjustment, the correct values for the "source_center" argument are set.
84+
# You can remove the "permissive" option.
85+
# You can display velocity data with a small opacity value to avoid hiding the streamlines.
86+
# More settings are added to adapt the streamlines creation to the geometry and
87+
# the data of the model:
88+
# - radius: streamlines radius
89+
# - n_points: source number of points
90+
# - source_radius
91+
# - max_time: maximum integration time of the streamline. It controls
92+
# the streamline length.
93+
streamline_obj, source_obj = compute_streamlines(
94+
meshed_region=meshed_region,
95+
field=field,
96+
return_source=True,
97+
source_center=(0.56, 0.48, 0.0),
98+
n_points=10,
99+
source_radius=0.075,
100+
max_time=10.0,
101+
)
102+
pl2 = DpfPlotter()
103+
pl2.add_field(field, meshed_region, opacity=0.2)
104+
pl2.add_streamlines(
105+
streamlines=streamline_obj,
106+
source=source_obj,
107+
radius=0.001,
108+
)
109+
pl2.show_figure(show_axes=True)
110+
111+
###############################################################################
112+
# Compute and plot streamlines from several sources
113+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114+
115+
###############################################################################
116+
# Get data to plot
117+
# ----------------
118+
# Create data sources for fluid simulation result:
119+
120+
files_cfx = examples.download_cfx_heating_coil()
121+
ds_cfx = dpf.DataSources()
122+
ds_cfx.set_result_file_path(files_cfx["cas"], "cas")
123+
ds_cfx.add_file_path(files_cfx["dat"], "dat")
124+
125+
###############################################################################
126+
# Create model from fluid simulation result data sources:
127+
m_cfx = dpf.Model(ds_cfx)
128+
129+
###############################################################################
130+
# Get meshed region and velocity data
131+
meshed_region = m_cfx.metadata.meshed_region
132+
velocity_op = m_cfx.results.velocity()
133+
field = velocity_op.outputs.fields_container()[0]
134+
135+
###############################################################################
136+
# Compute streamlines from different sources
137+
# ------------------------------------------
138+
139+
###############################################################################
140+
# Compute streamlines from different sources:
141+
streamline_1, source_1 = compute_streamlines(
142+
meshed_region=meshed_region,
143+
field=field,
144+
return_source=True,
145+
source_radius=0.25,
146+
source_center=(0.75, 0.0, 0.0),
147+
)
148+
streamline_2, source_2 = compute_streamlines(
149+
meshed_region=meshed_region,
150+
field=field,
151+
return_source=True,
152+
source_radius=0.25,
153+
source_center=(0.0, 0.75, 0.0),
154+
)
155+
streamline_3, source_3 = compute_streamlines(
156+
meshed_region=meshed_region,
157+
field=field,
158+
return_source=True,
159+
source_radius=0.25,
160+
source_center=(-0.75, 0.0, 0.0),
161+
)
162+
streamline_4, source_4 = compute_streamlines(
163+
meshed_region=meshed_region,
164+
field=field,
165+
return_source=True,
166+
source_radius=0.25,
167+
source_center=(0.0, -0.75, 0.0),
168+
)
169+
170+
###############################################################################
171+
# Plot streamlines from different sources
172+
# ---------------------------------------
173+
174+
pl = DpfPlotter()
175+
pl.add_field(field, meshed_region, opacity=0.2)
176+
pl.add_streamlines(
177+
streamlines=streamline_1,
178+
source=source_1,
179+
radius=0.007,
180+
)
181+
pl.add_streamlines(
182+
streamlines=streamline_2,
183+
source=source_2,
184+
radius=0.007,
185+
)
186+
pl.add_streamlines(
187+
streamlines=streamline_3,
188+
source=source_3,
189+
radius=0.007,
190+
)
191+
pl.add_streamlines(
192+
streamlines=streamline_4,
193+
source=source_4,
194+
radius=0.007,
195+
)
196+
pl.show_figure(show_axes=True)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"""
2+
.. _plot_surf_streamlines:
3+
4+
Compute and plot 2D streamlines
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
This example shows you how to compute and plot
7+
streamlines of fluid simulation results, for 2D models.
8+
9+
"""
10+
11+
###############################################################################
12+
# Plot surface streamlines
13+
# ~~~~~~~~~~~~~~~~~~~~~~~~
14+
15+
###############################################################################
16+
# Import modules, create the data sources and the model
17+
# -----------------------------------------------------
18+
# Import modules:
19+
20+
from ansys.dpf import core as dpf
21+
from ansys.dpf.core import examples
22+
from ansys.dpf.core.helpers.streamlines import compute_streamlines
23+
from ansys.dpf.core.plotter import DpfPlotter
24+
25+
###############################################################################
26+
# Create data sources for fluids simulation result:
27+
fluent_files = examples.download_fluent_multi_species()
28+
ds_fluent = dpf.DataSources()
29+
ds_fluent.set_result_file_path(fluent_files["cas"], "cas")
30+
ds_fluent.add_file_path(fluent_files["dat"], "dat")
31+
32+
###############################################################################
33+
# Create model from fluid simulation result data sources:
34+
m_fluent = dpf.Model(ds_fluent)
35+
36+
###############################################################################
37+
# Get meshed region and velocity data
38+
# -----------------------------------
39+
# Meshed region is used as the geometric base to compute the streamlines.
40+
# Velocity data is used to compute the streamlines. The velocity data must be nodal.
41+
42+
###############################################################################
43+
# Get the meshed region:
44+
meshed_region = m_fluent.metadata.meshed_region
45+
46+
###############################################################################
47+
# Get the velocity result at nodes:
48+
velocity_op = m_fluent.results.velocity()
49+
fc = velocity_op.outputs.fields_container()
50+
field = dpf.operators.averaging.to_nodal_fc(fields_container=fc).outputs.fields_container()[0]
51+
52+
###############################################################################
53+
# Compute single streamline
54+
# -------------------------
55+
56+
single_2d_streamline, single_2d_source = compute_streamlines(
57+
meshed_region=meshed_region,
58+
field=field,
59+
start_position=(0.005, 0.0005, 0.0),
60+
surface_streamlines=True,
61+
return_source=True,
62+
)
63+
64+
###############################################################################
65+
# Plot single streamline
66+
# ----------------------
67+
68+
pl_single = DpfPlotter()
69+
pl_single.add_field(field, meshed_region, opacity=0.2)
70+
pl_single.add_streamlines(
71+
streamlines=single_2d_streamline,
72+
source=single_2d_source,
73+
radius=0.00002,
74+
)
75+
pl_single.show_figure(show_axes=True)
76+
77+
###############################################################################
78+
# Compute multiple streamlines
79+
# ----------------------------
80+
multiple_2d_streamlines, multiple_2d_source = compute_streamlines(
81+
meshed_region=meshed_region,
82+
field=field,
83+
pointa=(0.005, 0.0001, 0.0),
84+
pointb=(0.005, 0.001, 0.0),
85+
n_points=10,
86+
surface_streamlines=True,
87+
return_source=True,
88+
)
89+
90+
91+
###############################################################################
92+
# Plot multiple streamlines
93+
# -------------------------
94+
95+
pl_multiple = DpfPlotter()
96+
pl_multiple.add_field(field, meshed_region, opacity=0.2)
97+
pl_multiple.add_streamlines(
98+
streamlines=multiple_2d_streamlines,
99+
source=multiple_2d_source,
100+
radius=0.000015,
101+
)
102+
pl_multiple.show_figure(plane="xy", show_axes=True)

examples/13-streamlines/README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _examples_streamlines:
2+
3+
Streamlines examples
4+
====================
5+
These examples show how to compute and plot streamlines.
6+

src/ansys/dpf/core/animator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from typing import Union, Sequence
1010

1111
import ansys.dpf.core as core
12-
from ansys.dpf.core.plotter import _sort_supported_kwargs, _PyVistaPlotter
12+
from ansys.dpf.core.helpers.utils import _sort_supported_kwargs
13+
from ansys.dpf.core.plotter import _PyVistaPlotter
1314

1415

1516
class _InternalAnimatorFactory:

src/ansys/dpf/core/faces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. _ref_faces_apis:
33
44
Faces
5-
========
5+
=====
66
"""
77
import numpy as np
88
from ansys.dpf.core import scoping

0 commit comments

Comments
 (0)