Skip to content

Commit

Permalink
Merge branch 'maint/update24r2_docker' of https://github.com/ansys/py…
Browse files Browse the repository at this point in the history
…mechanical into maint/update24r2_docker
  • Loading branch information
dipinknair committed Jul 14, 2024
2 parents f60272a + 427f2cd commit c580b81
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/812.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix exception when plotting a model with any line bodies
1 change: 1 addition & 0 deletions doc/changelog.d/814.dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAINT: Update dev version of pymechanical
1 change: 1 addition & 0 deletions doc/changelog.d/815.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update ACT API Reference Guide link
2 changes: 1 addition & 1 deletion doc/source/links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
.. _Mechanical Users Guide: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/%%VERSION%%/en/wb_sim/ds_Home.html
.. _Chapter 6: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/%%VERSION%%/en/installation/unix_silent.html
.. _Chapter 7: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/%%VERSION%%/en/installation/win_silent.html
.. _ACT API Reference Guide: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/%%VERSION%%/en/act_ref/act_ref.html
.. _ACT API Reference Guide: https://developer.ansys.com/docs/mechanical-scripting-interface/api/ansys/mechanical/stubs/%%VERSION%%/index.md
1 change: 0 additions & 1 deletion docker/232/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ RUN apt-get update && apt-get install -y \
tini \
ca-certificates \
libgomp1 \
libgomp1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
[project]
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
name = "ansys-mechanical-core"
version = "0.11.dev0"
version = "0.12.dev0"
description = "A python wrapper for Ansys Mechanical"
readme = "README.rst"
requires-python = ">=3.9,<4.0"
Expand Down Expand Up @@ -69,7 +69,7 @@ doc = [
"pypandoc==1.13",
"pytest-sphinx==0.6.3",
"pythreejs==2.4.2",
"pyvista==0.44.0",
"pyvista>=0.39.1",
"sphinx-autobuild==2024.4.16",
"sphinx-autodoc-typehints==2.2.2",
"sphinx-copybutton==0.5.2",
Expand Down
17 changes: 16 additions & 1 deletion src/ansys/mechanical/core/embedding/viz/pyvista_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _transform_to_pyvista(transform: "Ansys.ACT.Math.Matrix4D"):
return np_transform


def _get_nodes_and_coords(tri_tessellation: "Ansys.Mechanical.Scenegraph.TriTessellationNode"):
def _get_tri_nodes_and_coords(tri_tessellation: "Ansys.Mechanical.Scenegraph.TriTessellationNode"):
"""Get the nodes and indices of the TriTessellationNode.
pyvista format expects a number of vertices per facet which is always 3
Expand All @@ -55,6 +55,19 @@ def _get_nodes_and_coords(tri_tessellation: "Ansys.Mechanical.Scenegraph.TriTess
return np_coordinates, np_indices


def _get_nodes_and_coords(node: "Ansys.Mechanical.Scenegraph.Node"):
"""Get the nodes and indices of the Scenegraph node.
Currently only supported for tri tessellation nodes
"""
if isinstance(node, Ansys.Mechanical.Scenegraph.TriTessellationNode):
return _get_tri_nodes_and_coords(node)

# TODO - support line tessellation node. See issue #809
# if isinstance(node, Ansys.Mechanical.Scenegraph.LineTessellationNode):
return None, None


def to_pyvista_plotter(app: "ansys.mechanical.core.embedding.App"):
"""Convert the app's geometry to a pyvista plotter instance."""
plotter = pv.Plotter()
Expand All @@ -63,6 +76,8 @@ def to_pyvista_plotter(app: "ansys.mechanical.core.embedding.App"):
):
scenegraph_node = Ansys.ACT.Mechanical.Tools.ScenegraphHelpers.GetScenegraph(body)
np_coordinates, np_indices = _get_nodes_and_coords(scenegraph_node.Child)
if np_coordinates is None or np_indices is None:
continue
pv_transform = _transform_to_pyvista(scenegraph_node.Transform)
polydata = pv.PolyData(np_coordinates, np_indices).transform(pv_transform)
color = pv.Color(bgr_to_rgb_tuple(body.Color))
Expand Down
26 changes: 18 additions & 8 deletions src/ansys/mechanical/core/embedding/viz/usd_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,32 @@ def _convert_tri_tessellation_node(
return mesh_prim


def _convert_transform_node(
node: "Ansys.Mechanical.Scenegraph.TransformNode",
stage: Usd.Stage,
path: str,
rgb: typing.Tuple[int, int, int],
def _create_prim_with_transform(
stage: Usd.Stage, path: str, node: "Ansys.Mechanical.Scenegraph.TransformNode"
) -> Usd.Prim:
"""Convert a mechanical transform node into a Usd Xform prim."""
"""Create an empty Usd Xform prim based on a mechanical transform node."""
prim = UsdGeom.Xform.Define(stage, path)
rotation, translation = _transform_to_rotation_translation(node.Transform)
prim.AddOrientOp().Set(rotation)
prim.AddTranslateOp().Set(translation)
return prim


def _convert_transform_node(
node: "Ansys.Mechanical.Scenegraph.TransformNode",
stage: Usd.Stage,
path: str,
rgb: typing.Tuple[int, int, int],
) -> None:
"""Add a Usd prim to the stage based on the given mechanical transform node.
Currently only supports transforms that contain a single tri tessellation node.
"""
child_node = node.Child
child_path = prim.GetPath().AppendPath("TriTessellation")
if isinstance(child_node, Ansys.Mechanical.Scenegraph.TriTessellationNode):
prim = _create_prim_with_transform(stage, path, node)
child_path = prim.GetPath().AppendPath("TriTessellation")
_convert_tri_tessellation_node(child_node, stage, child_path, rgb)
return prim


def to_usd_stage(app: "ansys.mechanical.core.embedding.App", name: str) -> None:
Expand Down

0 comments on commit c580b81

Please sign in to comment.