Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/sphinx-7.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
PProfizi authored Oct 11, 2023
2 parents b02f475 + 7675dc6 commit 2b7f00d
Show file tree
Hide file tree
Showing 23 changed files with 348 additions and 87 deletions.
39 changes: 39 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""This runs at the init of the doctest pytest session."""
import doctest
from doctest import DocTestRunner
from unittest import mock

from ansys.dpf.core.misc import module_exists
import pytest

from ansys.dpf import core

# enable matplotlib off_screen plotting to avoid test interruption

if module_exists("matplotlib"):
import matplotlib as mpl

mpl.use("Agg")


# enable off_screen plotting to avoid test interruption
core.settings.disable_off_screen_rendering()
core.settings.bypass_pv_opengl_osmesa_crash()


class _DPFDocTestRunner(DocTestRunner):
def run(self, test, compileflags=None, out=None, clear_globs=True):
try:
return DocTestRunner.run(self, test, compileflags, out, clear_globs)
except doctest.UnexpectedException as e:
feature_str = "Feature not supported. Upgrade the server to"
if feature_str in str(e.exc_info):
pass
else:
raise e


@pytest.fixture(autouse=True)
def _doctest_runner_dpf():
with mock.patch("doctest.DocTestRunner", _DPFDocTestRunner):
yield
13 changes: 12 additions & 1 deletion docs/.vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ BasedOnStyles = Vale, Google

# Removing Google-specific rule - Not applicable under some circumstances
Google.WordList = NO
Google.Colons = NO
Google.Colons = NO

[formats]
# Format associations appear under
# the optional "formats" section.

[*]
# Format-specific settings appear
# under a user-provided "glob"
# pattern.
TokenIgnores = (:.*:\x60.*\x60)

1 change: 1 addition & 0 deletions src/ansys/dpf/post/dpf_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def get_result_info(self):
- co_energy: Elemental co-energy
- incremental_energy: Elemental incremental energy
- elastic_strain: ElementalNodal Strain
- element_euler_angles: ElementalNodal Element Euler Angles
- structural_temperature: ElementalNodal Structural temperature
"""
return self._model.metadata.result_info
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/post/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Examples
--------
This module module exposes PyDPF-Core functionalities.
This package exposes PyDPF-Core functionalities.
See `here <https://dpf.docs.pyansys.com/dev/api/ansys.dpf.core.examples.html>`_
for a description of the PyDPF-Core ``example`` API.
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/dpf/post/harmonic_mechanical_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ def _get_result(
)
for i_field in range(len(fc)):
bind_support_op = dpf.operators.utility.bind_support(
fc[i_field], submesh
fc[i_field],
submesh,
server=fc._server,
)
fc.add_field(fc.get_label_space(i_field), bind_support_op.eval())

Expand Down
6 changes: 6 additions & 0 deletions src/ansys/dpf/post/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Tools package.
Tools
-----
This package regroups helpers for different common post-treatment functionalities.
"""
42 changes: 42 additions & 0 deletions src/ansys/dpf/post/helpers/selections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Module containing helpers to build selections.
Selections
----------
"""
from ansys.dpf.post import selection


