Skip to content

Commit

Permalink
Suggestions from comments (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
PProfizi committed Mar 8, 2023
1 parent e71f9fb commit ccf38c4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 195 deletions.
11 changes: 6 additions & 5 deletions src/ansys/dpf/post/post_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def load_simulation(
except Exception as e:
warnings.warn(
Warning(
"Physics type is defaulting to 'mechanical'. Specify the physics type",
"keyword if it is invalid.",
"Physics type is defaulting to 'mechanical'. Specify 'simulation_type' "
"keyword if you want to use another type."
)
)
physics_type = _PhysicsType.mechanical
Expand All @@ -175,8 +175,8 @@ def load_simulation(
except Exception as e:
warnings.warn(
Warning(
"Analysis type is defaulting to 'static'. Specify the analysis"
"type keyword if it is invalid."
"Analysis type is set to 'static' as default. Specify the 'simulation_type' "
"keyword if you want to use another type."
)
)
analysis_type = _AnalysisType.static
Expand Down Expand Up @@ -219,7 +219,8 @@ def load_simulation(
else:
raise ValueError(
f"Simulation type '{simulation_type}' is not a recognized simulation type."
f" Please use ansys.dpf.common.AvailableSimulationTypes."
f" Please use ansys.dpf.post.common.AvailableSimulationTypes or instantiate one of the"
f" available Simulation sub-classes directly."
)


Expand Down
16 changes: 9 additions & 7 deletions src/ansys/dpf/post/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, server: Union[BaseServer, None] = None):
self._selection = Workflow(server=self._server)

def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
"""Select time frequency sets by their indices (0 based).
"""Select time frequency sets by their indices (zero-based indexing).
Parameters
----------
Expand All @@ -69,7 +69,7 @@ def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
self.select_time_freq_sets(time_freq_sets)

def select_time_freq_sets(self, time_freq_sets: List[int]) -> None:
"""Select time frequency sets by their cumulative sets (1 based).
"""Select time frequency sets by their cumulative sets (one-based indexing).
Parameters
----------
Expand All @@ -84,7 +84,7 @@ def select_time_freq_sets(self, time_freq_sets: List[int]) -> None:
self._selection.set_output_name(_WfNames.scoping, op.outputs.any)

def select_load_steps(self, load_steps: List[int]) -> None:
"""Select a list of load steps (1 based).
"""Select a list of load steps (one-based indexing).
Parameters
----------
Expand Down Expand Up @@ -117,7 +117,7 @@ def select_with_scoping(self, scoping: Scoping):
def select_time_freq_values(
self, time_freq_values: Union[List[float], ndarray, Field]
) -> None:
"""Select time frequency sets by their values (1 based).
"""Select time frequency sets by their values (one-based indexing).
Parameters
----------
Expand Down Expand Up @@ -473,7 +473,7 @@ def spatial_selection(self, value: SpatialSelection):
self._spatial_selection = value

def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
"""Select time frequency sets by their indices (0 based).
"""Select time frequency sets by their indices (zero-based indexing).
Parameters
----------
Expand All @@ -482,14 +482,16 @@ def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
"""
self._time_freq_selection.select_time_freq_indices(time_freq_indices)

def select_time_freq_sets(self, time_freq_sets: List[int]) -> None:
"""Select time frequency sets by their cumulative sets (1 based).
def select_time_freq_sets(self, time_freq_sets: Union[List[int], int]) -> None:
"""Select time frequency sets by their cumulative sets (one-based indexing).
Parameters
----------
time_freq_sets:
Time/freq sets to select.
"""
if isinstance(time_freq_sets, int):
time_freq_sets = [time_freq_sets]
self._time_freq_selection.select_time_freq_sets(time_freq_sets)

def select_time_freq_values(
Expand Down
40 changes: 22 additions & 18 deletions src/ansys/dpf/post/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ def plot(
the loads, and the boundary conditions currently defined.
Each representation can be deactivated with its respective boolean argument.
Args:
mesh:
Whether to plot the mesh representation.
constructed_geometries:
Whether to plot the constructed geometries.
loads:
Whether to plot the loads.
boundary_conditions:
Whether to plot the boundary conditions.
Parameters
----------
mesh:
Whether to plot the mesh representation.
constructed_geometries:
Whether to plot the constructed geometries.
loads:
Whether to plot the loads.
boundary_conditions:
Whether to plot the boundary conditions.
Returns
-------
Expand All @@ -238,7 +239,7 @@ def plot(
plt.show_figure()

@property
def active_selection(self) -> Selection:
def active_selection(self) -> Union[Selection, None]:
"""Active selection used by default for result queries.
Returns a :object:`ansys.dpf.post.selection.Selection` object.
Expand All @@ -249,13 +250,14 @@ def active_selection(self) -> Selection:
>>> from ansys.dpf.post import examples
>>> simulation = post.load_simulation(examples.static_rst)
>>> selection = post.selection.Selection()
>>> simulation.activate_selection(selection=selection)
>>> simulation.active_selection = selection
>>> print(simulation.active_selection) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
<ansys.dpf.post.selection.Selection object at ...>
"""
return self._active_selection

def activate_selection(self, selection: Selection):
@active_selection.setter
def active_selection(self, selection: Union[Selection, None]):
"""Sets a selection as active on the simulation.
Activating a given selection on a simulation means it is used
Expand All @@ -267,11 +269,14 @@ def activate_selection(self, selection: Selection):
>>> from ansys.dpf.post import examples
>>> simulation = post.load_simulation(examples.static_rst)
>>> selection = post.selection.Selection()
>>> simulation.activate_selection(selection=selection)
>>> simulation.active_selection = selection
>>> print(simulation.active_selection) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
<ansys.dpf.post.selection.Selection object at ...>
"""
self._active_selection = selection
if selection is not None:
self._active_selection = selection
else:
self.deactivate_selection()

def deactivate_selection(self):
"""Deactivate the currently active selection.
Expand All @@ -282,7 +287,7 @@ def deactivate_selection(self):
>>> from ansys.dpf.post import examples
>>> simulation = post.load_simulation(examples.static_rst)
>>> selection = post.selection.Selection()
>>> simulation.activate_selection(selection=selection)
>>> simulation.active_selection = selection
>>> print(simulation.active_selection) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
<ansys.dpf.post.selection.Selection object at ...>
>>> simulation.deactivate_selection()
Expand Down Expand Up @@ -360,7 +365,8 @@ def _build_components(self, base_name, components, component_names):
for comp in components:
if not (isinstance(comp, str) or isinstance(comp, int)):
raise ValueError(
"Argument 'components' can only contain integers and/or strings."
"Argument 'components' can only contain integers and/or strings.\n"
f"The provided component '{comp}' is not valid."
)
if isinstance(comp, int):
comp = str(comp)
Expand Down Expand Up @@ -611,8 +617,6 @@ def _build_selection(
dpf.time_freq_scoping_factory.scoping_on_all_time_freqs(self._model)
)
elif set_ids is not None:
if isinstance(set_ids, int):
set_ids = [set_ids]
selection.select_time_freq_sets(time_freq_sets=set_ids)

elif times is not None:
Expand Down
25 changes: 0 additions & 25 deletions temp/example.py

This file was deleted.

139 changes: 0 additions & 139 deletions temp/meeting.md

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_simulation_named_selections(static_simulation):
def test_simulation_active_selection(static_simulation):
assert static_simulation.active_selection is None
selection = post.selection.Selection()
static_simulation.activate_selection(selection=selection)
static_simulation.active_selection = selection
assert static_simulation.active_selection == selection
static_simulation.deactivate_selection()
assert static_simulation.active_selection is None
Expand Down

0 comments on commit ccf38c4

Please sign in to comment.