Skip to content

Commit ad65dd4

Browse files
Properly handle dict in operators generation (#1046)
* dict in mustache * update operators (#1047) Co-authored-by: rafacanton <[email protected]> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: rafacanton <[email protected]>
1 parent 929d78d commit ad65dd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+711
-279
lines changed

docs/source/_static/dpf_operators.html

Lines changed: 11 additions & 2 deletions
Large diffs are not rendered by default.

src/ansys/dpf/core/operators/averaging/elemental_to_nodal.py

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@
1111

1212

1313
class elemental_to_nodal(Operator):
14-
"""Transforms an Elemental Nodal field to a Nodal field. The result is
15-
computed on a given node's scoping.
14+
"""Transforms an Elemental field to a Nodal field. The result is computed
15+
on a given node's scoping. 1. For a finite element mesh, the
16+
value on a node is the average of the values of the neighbour
17+
elements. 2. For a volume finite volume mesh, the agorithm is :
18+
- For each node, compute interpolation weights for the cells
19+
connected to it based on the Frink's Laplacian method. -
20+
If the determinant of the I matrix is zero, switch to an inverse
21+
distance weighted average. - If not, compute the Frink
22+
weights and apply the Holmes' weight clip. - If the
23+
clipping produces a large overshoot, inverse volume weighted
24+
average is used.. 3. For a face finite volume mesh inverse
25+
distance weighted average is used.
1626
1727
Parameters
1828
----------
@@ -24,6 +34,10 @@ class elemental_to_nodal(Operator):
2434
Averaging on nodes is used if this pin is set
2535
to 1 (default is 1 for integrated
2636
results and 0 for discrete ones).
37+
algorithm : int, optional
38+
Forces the usage of algorithm 1, 2 or 3
39+
(default is chosen based on the type
40+
of mesh).
2741
2842
2943
Examples
@@ -40,12 +54,15 @@ class elemental_to_nodal(Operator):
4054
>>> op.inputs.mesh_scoping.connect(my_mesh_scoping)
4155
>>> my_force_averaging = int()
4256
>>> op.inputs.force_averaging.connect(my_force_averaging)
57+
>>> my_algorithm = int()
58+
>>> op.inputs.algorithm.connect(my_algorithm)
4359
4460
>>> # Instantiate operator and connect inputs in one line
4561
>>> op = dpf.operators.averaging.elemental_to_nodal(
4662
... field=my_field,
4763
... mesh_scoping=my_mesh_scoping,
4864
... force_averaging=my_force_averaging,
65+
... algorithm=my_algorithm,
4966
... )
5067
5168
>>> # Get output data
@@ -57,6 +74,7 @@ def __init__(
5774
field=None,
5875
mesh_scoping=None,
5976
force_averaging=None,
77+
algorithm=None,
6078
config=None,
6179
server=None,
6280
):
@@ -69,11 +87,24 @@ def __init__(
6987
self.inputs.mesh_scoping.connect(mesh_scoping)
7088
if force_averaging is not None:
7189
self.inputs.force_averaging.connect(force_averaging)
90+
if algorithm is not None:
91+
self.inputs.algorithm.connect(algorithm)
7292

7393
@staticmethod
7494
def _spec():
75-
description = """Transforms an Elemental Nodal field to a Nodal field. The result is
76-
computed on a given node's scoping."""
95+
description = """Transforms an Elemental field to a Nodal field. The result is computed
96+
on a given node's scoping. 1. For a finite element mesh,
97+
the value on a node is the average of the values of the
98+
neighbour elements. 2. For a volume finite volume mesh,
99+
the agorithm is : - For each node, compute
100+
interpolation weights for the cells connected to it based
101+
on the Frink's Laplacian method. - If the
102+
determinant of the I matrix is zero, switch to an inverse
103+
distance weighted average. - If not, compute the
104+
Frink weights and apply the Holmes' weight clip. -
105+
If the clipping produces a large overshoot, inverse volume
106+
weighted average is used.. 3. For a face finite volume
107+
mesh inverse distance weighted average is used."""
77108
spec = Specification(
78109
description=description,
79110
map_input_pin_spec={
@@ -98,6 +129,14 @@ def _spec():
98129
to 1 (default is 1 for integrated
99130
results and 0 for discrete ones).""",
100131
),
132+
200: PinSpecification(
133+
name="algorithm",
134+
type_names=["int32"],
135+
optional=True,
136+
document="""Forces the usage of algorithm 1, 2 or 3
137+
(default is chosen based on the type
138+
of mesh).""",
139+
),
101140
},
102141
map_output_pin_spec={
103142
0: PinSpecification(
@@ -161,6 +200,8 @@ class InputsElementalToNodal(_Inputs):
161200
>>> op.inputs.mesh_scoping.connect(my_mesh_scoping)
162201
>>> my_force_averaging = int()
163202
>>> op.inputs.force_averaging.connect(my_force_averaging)
203+
>>> my_algorithm = int()
204+
>>> op.inputs.algorithm.connect(my_algorithm)
164205
"""
165206

166207
def __init__(self, op: Operator):
@@ -173,6 +214,8 @@ def __init__(self, op: Operator):
173214
elemental_to_nodal._spec().input_pin(2), 2, op, -1
174215
)
175216
self._inputs.append(self._force_averaging)
217+
self._algorithm = Input(elemental_to_nodal._spec().input_pin(200), 200, op, -1)
218+
self._inputs.append(self._algorithm)
176219

177220
@property
178221
def field(self):
@@ -235,6 +278,28 @@ def force_averaging(self):
235278
"""
236279
return self._force_averaging
237280

281+
@property
282+
def algorithm(self):
283+
"""Allows to connect algorithm input to the operator.
284+
285+
Forces the usage of algorithm 1, 2 or 3
286+
(default is chosen based on the type
287+
of mesh).
288+
289+
Parameters
290+
----------
291+
my_algorithm : int
292+
293+
Examples
294+
--------
295+
>>> from ansys.dpf import core as dpf
296+
>>> op = dpf.operators.averaging.elemental_to_nodal()
297+
>>> op.inputs.algorithm.connect(my_algorithm)
298+
>>> # or
299+
>>> op.inputs.algorithm(my_algorithm)
300+
"""
301+
return self._algorithm
302+
238303

239304
class OutputsElementalToNodal(_Outputs):
240305
"""Intermediate class used to get outputs from

src/ansys/dpf/core/operators/averaging/elemental_to_nodal_fc.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@
1212

1313
class elemental_to_nodal_fc(Operator):
1414
"""Transforms Elemental Nodal fields to Nodal fields. The result is
15-
computed on a given node's scoping.
15+
computed on a given node's scoping.1. For a finite element mesh,
16+
the value on a node is the average of the values of the neighbour
17+
elements. 2. For a finite volume mesh, the agorithm is : - For
18+
each node, compute interpolation weights for the cells connected
19+
to it based on the Frink's Laplacian method. - If the
20+
determinant of the I matrix is zero, switch to an inverse distance
21+
weighted average. - If not, compute the Frink weights and
22+
apply the Holmes' weight clip. - If the clipping produces
23+
a large overshoot, inverse volume weighted average is used.. 3.
24+
For a face finite volume mesh inverse distance weighted average is
25+
used.
1626
1727
Parameters
1828
----------
@@ -23,6 +33,10 @@ class elemental_to_nodal_fc(Operator):
2333
to 1 (default is 1 for integrated
2434
results and 0 for discrete ones).
2535
mesh_scoping : Scoping or ScopingsContainer, optional
36+
algorithm : int, optional
37+
Forces the usage of algorithm 1, 2 or 3
38+
(default is chosen based on the type
39+
of mesh).
2640
2741
2842
Examples
@@ -41,13 +55,16 @@ class elemental_to_nodal_fc(Operator):
4155
>>> op.inputs.force_averaging.connect(my_force_averaging)
4256
>>> my_mesh_scoping = dpf.Scoping()
4357
>>> op.inputs.mesh_scoping.connect(my_mesh_scoping)
58+
>>> my_algorithm = int()
59+
>>> op.inputs.algorithm.connect(my_algorithm)
4460
4561
>>> # Instantiate operator and connect inputs in one line
4662
>>> op = dpf.operators.averaging.elemental_to_nodal_fc(
4763
... fields_container=my_fields_container,
4864
... mesh=my_mesh,
4965
... force_averaging=my_force_averaging,
5066
... mesh_scoping=my_mesh_scoping,
67+
... algorithm=my_algorithm,
5168
... )
5269
5370
>>> # Get output data
@@ -60,6 +77,7 @@ def __init__(
6077
mesh=None,
6178
force_averaging=None,
6279
mesh_scoping=None,
80+
algorithm=None,
6381
config=None,
6482
server=None,
6583
):
@@ -74,11 +92,24 @@ def __init__(
7492
self.inputs.force_averaging.connect(force_averaging)
7593
if mesh_scoping is not None:
7694
self.inputs.mesh_scoping.connect(mesh_scoping)
95+
if algorithm is not None:
96+
self.inputs.algorithm.connect(algorithm)
7797

7898
@staticmethod
7999
def _spec():
80100
description = """Transforms Elemental Nodal fields to Nodal fields. The result is
81-
computed on a given node's scoping."""
101+
computed on a given node's scoping.1. For a finite element
102+
mesh, the value on a node is the average of the values of
103+
the neighbour elements. 2. For a finite volume mesh, the
104+
agorithm is : - For each node, compute interpolation
105+
weights for the cells connected to it based on the
106+
Frink's Laplacian method. - If the determinant of
107+
the I matrix is zero, switch to an inverse distance
108+
weighted average. - If not, compute the Frink
109+
weights and apply the Holmes' weight clip. - If
110+
the clipping produces a large overshoot, inverse volume
111+
weighted average is used.. 3. For a face finite volume
112+
mesh inverse distance weighted average is used."""
82113
spec = Specification(
83114
description=description,
84115
map_input_pin_spec={
@@ -108,6 +139,14 @@ def _spec():
108139
optional=True,
109140
document="""""",
110141
),
142+
200: PinSpecification(
143+
name="algorithm",
144+
type_names=["int32"],
145+
optional=True,
146+
document="""Forces the usage of algorithm 1, 2 or 3
147+
(default is chosen based on the type
148+
of mesh).""",
149+
),
111150
},
112151
map_output_pin_spec={
113152
0: PinSpecification(
@@ -173,6 +212,8 @@ class InputsElementalToNodalFc(_Inputs):
173212
>>> op.inputs.force_averaging.connect(my_force_averaging)
174213
>>> my_mesh_scoping = dpf.Scoping()
175214
>>> op.inputs.mesh_scoping.connect(my_mesh_scoping)
215+
>>> my_algorithm = int()
216+
>>> op.inputs.algorithm.connect(my_algorithm)
176217
"""
177218

178219
def __init__(self, op: Operator):
@@ -191,6 +232,10 @@ def __init__(self, op: Operator):
191232
elemental_to_nodal_fc._spec().input_pin(3), 3, op, -1
192233
)
193234
self._inputs.append(self._mesh_scoping)
235+
self._algorithm = Input(
236+
elemental_to_nodal_fc._spec().input_pin(200), 200, op, -1
237+
)
238+
self._inputs.append(self._algorithm)
194239

195240
@property
196241
def fields_container(self):
@@ -268,6 +313,28 @@ def mesh_scoping(self):
268313
"""
269314
return self._mesh_scoping
270315

316+
@property
317+
def algorithm(self):
318+
"""Allows to connect algorithm input to the operator.
319+
320+
Forces the usage of algorithm 1, 2 or 3
321+
(default is chosen based on the type
322+
of mesh).
323+
324+
Parameters
325+
----------
326+
my_algorithm : int
327+
328+
Examples
329+
--------
330+
>>> from ansys.dpf import core as dpf
331+
>>> op = dpf.operators.averaging.elemental_to_nodal_fc()
332+
>>> op.inputs.algorithm.connect(my_algorithm)
333+
>>> # or
334+
>>> op.inputs.algorithm(my_algorithm)
335+
"""
336+
return self._algorithm
337+
271338

272339
class OutputsElementalToNodalFc(_Outputs):
273340
"""Intermediate class used to get outputs from

src/ansys/dpf/core/operators/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def build_pin_data(pins, output=False):
7575
pin_name = pin_name.replace(">", "_")
7676

7777
main_type = docstring_types[0] if len(docstring_types) >= 1 else ""
78-
built_in_types = ("int", "double", "string", "bool", "float", "str")
78+
built_in_types = ("int", "double", "string", "bool", "float", "str", "dict")
7979

8080
# Case where output pin has multiple types.
8181
multiple_types = len(type_names) >= 2

src/ansys/dpf/core/operators/geo/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
from .spherical_to_cartesian import spherical_to_cartesian
1616
from .spherical_to_cartesian_fc import spherical_to_cartesian_fc
1717
from .to_polar_coordinates import to_polar_coordinates
18+
from .transform_invariant_terms_rbd import transform_invariant_terms_rbd

0 commit comments

Comments
 (0)