def select(
time_freq_indexes=None,
time_freq_sets=None,
time_freq_values=None,
named_selection_names=None,
**kwargs,
):
"""Creates a ``Selection`` instance allowing to choose the domain on which to evaluate results.
The results domain defines the time frequency and the spatial selection.
Parameters
----------
time_freq_indexes:
Time/freq indexes to select.
time_freq_sets:
Time/freq sets to select.
time_freq_values:
Time/freq values to select.
named_selection_names:
Time/freq named selection to select.
"""
current_selection = selection.Selection()
if time_freq_indexes:
current_selection.select_time_freq_indexes(time_freq_indexes)
if time_freq_sets:
current_selection.select_time_freq_sets(time_freq_sets)
if time_freq_values:
current_selection.select_time_freq_values(time_freq_values)
if named_selection_names:
current_selection.select_named_selection(named_selection_names)
return current_selection
92 changes: 92 additions & 0 deletions src/ansys/dpf/post/helpers/streamlines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""Module containing the helpers for streamlines.
Streamlines
-----------
"""
from typing import List, Union

from ansys.dpf.core.helpers import streamlines as core_streamlines
from ansys.dpf.core.plotter import DpfPlotter

from ansys.dpf import core as dpf
from ansys.dpf import post


def plot_streamlines(
dataframe: post.DataFrame,
sources: List[dict],
set_id: int = 1,
streamline_thickness: Union[float, List[float]] = 0.01,
plot_mesh: bool = True,
mesh_opacity: float = 0.3,
plot_contour: bool = True,
contour_opacity: float = 0.3,
**kwargs,
):
"""Plot streamlines based on a vector field DataFrame.
Parameters
----------
dataframe:
A `post.DataFrame` object containing a vector field.
If present, merges the `DataFrame` across its `zone` label before plotting.
sources:
A list of dictionaries defining spherical point sources for the streamlines.
Expected keywords are "center", "radius", "max_time" and "n_points".
Keyword "max_time" is for the maximum integration pseudo-time for the streamline
computation algorithm, which defines the final length of the lines.
More information is available at :func:`pyvista.DataSetFilters.streamlines`.
set_id:
ID of the set (time-step) for which to compute streamlines if the `DataFrame` object
contains temporal data.
streamline_thickness:
Thickness of the streamlines plotted. Use a list to specify a value for each source.
plot_contour:
Whether to plot the field's norm contour along with the streamlines.
contour_opacity:
Opacity to use for the field contour in case "plot_contour=True".
plot_mesh:
Whether to plot the mesh along the streamlines in case "plot_contour=False".
mesh_opacity:
Opacity to use for the mesh in case "plot_contour=False" and "plot_mesh=True".
**kwargs:
"""
# Select data to work with
fc = dataframe._fc
if "zone" in dataframe.columns.names:
fc = dpf.operators.utility.merge_fields_by_label(
fields_container=fc,
label="zone",
).outputs.fields_container()
if set_id not in dataframe.columns.set_index.values:
raise ValueError("The set_id requested is not available in this dataframe.")
field = fc.get_field_by_time_id(timeid=set_id)
meshed_region = field.meshed_region

# Initialize the plotter
plt = DpfPlotter(**kwargs)

if plot_contour:
plt.add_field(field=field, opacity=contour_opacity)
elif plot_mesh:
plt.add_mesh(meshed_region=meshed_region, opacity=mesh_opacity)
if not isinstance(streamline_thickness, list):
streamline_thickness = [streamline_thickness] * len(sources)
# Add streamlines for each source
for i, source in enumerate(sources):
pv_streamline, pv_source = core_streamlines.compute_streamlines(
meshed_region=meshed_region,
field=field,
return_source=True,
source_radius=source["radius"],
source_center=source["center"],
n_points=source["n_points"] if "n_points" in source else 100,
max_time=source["max_time"] if "max_time" in source else None,
)
plt.add_streamlines(
pv_streamline, source=pv_source, radius=streamline_thickness[i]
)

plt.show_figure(**kwargs)
12 changes: 10 additions & 2 deletions src/ansys/dpf/post/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,20 +379,28 @@ def names(self):

@property
def results_index(self) -> Union[ResultsIndex, None]:
"""Returns the available ResultsIndex is present."""
"""Returns the available ResultsIndex if present."""
for index in self._indexes:
if isinstance(index, ResultsIndex):
return index
return None

@property
def mesh_index(self) -> Union[MeshIndex, None]:
"""Returns the available ResultsIndex is present."""
"""Returns the available ResultsIndex if present."""
for index in self._indexes:
if isinstance(index, MeshIndex):
return index
return None

@property
def set_index(self) -> Union[SetIndex, None]:
"""Returns the available SetIndex if present."""
for index in self._indexes:
if isinstance(index, SetIndex):
return index
return None

# @property
# def label_names(self):
# """Returns a list with the name of each label Index."""
Expand Down
7 changes: 5 additions & 2 deletions src/ansys/dpf/post/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ def _generate_disp_workflow(self, fc, selection) -> Union[dpf.Workflow, None]:
merge_op = dpf.operators.utility.merge_fields_by_label(
fields_container=shell_layer_op.outputs.fields_container_as_fields_container,
label="eltype",
server=fc._server,
)

# Expose output
Expand All @@ -643,7 +644,9 @@ def _create_dataframe(
if submesh is not None:
for i_field in range(len(fc)):
bind_support_op = dpf.operators.utility.bind_support(
fc[i_field], submesh
fc[i_field],
submesh,
server=fc._server,
)
fc.add_field(fc.get_label_space(i_field), bind_support_op.eval())
if unit == "":
Expand Down Expand Up @@ -811,7 +814,7 @@ def _build_selection(
node_ids: Union[List[int], None] = None,
location: Union[locations, str] = locations.nodal,
external_layer: bool = False,
skin: Union[bool] = False,
skin: Union[bool, List[int]] = False,
expand_cyclic: Union[bool, List[Union[int, List[int]]]] = True,
) -> Selection:
tot = (
Expand Down
44 changes: 4 additions & 40 deletions src/ansys/dpf/post/tools.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,11 @@
"""This module holds factories to create geometry, selections...
"""This module holds a deprecated link to the legacy `ansys.dpf.post.tools.select` method.
tools
=====
These factories help creating Objects used to defined which results are evaluated.
This module has been replaced by the `helpers` sub-package.
Please use `ansys.dpf.post.helpers.selections.select` instead.
"""

from ansys.dpf.post import selection

# from ansys.dpf.core.geometry_factory import *


def select(
time_freq_indexes=None,
time_freq_sets=None,
time_freq_values=None,
named_selection_names=None,
**kwargs,
):
"""Creates a ``Selection`` instance allowing to choose the domain on which to evaluate results.
The results domain defines the time frequency and the spatial selection.
Parameters
----------
time_freq_indexes:
Time/freq indexes to select.
time_freq_sets:
Time/freq sets to select.
time_freq_values:
Time/freq values to select.
named_selection_names:
Time/freq named selection to select.
"""
current_selection = selection.Selection()
if time_freq_indexes:
current_selection.select_time_freq_indexes(time_freq_indexes)
if time_freq_sets:
current_selection.select_time_freq_sets(time_freq_sets)
if time_freq_values:
current_selection.select_time_freq_values(time_freq_values)
if named_selection_names:
current_selection.select_named_selection(named_selection_names)
return current_selection
from ansys.dpf.post.helpers.selections import select # noqa: F401
2 changes: 1 addition & 1 deletion tests/test_dataframe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ansys.dpf.core as core
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0
import numpy as np
import pytest
from pytest import fixture
Expand All @@ -17,6 +16,7 @@
from ansys.dpf.post.modal_mechanical_simulation import ModalMechanicalSimulation
from ansys.dpf.post.static_mechanical_simulation import StaticMechanicalSimulation
from ansys.dpf.post.transient_mechanical_simulation import TransientMechanicalSimulation
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0


@fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_faces.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from ansys.dpf.core import examples
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0
import pytest
from pytest import fixture

from ansys.dpf import core as dpf
from ansys.dpf import post
from ansys.dpf.post.faces import Face, FaceListById, FaceListByIndex
from ansys.dpf.post.nodes import NodeListByIndex
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0


@pytest.mark.skipif(
Expand Down
Loading

0 comments on commit 2b7f00d

Please sign in to comment.