Skip to content

Commit 4a617bb

Browse files
authored
Scoping on all times (#151)
1 parent 259a878 commit 4a617bb

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

ansys/dpf/core/mesh_scoping_factory.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ def nodal_scoping(node_ids, server=None):
1414
1515
Parameters
1616
----------
17-
node_ids : List of int
17+
node_ids : list[int]
1818
List of IDs for the nodes.
19-
server : ansys.dpf.core.server, optional
19+
server : DpfServer, optional
2020
Server with the channel connected to the remote or local instance.
2121
The default is ``None``, in which case an attempt is made to use the
2222
global server.
2323
2424
Returns
2525
-------
26-
scoping : ansys.dpf.core.Scoping
26+
scoping : Scoping
2727
"""
2828
scoping = Scoping(server=server, ids=node_ids, location=locations.nodal)
2929
return scoping
@@ -34,16 +34,16 @@ def elemental_scoping(element_ids, server=None):
3434
3535
Parameters
3636
----------
37-
element_ids : List of int
37+
element_ids : list[int]
3838
List of IDs for the elements.
39-
server : ansys.dpf.core.server, optional
39+
server : DpfServer, optional
4040
Server with the channel connected to the remote or local instance.
4141
The default is ``None``, in which case an attempt is made to use the
4242
global server.
4343
4444
Returns
4545
-------
46-
scoping : ansys.dpf.core.Scoping
46+
scoping : Scoping
4747
"""
4848
scoping = Scoping(server=server, ids=element_ids, location=locations.elemental)
4949
return scoping
@@ -56,13 +56,13 @@ def named_selection_scoping(named_selection_name, model, server=None):
5656
----------
5757
named_selection_name : str
5858
Name of the named selection.
59-
server : ansys.dpf.core.server, optional
59+
server : DpfServer, optional
6060
Server with the channel connected to the remote or local instance.
6161
The default is ``None``, in which case an attempt is made to use the
6262
global server.
6363
6464
Returns
6565
-------
66-
scoping : ansys.dpf.core.Scoping
66+
scoping : Scoping
6767
"""
6868
return model.metadata.named_selection(named_selection_name)

ansys/dpf/core/time_freq_scoping_factory.py

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ansys.dpf.core import Scoping
99
from ansys.dpf.core import errors as dpf_errors
1010
from ansys.dpf.core.common import locations
11-
11+
from ansys.dpf.core.model import Model
1212

1313
def scoping_by_load_step(load_step, server=None):
1414
"""Create a specific ``ansys.dpf.core.Scoping`` for a given load step.
@@ -19,15 +19,15 @@ def scoping_by_load_step(load_step, server=None):
1919
Parameters
2020
----------
2121
load_step : int
22-
Load step ID of the specific time frequency scoiping.
23-
server : ansys.dpf.core.server, optional
22+
Load step ID of the specific time frequency scoping.
23+
server : DpfServer, optional
2424
Server with the channel connected to the remote or local instance.
2525
The default is ``None``, in which case an attempt is made to use the
2626
global server.
2727
2828
Returns
2929
-------
30-
scoping : ansys.dpf.core.Scoping
30+
scoping : Scoping
3131
Scoping targeting one load step.
3232
"""
3333
scoping = Scoping(server=server, ids=[load_step], location=locations.time_freq_step)
@@ -42,16 +42,16 @@ def scoping_by_load_steps(load_steps, server=None):
4242
4343
Parameters
4444
----------
45-
load_steps : list of int
45+
load_steps : list[int]
4646
List of load steps IDs of the specific time frequency scoping.
47-
server : ansys.dpf.core.server, optional
47+
server : DpfServer, optional
4848
Server with the channel connected to the remote or local instance.
4949
The default is ``None``, in which case an attempt is made to use the
5050
global server.
5151
5252
Returns
5353
-------
54-
scoping : ansys.dpf.core.Scoping
54+
scoping : Scoping
5555
Scoping targeting several load_steps.
5656
"""
5757
if not isinstance(load_steps, list):
@@ -70,14 +70,14 @@ def scoping_by_set(cumulative_set, server=None):
7070
----------
7171
cumulative_set : int
7272
Cumulative index of the set.
73-
server : ansys.dpf.core.server, optional
73+
server : DpfServer, optional
7474
Server with the channel connected to the remote or local instance.
7575
The default is ``None``, in which case an attempt is made to use the
7676
global server.
7777
7878
Returns
7979
-------
80-
scoping : ansys.dpf.core.Scoping
80+
scoping : Scoping
8181
Scoping targeting one set (referenced by cumulative index).
8282
"""
8383
scoping = Scoping(server=server, ids=[cumulative_set], location=locations.time_freq)
@@ -92,16 +92,16 @@ def scoping_by_sets(cumulative_sets, server=None):
9292
9393
Parameters
9494
----------
95-
cumulative_sets : list of int
95+
cumulative_sets : list[int]
9696
List of cumulative indices of the sets.
97-
server : ansys.dpf.core.server, optional
97+
server : DpfServer, optional
9898
Server with the channel connected to the remote or local instance.
9999
The default is ``None``, in which case an attempt is made to use the
100100
global server.
101101
102102
Returns
103103
-------
104-
scoping : ansys.dpf.core.Scoping
104+
scoping : Scoping
105105
Scoping targeting severals sets (referenced by cumulative indices).
106106
"""
107107
if not isinstance(cumulative_sets, list):
@@ -111,7 +111,7 @@ def scoping_by_sets(cumulative_sets, server=None):
111111

112112

113113
def scoping_by_step_and_substep(
114-
load_step_id, subset_id, time_freq_support, server=None
114+
load_step_id, subset_id, time_freq_support
115115
):
116116
"""Create a specific :class:`ansys.dpf.core.Scoping` for a given step and subset.
117117
@@ -124,19 +124,18 @@ def scoping_by_step_and_substep(
124124
ID of the load step.
125125
subset_id : int
126126
ID of the subset.
127-
time_freq_support : ansys.dpf.core.TimeFreqSupport
128-
server : ansys.dpf.core.server, optional
129-
Server with the channel connected to the remote or local instance.
130-
The default is ``None``, in which case an attempt is made to use the
131-
global server.
127+
time_freq_support : TimeFreqSupport
132128
133129
Returns
134130
-------
135-
scoping : ansys.dpf.core.Scoping
131+
scoping : Scoping
136132
Scoping based on a given step and substep of a time frequency support.
137133
"""
138134
set_index = time_freq_support.get_cumulative_index(load_step_id - 1, subset_id - 1)
139-
scoping = Scoping(ids=[set_index + 1], location=locations.time_freq)
135+
scoping = Scoping(
136+
ids=[set_index + 1],
137+
location=locations.time_freq,
138+
server=time_freq_support._server)
140139
return scoping
141140

142141

@@ -152,16 +151,37 @@ def scoping_by_step_and_substep_from_model(load_step_id, subset_id, model, serve
152151
ID of the step.
153152
subset_id : int
154153
ID of the subset.
155-
time_freq_support : ansys.dpf.core.TimeFreqSupport()
156-
server : ansys.dpf.core.server, optional
154+
model : Model
155+
server : DpfServer, optional
157156
Server with the channel connected to the remote or local instance.
158157
The default is ``None``, in which case an attempt is made to use the
159158
global server.
160159
161160
Returns
162161
-------
163-
scoping : ansys.dpf.core.Scoping
162+
scoping : Scoping
164163
Scoping based on a given step/substep of a model's time_freq_support."""
165164
return scoping_by_step_and_substep(
166165
load_step_id, subset_id, model.metadata.time_freq_support
167166
)
167+
168+
169+
def scoping_on_all_time_freqs(tf_support_or_model):
170+
"""Create a specific :class:`ansys.dpf.core.Scoping` with all time or
171+
frequency sets of a :class:`ansys.dpf.core.TimeFreqSupport` or a class:`ansys.dpf.core.Model`
172+
173+
Parameters
174+
----------
175+
tf_support_or_model : TimeFreqSupport, Model
176+
177+
Returns
178+
-------
179+
scoping : Scoping
180+
Scoping with all time or frequency sets IDs.
181+
"""
182+
if isinstance(tf_support_or_model, Model):
183+
tf_support_or_model = tf_support_or_model.metadata.time_freq_support
184+
return Scoping(
185+
ids=range(1, len(tf_support_or_model.time_frequencies) + 1),
186+
location=locations.time_freq,
187+
server=tf_support_or_model._server)

tests/test_factories.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ def test_scoping_by_step_and_substep_from_model(plate_msup):
242242
assert scop.location == locations.time_freq
243243

244244

245+
def test_scoping_on_all_freqs(plate_msup):
246+
model = Model(plate_msup)
247+
scop = time_freq_scoping_factory.scoping_on_all_time_freqs(model)
248+
assert scop is not None
249+
assert np.allclose(scop.ids, range(1, 21))
250+
scop = time_freq_scoping_factory.scoping_on_all_time_freqs(model.metadata.time_freq_support)
251+
assert scop is not None
252+
assert np.allclose(scop.ids, range(1, 21))
253+
254+
245255
def test_nodal_scoping():
246256
scop = mesh_scoping_factory.nodal_scoping([2, 5, 10])
247257
assert scop is not None

0 commit comments

Comments
 (0)