Skip to content

Commit

Permalink
Kecolburn/srt lic (#347)
Browse files Browse the repository at this point in the history
Co-authored-by: Mario Ostieri <[email protected]>
Co-authored-by: Mario Ostieri <[email protected]>
  • Loading branch information
3 people authored Jan 11, 2024
1 parent cca6a1a commit 826ab5e
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 126 deletions.
Binary file added doc/source/_static/05_srt_lic_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/_static/05_srt_lic_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/_static/05_srt_lic_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/_static/05_srt_lic_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
252 changes: 126 additions & 126 deletions doc/source/examples_source/00-basic/04-ptrace_pathline.py
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
"""
.. _ptrace_pathline:
Pathline (transient streamline) Creation
========================================
Utilize EnSight Particle Trace for Pathline (transient streamline).
Create a Pathline and Animate it.
"""

###############################################################################
# Start an EnSight session
# ------------------------
# Launch and connect to an instance of EnSight.
# This example uses a local EnSight installation.
from ansys.pyensight.core import LocalLauncher

session = LocalLauncher().start()

# Setup shortcuts for long winded calls.
eocore = session.ensight.objs.core
eonums = session.ensight.objs.enums
eoutil = session.ensight.utils

###############################################################################
# Load a dataset
# --------------
# Load Flow2D dataset included in the EnSight installation
# set the timestep to the minimum timestep and render.
#
# .. image:: /_static/04_pathline_0.png

session.load_data(f"{session.cei_home}/ensight{session.cei_suffix}/data/flow2d/flow2d.case")
varname = eocore.VARIABLES["VITESSE"][0]
eocore.PARTS.set_attr("COLORBYPALETTE", varname)
session.ensight.objs.core.TIMESTEP = session.ensight.objs.core.TIMESTEP_LIMITS[0]
session.show("image", width=800, height=600)


###############################################################################
# Create a clip plane
# -------------------
# Create a clip through the domain, at X = 0.75.
# We first call up the default clip part, set attributes, and then create the clip
# MESHPLANE sets the type of clip (e.g. X, Y, Z, R, T, Z, etc)
# TOOL sets the tool to create the clip from.
# VALUE is the location of the clip.
# DOMAIN controls intersection vs inside vs outside etc.
# Parent Part is named 'Part by All Elements'
#

clip = eocore.DEFAULTPARTS[session.ensight.PART_CLIP_PLANE]
parent_parts = eocore.PARTS["Part by All Elements"][0]

attrs = []
attrs.append(["MESHPLANE", eonums.MESH_SLICE_X])
attrs.append(["TOOL", eonums.CT_XYZ])
attrs.append(["VALUE", 0.75])
attrs.append(["DOMAIN", eonums.CLIP_DOMAIN_INTER])
clip = clip.createpart(name="X_Clip", sources=[parent_parts], attributes=attrs)


###############################################################################
# Create a Pathline Trace Emitting from the Clip Part
# ---------------------------------------------------------
# Using the 2D parts as the parent (model is 2d), with the "from Part" as the emission type
# "VITESSE" as the vector, and 25 points along the Clip line as emitter locations.
# We also setup to first emit the Pathlines at time = 4 seconds.
# and Emit NEW pathlines ever 20 seconds after that. (They will follow NEW path)
#
# .. image:: /_static/04_pathline_1.png

emitter_part = clip
parent_parts = eoutil.parts.select_parts_by_dimension(2)
npts = 25 # number of emitters
vector_var = varname # Vector variable to use
pathline_part = eoutil.parts.create_particle_trace_from_parts(
"Pathline",
vector_var,
parts=emitter_part,
num_points=npts,
source_parts=parent_parts,
pathlines=True,
emit_time=4.0,
delta_time=20.0,
)
session.show("image", width=800, height=600)


###############################################################################
# Change Visual Attributes
# ----------------------------------------------------------
# Modify the attributes of the pathlines and animate over time
#
# .. image:: /_static/04_pathline_2.png

pathline_part.REPRESENTATION = eonums.TRACE_TUBE
pathline_part.WIDTHSCALEFACTOR = 0.012
session.show("image", width=800, height=600)


###############################################################################
# Animate the Pathlines
# ----------------------------------------------------------
# Turn OFF the pathline lines visibility (to see the animate under)
# Turn ON the animate pathlines.
# Change to Sphere representation, size, and adjust speed and length.
#
# .. video:: ../../_static/04_pathline_3.mp4
# :width: 640
# :height: 360
#

pathline_part.VISIBLE = False
pathline_part.ANIMATE = True
eocore.HEADTYPE = eonums.ATRACE_HEAD_SPHERE
eocore.HEADSCALE = 0.3
session.ensight.solution_time.play_forward()
session.show("animation", width=800, height=600, fps=15)

###############################################################################
# Close the session

# sphinx_gallery_thumbnail_path = '_static/04_pathline_2.png'
session.close()
"""
.. _ptrace_pathline:
Pathline (transient streamline) Creation
========================================
Utilize EnSight Particle Trace for Pathline (transient streamline).
Create a Pathline and Animate it.
"""

###############################################################################
# Start an EnSight session
# ------------------------
# Launch and connect to an instance of EnSight.
# This example uses a local EnSight installation.
from ansys.pyensight.core import LocalLauncher

session = LocalLauncher().start()

# Setup shortcuts for long winded calls.
eocore = session.ensight.objs.core
eonums = session.ensight.objs.enums
eoutil = session.ensight.utils

###############################################################################
# Load a dataset
# --------------
# Load Flow2D dataset included in the EnSight installation
# set the timestep to the minimum timestep and render.
#
# .. image:: /_static/04_pathline_0.png

session.load_data(f"{session.cei_home}/ensight{session.cei_suffix}/data/flow2d/flow2d.case")
varname = eocore.VARIABLES["VITESSE"][0]
eocore.PARTS.set_attr("COLORBYPALETTE", varname)
session.ensight.objs.core.TIMESTEP = session.ensight.objs.core.TIMESTEP_LIMITS[0]
session.show("image", width=800, height=600)


###############################################################################
# Create a clip plane
# -------------------
# Create a clip through the domain, at X = 0.75.
# We first call up the default clip part, set attributes, and then create the clip
# MESHPLANE sets the type of clip (e.g. X, Y, Z, R, T, Z, etc)
# TOOL sets the tool to create the clip from.
# VALUE is the location of the clip.
# DOMAIN controls intersection vs inside vs outside etc.
# Parent Part is named 'Part by All Elements'
#

clip = eocore.DEFAULTPARTS[session.ensight.PART_CLIP_PLANE]
parent_parts = eocore.PARTS["Part by All Elements"][0]

attrs = []
attrs.append(["MESHPLANE", eonums.MESH_SLICE_X])
attrs.append(["TOOL", eonums.CT_XYZ])
attrs.append(["VALUE", 0.75])
attrs.append(["DOMAIN", eonums.CLIP_DOMAIN_INTER])
clip = clip.createpart(name="X_Clip", sources=[parent_parts], attributes=attrs)


###############################################################################
# Create a Pathline Trace Emitting from the Clip Part
# ---------------------------------------------------------
# Using the 2D parts as the parent (model is 2d), with the "from Part" as the emission type
# "VITESSE" as the vector, and 25 points along the Clip line as emitter locations.
# We also setup to first emit the Pathlines at time = 4 seconds.
# and Emit NEW pathlines ever 20 seconds after that. (They will follow NEW path)
#
# .. image:: /_static/04_pathline_1.png

emitter_part = clip
parent_parts = eoutil.parts.select_parts_by_dimension(2)
npts = 25 # number of emitters
vector_var = varname # Vector variable to use
pathline_part = eoutil.parts.create_particle_trace_from_parts(
"Pathline",
vector_var,
parts=emitter_part,
num_points=npts,
source_parts=parent_parts,
pathlines=True,
emit_time=4.0,
delta_time=20.0,
)
session.show("image", width=800, height=600)


###############################################################################
# Change Visual Attributes
# ----------------------------------------------------------
# Modify the attributes of the pathlines and animate over time
#
# .. image:: /_static/04_pathline_2.png

pathline_part.REPRESENTATION = eonums.TRACE_TUBE
pathline_part.WIDTHSCALEFACTOR = 0.012
session.show("image", width=800, height=600)


###############################################################################
# Animate the Pathlines
# ----------------------------------------------------------
# Turn OFF the pathline lines visibility (to see the animate under)
# Turn ON the animate pathlines.
# Change to Sphere representation, size, and adjust speed and length.
#
# .. video:: ../../_static/04_pathline_3.mp4
# :width: 640
# :height: 360
#

pathline_part.VISIBLE = False
pathline_part.ANIMATE = True
eocore.HEADTYPE = eonums.ATRACE_HEAD_SPHERE
eocore.HEADSCALE = 0.3
session.ensight.solution_time.play_forward()
session.show("animation", width=800, height=600, fps=15)

###############################################################################
# Close the session

# sphinx_gallery_thumbnail_path = '_static/04_pathline_2.png'
session.close()
107 changes: 107 additions & 0 deletions doc/source/examples_source/00-basic/05-surface_traces_lic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
.. _surface_traces_lic:
Surface Restricted Traces and Line Integral Convolution
=======================================================
Utilze EnSight to investigate two types of surface streamlines:
Surface Restricted Traces (using Particle Trace)
and LIC (Line Integral Convolution)
Intended to work with EnSight version 24.2 or later
"""

###############################################################################
# Start an EnSight session
# ------------------------
# Launch and connect to an instance of EnSight.
# This example uses a local EnSight installation.
from ansys.pyensight.core import LocalLauncher

session = LocalLauncher().start()

# Setup shortcuts for long winded calls.
eocore = session.ensight.objs.core
eoutil = session.ensight.utils

###############################################################################
# Load a dataset
# --------------
# Load Shuttle Session file included in the EnSight installation and render
#
# .. image:: /_static/05_srt_lic_0.png

session.ensight.objs.ensxml_restore_file(
f"{session.cei_home}/ensight{session.cei_suffix}gui/demos/Shuttle Basic.ens"
)
session.ensight.view.highlight_parts("OFF")
session.ensight.view_transf.fit(0)
session.show("image", width=800, height=600)

###############################################################################
# Option 1. Using Particle Trace to create Surface Restricted Traces
# ------------------------------------------------------------------
# Using a Particle Trace capability
# Parent Part and Emit part are the same part.
# Surface Restriction is ON.

# .. image:: /_static/05_srt_lic_1.png

emitter_part = eoutil.parts.select_parts_by_dimension(2)
parent_parts = emitter_part
npts = 1500 # number of emitters
vector_var = eocore.VARIABLES["Momentum"][0] # Vector variable to use

SRTpart = eoutil.parts.create_particle_trace_from_parts(
"SurfaceRestrictedTrace",
vector_var,
parts=emitter_part,
source_parts=parent_parts,
direction="+/-",
surface_restrict=True,
num_points=npts,
)
session.show("image", width=800, height=600)

###############################################################################
# Change Visual Attributes
# ----------------------------------------------------------
# Modify the attributes of the Surface Restricted Traces to
# be visually closer to Flourescene or Titantiam Dioxide (experimental use)

# .. image:: /_static/05_str_lic_2.png

SRTpart.colorbyrgb = [0, 1, 0]
SRTpart.OPAQUENESS = 0.25
session.show("image", width=800, height=600)

###############################################################################
# Try Line Integral Convolution (LIC) instead
# ----------------------------------------------------------
# As we don't already have a near-surface, non-zero vector defined we need to create 'Offset' Variable.
# Create Offset Variable for Value of Momentum at 2.e-5 distance into fluid domain
# Specify Offset Variable as the variable for LIC.
# Specify High Contrast and 1 length for the LIC
# Specify that we want to see LIC for the Shuttle Surface

# .. image:: /_static/05_srt_lic_3.png

SRTpart.VISIBLE = False
session.ensight.part.select_byname_begin("(CASE:Case 1)Shuttle")
session.ensight.variables.evaluate("OffsetVar = OffsetVar(plist,Momentum,2e-05)")

session.ensight.case.sft_variable("OffsetVar")
session.ensight.case.sft_contrast("ON")
session.ensight.case.sft_norm_length(1.000000)

session.ensight.part.select_byname_begin("(CASE:Case 1)Shuttle")
session.ensight.part.show_sft("ON")
session.show("image", width=800, height=600)

###############################################################################
# Thumbnail
# sphinx_gallery_thumbnail_path = '_static/05_srt_lic_3.png'


session.close()

0 comments on commit 826ab5e

Please sign in to comment.