Skip to content

Commit a5c32a7

Browse files
authored
Remove all locations string (#781)
* Remove all locations string * fixes
1 parent d6ea144 commit a5c32a7

File tree

13 files changed

+68
-93
lines changed

13 files changed

+68
-93
lines changed

examples/02-modal-harmonic/01-modal_cyclic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
scyc_op.inputs.time_scoping.connect([8])
5151

5252
# request the results averaged on the nodes
53-
scyc_op.inputs.requested_location.connect("Nodal")
53+
scyc_op.inputs.requested_location.connect(dpf.locations.nodal)
5454

5555
# connect the base mesh and the expanded mesh, to avoid rexpanding the mesh
5656
scyc_op.inputs.sector_mesh.connect(model.metadata.meshed_region)
5757
# scyc_op.inputs.expanded_meshed_region.connect(mesh)
5858

5959
# request equivalent von mises operator and connect it to stress operator
60-
eqv = dpf.Operator("eqv_fc")
60+
eqv = dpf.operators.invariant.von_mises_eqv_fc()
6161
eqv.inputs.connect(scyc_op.outputs)
6262

6363
# expand the results and get stress eqv
@@ -77,7 +77,7 @@
7777
scyc_op.inputs.time_scoping.connect([8])
7878

7979
# request the results averaged on the nodes
80-
scyc_op.inputs.requested_location.connect("Nodal")
80+
scyc_op.inputs.requested_location.connect(dpf.locations.nodal)
8181

8282
# connect the base mesh and the expanded mesh, to avoid rexpanding the mesh
8383
scyc_op.inputs.sector_mesh.connect(model.metadata.meshed_region)
@@ -87,7 +87,7 @@
8787
scyc_op.inputs.sectors_to_expand.connect([1, 3, 5])
8888

8989
# extract Sy (use component selector and select the component 1)
90-
comp_sel = dpf.Operator("component_selector_fc")
90+
comp_sel = dpf.operators.logic.component_selector_fc()
9191
comp_sel.inputs.fields_container.connect(scyc_op.outputs.fields_container)
9292
comp_sel.inputs.component_number.connect(0)
9393

@@ -115,11 +115,11 @@
115115
# scyc_op.inputs.expanded_meshed_region.connect(mesh)
116116

117117
# request to elemental averaging operator
118-
to_elemental = dpf.Operator("to_elemental_fc")
118+
to_elemental = dpf.operators.averaging.to_elemental_fc()
119119
to_elemental.inputs.fields_container.connect(scyc_op.outputs.fields_container)
120120

121121
# extract Sy (use component selector and select the component 1)
122-
comp_sel = dpf.Operator("component_selector_fc")
122+
comp_sel = dpf.operators.logic.component_selector_fc()
123123
comp_sel.inputs.fields_container.connect(to_elemental.outputs.fields_container)
124124
comp_sel.inputs.component_number.connect(1)
125125

examples/02-modal-harmonic/02-cyclic_multi_stage.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
# property with 2 as an argument (1 would ignore the cyclic symmetry).
2929

3030
# Create displacement cyclic operator
31-
UCyc = model.results.displacement()
32-
UCyc.inputs.read_cyclic(2)
31+
u_cyc = model.results.displacement()
32+
u_cyc.inputs.read_cyclic(2)
3333

3434
# expand the displacements and get a total deformation
35-
nrm = dpf.Operator("norm_fc")
36-
nrm.inputs.connect(UCyc.outputs)
35+
nrm = dpf.operators.math.norm_fc()
36+
nrm.inputs.connect(u_cyc.outputs)
3737
fields = nrm.outputs.fields_container()
3838

3939
# # get the expanded mesh
@@ -54,11 +54,11 @@
5454
SCyc.inputs.time_scoping.connect([3])
5555

5656
# request the results averaged on the nodes
57-
SCyc.inputs.requested_location.connect("Nodal")
57+
SCyc.inputs.requested_location.connect(dpf.locations.nodal)
5858

5959
# request equivalent von mises operator and connect it to stress
6060
# operator
61-
eqv = dpf.Operator("eqv_fc")
61+
eqv = dpf.operators.invariant.von_mises_eqv_fc()
6262
eqv.inputs.connect(SCyc.outputs)
6363

6464
# expand the results and get stress eqv

examples/03-advanced/10-asme_secviii_divtwo.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
path = examples.download_example_asme_result()
2828
model = dpf.Model(path)
29-
dataSource = model.metadata.data_sources
29+
data_source = model.metadata.data_sources
3030

31-
timeScoping = dpf.Scoping()
32-
timeScoping.location = dpf.locations.time_freq
33-
timeScoping.ids = [4]
31+
time_scoping = dpf.Scoping()
32+
time_scoping.location = dpf.locations.time_freq
33+
time_scoping.ids = [4]
3434

3535

3636
###############################################################################
@@ -61,29 +61,29 @@
6161
# Consequently, a correction factor is applied.
6262

6363
seqv_op = dpf.operators.result.stress_von_mises(
64-
time_scoping=timeScoping, data_sources=dataSource, requested_location="Nodal"
64+
time_scoping=time_scoping, data_sources=data_source, requested_location=dpf.locations.nodal
6565
)
6666
seqv = seqv_op.outputs.fields_container()
6767

6868
s1_op = dpf.operators.result.stress_principal_1(
69-
time_scoping=timeScoping, data_sources=dataSource, requested_location="Nodal"
69+
time_scoping=time_scoping, data_sources=data_source, requested_location=dpf.locations.nodal
7070
)
7171
s1 = s1_op.outputs.fields_container()
7272

7373
s2_op = dpf.operators.result.stress_principal_2(
74-
time_scoping=timeScoping, data_sources=dataSource, requested_location="Nodal"
74+
time_scoping=time_scoping, data_sources=data_source, requested_location=dpf.locations.nodal
7575
)
7676
s2 = s2_op.outputs.fields_container()
7777

7878
s3_op = dpf.operators.result.stress_principal_3(
79-
time_scoping=timeScoping, data_sources=dataSource, requested_location="Nodal"
79+
time_scoping=time_scoping, data_sources=data_source, requested_location=dpf.locations.nodal
8080
)
8181
s3 = s3_op.outputs.fields_container()
8282

8383
strain_op = dpf.operators.result.plastic_strain(
84-
data_sources=dataSource,
85-
requested_location="ElementalNodal",
86-
time_scoping=timeScoping,
84+
data_sources=data_source,
85+
requested_location=dpf.locations.elemental_nodal,
86+
time_scoping=time_scoping,
8787
)
8888
pstrain = strain_op.outputs.fields_container()
8989

examples/05-plotting/00-basic_plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
# Plot a field on its supporting mesh (field location must be Elemental or Nodal)
3434
stress = model.results.stress()
35-
stress.inputs.requested_location.connect("Nodal")
35+
stress.inputs.requested_location.connect(dpf.locations.nodal)
3636
fc = stress.outputs.fields_container()
3737
field = fc[0]
3838
field.plot(notebook=False, shell_layers=None, show_axes=True, title="Field", text="Field plot")

examples/05-plotting/02-solution_combination.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
###############################################################################
14-
# Import the ``dpf_core`` module, included examples file, and the ``DpfPlotter``
14+
# Import the ``ansys.dpf.core`` module, included examples file, and the ``DpfPlotter``
1515
# module.
1616
from ansys.dpf import core as dpf
1717
from ansys.dpf.core import examples
@@ -35,21 +35,21 @@
3535

3636
###############################################################################
3737
# Get the stress tensor and ``connect`` time scoping.
38-
# Make sure that you define ``"Nodal"`` as the scoping location because
38+
# Make sure that you define ``dpf.locations.nodal`` as the scoping location because
3939
# labels are supported only for nodal results.
4040
#
4141
stress_tensor = model.results.stress()
4242
time_scope = dpf.Scoping()
4343
time_scope.ids = [1, 2]
4444
stress_tensor.inputs.time_scoping.connect(time_scope)
45-
stress_tensor.inputs.requested_location.connect("Nodal")
45+
stress_tensor.inputs.requested_location.connect(dpf.locations.nodal)
4646

4747
###############################################################################
4848
# This code performs solution combination on two load cases, LC1 and LC2.
4949
# You can access individual load cases as the fields of a fields container for
5050
# the stress tensor.
51-
field_lc1 = stress_tensor.outputs.fields_container.get_data()[0]
52-
field_lc2 = stress_tensor.outputs.fields_container.get_data()[1]
51+
field_lc1 = stress_tensor.outputs.fields_container()[0]
52+
field_lc2 = stress_tensor.outputs.fields_container()[1]
5353

5454
# Scale LC2 to -1.
5555
stress_tensor_lc2_sc = dpf.operators.math.scale(field=field_lc2, ponderation=-1.0)

examples/05-plotting/03-labels.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,22 @@
5858

5959
###############################################################################
6060
# Get the stress tensor and ``connect`` time scoping.
61-
# Make sure that you define ``"Nodal"`` as the scoping location because
61+
# Make sure that you define ``dpf.locations.nodal`` as the scoping location because
6262
# labels are supported only for nodal results.
6363
#
6464
stress_tensor = model.results.stress()
65-
time_scope = dpf.Scoping()
66-
time_scope.ids = [20] # [1, 2]
67-
stress_tensor.inputs.time_scoping.connect(time_scope)
68-
stress_tensor.inputs.requested_location.connect("Nodal")
65+
stress_tensor.inputs.time_scoping([20])
66+
stress_tensor.inputs.requested_location(dpf.locations.nodal)
6967
# field = stress_tensor.outputs.fields_container.get_data()[0]
7068

71-
norm_op = dpf.Operator("norm_fc")
72-
norm_op.inputs.connect(stress_tensor.outputs)
69+
norm_op = dpf.operators.math.norm_fc()
70+
norm_op.inputs.connect(stress_tensor)
7371
field_norm_stress = norm_op.outputs.fields_container()[0]
7472
print(field_norm_stress)
7573

7674
norm_op2 = dpf.Operator("norm_fc")
7775
disp = model.results.displacement()
78-
disp.inputs.time_scoping.connect(time_scope)
76+
disp.inputs.time_scoping.connect([20])
7977
norm_op2.inputs.connect(disp.outputs)
8078
field_norm_disp = norm_op2.outputs.fields_container()[0]
8179
print(field_norm_disp)

examples/08-averaging/01-average_across_bodies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def average_across_bodies(analysis):
281281
stress_op = ops.result.stress_eqv_as_mechanical()
282282
stress_op.inputs.time_scoping.connect([time_set])
283283
stress_op.inputs.data_sources.connect(model)
284-
stress_op.inputs.requested_location.connect("Nodal")
284+
stress_op.inputs.requested_location.connect(dpf.locations.nodal)
285285
stress_op.inputs.average_across_bodies.connect(False)
286286

287287
print(stress_op.outputs.fields_container())

src/ansys/dpf/core/field.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ class Field(_FieldBase):
4747
nature : :class:`ansys.dpf.core.common.natures`, optional
4848
Nature of the field.
4949
location : str, optional
50-
Location of the field. Options are:
50+
Location of the field. Options are in :class:`locations <ansys.dpf.core.common.locations>`
5151
52-
- ``"Nodal"``
53-
- ``"Elemental"``
54-
- ``"ElementalNodal"``
52+
- ``dpf.locations.nodal``
53+
- ``dpf.locations.elemental``
54+
- ``dpf.locations.elemental_nodal``
55+
- ...
5556
5657
field : Field, ansys.grpc.dpf.field_pb2.Field, ctypes.c_void_p, optional
5758
Field message generated from a gRPC stub, or returned by DPF's C clients.
@@ -248,8 +249,7 @@ def location(self):
248249
Returns
249250
-------
250251
str
251-
Location string, which can be ``"Nodal"``, ``"Elemental"``,
252-
``"ElementalNodal"``... See :class:`ansys.dpf.core.common.locations`.
252+
Location string, Options are in :class:`locations <ansys.dpf.core.common.locations>`.
253253
254254
Examples
255255
--------
@@ -275,8 +275,7 @@ def location(self, value):
275275
Parameters
276276
-------
277277
location : str or locations
278-
Location string, which can be ``"Nodal"``, ``"Elemental"``,
279-
``"ElementalNodal"``... See :class:`ansys.dpf.core.common.locations`.
278+
Location string, Options are in :class:`locations <ansys.dpf.core.common.locations>`.
280279
281280
Examples
282281
--------

src/ansys/dpf/core/field_definition.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ def location(self):
5959
Returns
6060
-------
6161
str
62-
Location string, such as ``"Nodal"``, ``"Elemental"``,
63-
or ``"TimeFreq_sets"``.
62+
Location string, such as :class:`ansys.dpf.core.locations.nodal`,
63+
:class:`ansys.dpf.core.locations.elemental` or
64+
:class:`ansys.dpf.core.locations.time_freq`.
6465
"""
6566
location = integral_types.MutableString(256)
6667
size = integral_types.MutableInt32(0)

src/ansys/dpf/core/fields_factory.py

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def field_from_array(arr, server=None):
6666
def create_matrix_field(num_entities, num_lines, num_col, location=locations.nodal, server=None):
6767
"""Create a matrix :class:`ansys.dpf.core.Field`.
6868
69-
This field contain entities that have a matrix format. This is a "reserve" mechanism,
69+
This field contains entities that have a matrix format. This is a "reserve" mechanism,
7070
not a resize one. This means that you need to append data to grow the size of your field.
7171
7272
Parameters
@@ -78,12 +78,8 @@ def create_matrix_field(num_entities, num_lines, num_col, location=locations.nod
7878
num_col : int
7979
Number of matrix columns.
8080
location : str, optional
81-
Location of the field. The default is ``"Nodal"``. For example:
82-
83-
- :class:`ansys.dpf.core.natures.nodal` (``"Nodal"``)
84-
- :class:`ansys.dpf.core.natures.elemental` (``"Elemental"``)
85-
- :class:`ansys.dpf.core.natures.elemental_nodal` (``"ElementalNodal"``)
86-
- ...
81+
Location of the field. Options are in :class:`locations <ansys.dpf.core.common.locations>`.
82+
The default is ``dpf.locations.nodal``.
8783
8884
server : ansys.dpf.core.server, optional
8985
Server with the channel connected to the remote or local instance.
@@ -126,12 +122,8 @@ def create_3d_vector_field(num_entities, location=locations.nodal, server=None):
126122
Number of entities to reserve
127123
128124
location : str, optional
129-
Location of the field. The default is ``"Nodal"``. For example:
130-
131-
- ansys.dpf.core.natures.nodal (``"Nodal"``)
132-
- ansys.dpf.core.natures.elemental (``"Elemental"``)
133-
- ansys.dpf.core.natures.elemental_nodal (``"ElementalNodal"``)
134-
- ...
125+
Location of the field. Options are in :class:`locations <ansys.dpf.core.common.locations>`.
126+
The default is ``dpf.locations.nodal``.
135127
136128
server : ansys.dpf.core.server, optional
137129
Server with the channel connected to the remote or local instance.
@@ -165,12 +157,8 @@ def create_tensor_field(num_entities, location=locations.nodal, server=None):
165157
num_entities : int
166158
Number of entities to reserve.
167159
location : str, optional
168-
Location of the field. The default is ``"Nodal"``. For example:
169-
170-
- :class:`ansys.dpf.core.natures.nodal` (``"Nodal"``)
171-
- :class:`ansys.dpf.core.natures.elemental` (``"Elemental"``)
172-
- :class:`ansys.dpf.core.natures.elemental_nodal` (``"ElementalNodal"``)
173-
- ...
160+
Location of the field. Options are in :class:`locations <ansys.dpf.core.common.locations>`.
161+
The default is ``dpf.locations.nodal``.
174162
175163
server : ansys.dpf.core.server, optional
176164
Server with the channel connected to the remote or local instance.
@@ -204,12 +192,8 @@ def create_scalar_field(num_entities, location=locations.nodal, server=None):
204192
num_entities : int
205193
Number of entities to reserve
206194
location : str, optional
207-
Location of the field. The default is ``"Nodal"``. For example:
208-
209-
- ansys.dpf.core.natures.nodal (``"Nodal"``)
210-
- ansys.dpf.core.natures.elemental (``"Elemental"``)
211-
- ansys.dpf.core.natures.elemental_nodal (``"ElementalNodal"``)
212-
- ...
195+
Location of the field. Options are in :class:`locations <ansys.dpf.core.common.locations>`.
196+
The default is ``dpf.locations.nodal``.
213197
214198
server : ansys.dpf.core.server, optional
215199
Server with the channel connected to the remote or local instance.
@@ -245,12 +229,8 @@ def create_vector_field(num_entities, num_comp, location=locations.nodal, server
245229
num_comp : int
246230
Number of vector components.
247231
location : str, optional
248-
Location of the field. The default is ``"Nodal"``. For example:
249-
250-
- ansys.dpf.core.natures.nodal (``"Nodal"``)
251-
- ansys.dpf.core.natures.elemental (``"Elemental"``)
252-
- ansys.dpf.core.natures.elemental_nodal (``"ElementalNodal"``)
253-
- ...
232+
Location of the field. Options are in :class:`locations <ansys.dpf.core.common.locations>`.
233+
The default is ``dpf.locations.nodal``.
254234
255235
server : ansys.dpf.core.server, optional
256236
Server with the channel connected to the remote or local instance.
@@ -286,22 +266,18 @@ def _create_field(server, nature, nentities, location=locations.nodal, ncomp_n=0
286266
Server with the channel connected to the remote or local instance.
287267
The default is ``None``, in which case an attempt is made to use the
288268
global server.
289-
snature : str
269+
nature : str
290270
Nature of the field entity data. For example:
291271
292272
- :class:`ansys.dpf.core.natures.matrix`
293273
- :class:`ansys.dpf.core.natures.scalar`
294274
295-
num_entities : int
275+
nentities : int
296276
Number of entities to reserve.
297277
298278
location : str, optional
299-
Location of the field. For example:
300-
301-
- :class:`ansys.dpf.core.natures.nodal` (``"Nodal"``)
302-
- :class:`ansys.dpf.core.natures.elemental` (``"Elemental"``)
303-
- :class:`ansys.dpf.core.natures.elemental_nodal` (``"ElementalNodal"``)
304-
- ...
279+
Location of the field. Options are in :class:`locations <ansys.dpf.core.common.locations>`.
280+
The default is ``dpf.locations.nodal``.
305281
306282
ncomp_n : int
307283
Number of lines.

0 commit comments

Comments
 (0)