Skip to content

Commit ccf38c4

Browse files
committed
Suggestions from comments (#313)
1 parent e71f9fb commit ccf38c4

File tree

6 files changed

+38
-195
lines changed

6 files changed

+38
-195
lines changed

src/ansys/dpf/post/post_utility.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def load_simulation(
165165
except Exception as e:
166166
warnings.warn(
167167
Warning(
168-
"Physics type is defaulting to 'mechanical'. Specify the physics type",
169-
"keyword if it is invalid.",
168+
"Physics type is defaulting to 'mechanical'. Specify 'simulation_type' "
169+
"keyword if you want to use another type."
170170
)
171171
)
172172
physics_type = _PhysicsType.mechanical
@@ -175,8 +175,8 @@ def load_simulation(
175175
except Exception as e:
176176
warnings.warn(
177177
Warning(
178-
"Analysis type is defaulting to 'static'. Specify the analysis"
179-
"type keyword if it is invalid."
178+
"Analysis type is set to 'static' as default. Specify the 'simulation_type' "
179+
"keyword if you want to use another type."
180180
)
181181
)
182182
analysis_type = _AnalysisType.static
@@ -219,7 +219,8 @@ def load_simulation(
219219
else:
220220
raise ValueError(
221221
f"Simulation type '{simulation_type}' is not a recognized simulation type."
222-
f" Please use ansys.dpf.common.AvailableSimulationTypes."
222+
f" Please use ansys.dpf.post.common.AvailableSimulationTypes or instantiate one of the"
223+
f" available Simulation sub-classes directly."
223224
)
224225

225226

src/ansys/dpf/post/selection.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, server: Union[BaseServer, None] = None):
5858
self._selection = Workflow(server=self._server)
5959

6060
def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
61-
"""Select time frequency sets by their indices (0 based).
61+
"""Select time frequency sets by their indices (zero-based indexing).
6262
6363
Parameters
6464
----------
@@ -69,7 +69,7 @@ def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
6969
self.select_time_freq_sets(time_freq_sets)
7070

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

8686
def select_load_steps(self, load_steps: List[int]) -> None:
87-
"""Select a list of load steps (1 based).
87+
"""Select a list of load steps (one-based indexing).
8888
8989
Parameters
9090
----------
@@ -117,7 +117,7 @@ def select_with_scoping(self, scoping: Scoping):
117117
def select_time_freq_values(
118118
self, time_freq_values: Union[List[float], ndarray, Field]
119119
) -> None:
120-
"""Select time frequency sets by their values (1 based).
120+
"""Select time frequency sets by their values (one-based indexing).
121121
122122
Parameters
123123
----------
@@ -473,7 +473,7 @@ def spatial_selection(self, value: SpatialSelection):
473473
self._spatial_selection = value
474474

475475
def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
476-
"""Select time frequency sets by their indices (0 based).
476+
"""Select time frequency sets by their indices (zero-based indexing).
477477
478478
Parameters
479479
----------
@@ -482,14 +482,16 @@ def select_time_freq_indices(self, time_freq_indices: List[int]) -> None:
482482
"""
483483
self._time_freq_selection.select_time_freq_indices(time_freq_indices)
484484

485-
def select_time_freq_sets(self, time_freq_sets: List[int]) -> None:
486-
"""Select time frequency sets by their cumulative sets (1 based).
485+
def select_time_freq_sets(self, time_freq_sets: Union[List[int], int]) -> None:
486+
"""Select time frequency sets by their cumulative sets (one-based indexing).
487487
488488
Parameters
489489
----------
490490
time_freq_sets:
491491
Time/freq sets to select.
492492
"""
493+
if isinstance(time_freq_sets, int):
494+
time_freq_sets = [time_freq_sets]
493495
self._time_freq_selection.select_time_freq_sets(time_freq_sets)
494496

495497
def select_time_freq_values(

src/ansys/dpf/post/simulation.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,16 @@ def plot(
204204
the loads, and the boundary conditions currently defined.
205205
Each representation can be deactivated with its respective boolean argument.
206206
207-
Args:
208-
mesh:
209-
Whether to plot the mesh representation.
210-
constructed_geometries:
211-
Whether to plot the constructed geometries.
212-
loads:
213-
Whether to plot the loads.
214-
boundary_conditions:
215-
Whether to plot the boundary conditions.
207+
Parameters
208+
----------
209+
mesh:
210+
Whether to plot the mesh representation.
211+
constructed_geometries:
212+
Whether to plot the constructed geometries.
213+
loads:
214+
Whether to plot the loads.
215+
boundary_conditions:
216+
Whether to plot the boundary conditions.
216217
217218
Returns
218219
-------
@@ -238,7 +239,7 @@ def plot(
238239
plt.show_figure()
239240

240241
@property
241-
def active_selection(self) -> Selection:
242+
def active_selection(self) -> Union[Selection, None]:
242243
"""Active selection used by default for result queries.
243244
244245
Returns a :object:`ansys.dpf.post.selection.Selection` object.
@@ -249,13 +250,14 @@ def active_selection(self) -> Selection:
249250
>>> from ansys.dpf.post import examples
250251
>>> simulation = post.load_simulation(examples.static_rst)
251252
>>> selection = post.selection.Selection()
252-
>>> simulation.activate_selection(selection=selection)
253+
>>> simulation.active_selection = selection
253254
>>> print(simulation.active_selection) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
254255
<ansys.dpf.post.selection.Selection object at ...>
255256
"""
256257
return self._active_selection
257258

258-
def activate_selection(self, selection: Selection):
259+
@active_selection.setter
260+
def active_selection(self, selection: Union[Selection, None]):
259261
"""Sets a selection as active on the simulation.
260262
261263
Activating a given selection on a simulation means it is used
@@ -267,11 +269,14 @@ def activate_selection(self, selection: Selection):
267269
>>> from ansys.dpf.post import examples
268270
>>> simulation = post.load_simulation(examples.static_rst)
269271
>>> selection = post.selection.Selection()
270-
>>> simulation.activate_selection(selection=selection)
272+
>>> simulation.active_selection = selection
271273
>>> print(simulation.active_selection) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
272274
<ansys.dpf.post.selection.Selection object at ...>
273275
"""
274-
self._active_selection = selection
276+
if selection is not None:
277+
self._active_selection = selection
278+
else:
279+
self.deactivate_selection()
275280

276281
def deactivate_selection(self):
277282
"""Deactivate the currently active selection.
@@ -282,7 +287,7 @@ def deactivate_selection(self):
282287
>>> from ansys.dpf.post import examples
283288
>>> simulation = post.load_simulation(examples.static_rst)
284289
>>> selection = post.selection.Selection()
285-
>>> simulation.activate_selection(selection=selection)
290+
>>> simulation.active_selection = selection
286291
>>> print(simulation.active_selection) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
287292
<ansys.dpf.post.selection.Selection object at ...>
288293
>>> simulation.deactivate_selection()
@@ -360,7 +365,8 @@ def _build_components(self, base_name, components, component_names):
360365
for comp in components:
361366
if not (isinstance(comp, str) or isinstance(comp, int)):
362367
raise ValueError(
363-
"Argument 'components' can only contain integers and/or strings."
368+
"Argument 'components' can only contain integers and/or strings.\n"
369+
f"The provided component '{comp}' is not valid."
364370
)
365371
if isinstance(comp, int):
366372
comp = str(comp)
@@ -611,8 +617,6 @@ def _build_selection(
611617
dpf.time_freq_scoping_factory.scoping_on_all_time_freqs(self._model)
612618
)
613619
elif set_ids is not None:
614-
if isinstance(set_ids, int):
615-
set_ids = [set_ids]
616620
selection.select_time_freq_sets(time_freq_sets=set_ids)
617621

618622
elif times is not None:

temp/example.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

temp/meeting.md

Lines changed: 0 additions & 139 deletions
This file was deleted.

tests/test_simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_simulation_named_selections(static_simulation):
6464
def test_simulation_active_selection(static_simulation):
6565
assert static_simulation.active_selection is None
6666
selection = post.selection.Selection()
67-
static_simulation.activate_selection(selection=selection)
67+
static_simulation.active_selection = selection
6868
assert static_simulation.active_selection == selection
6969
static_simulation.deactivate_selection()
7070
assert static_simulation.active_selection is None

0 commit comments

Comments
 (0)