Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the operators for 2023.2.pre0 #644

Merged
merged 11 commits into from
Nov 25, 2022
37 changes: 28 additions & 9 deletions .ci/code_generation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import sys

from ansys.dpf import core
import os
import glob
from pathlib import Path
import time
import shutil
import subprocess


core.set_default_server_context(core.AvailableServerContexts.premium)

if os.name == "posix":
LIB_TO_GENERATE = [
Expand All @@ -24,7 +30,6 @@
else:
LIB_TO_GENERATE = [
"Ans.Dpf.Native.dll",
"Ans.Dpf.Mechanical.dll",
"Ans.Dpf.FEMutils.dll",
"meshOperatorsCore.dll",
"mapdlOperatorsCore.dll",
Expand Down Expand Up @@ -58,17 +63,22 @@
os.remove(f)
except:
pass
core.start_local_server(config=core.AvailableServerConfigs.LegacyGrpcServer)
core.start_local_server(config=core.AvailableServerConfigs.GrpcServer)
code_gen = core.Operator("python_generator")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only work for PREMIUM. Should we explicitly add it as context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafacanton, sure, we can add it explicitely at the beginning of the script.
Also, sorry about the confusion Rafael, the problems with the constructors of the operators is that there is a second step in the operator generation, which I now added to the script.

code_gen.connect(1, TARGET_PATH)
for lib in LIB_TO_GENERATE:
code_gen.connect(0, lib)
if lib != LIB_TO_GENERATE[0]:
code_gen.connect(2, False)
else:
code_gen.connect(2, True)
code_gen.run()
time.sleep(0.1)
try:
code_gen.connect(0, lib)
if lib != LIB_TO_GENERATE[0]:
code_gen.connect(2, False)
else:
code_gen.connect(2, True)
print(f"Generating {lib} operators for server {core.SERVER.version}...")
code_gen.run()
time.sleep(0.1)
except Exception as e:
print(f"Could not generate operators for library {lib}:\n{str(e)}")
raise e

for lib in LIB_OPTIONAL_TO_GENERATE:
try:
Expand All @@ -77,7 +87,16 @@
code_gen.connect(2, False)
else:
code_gen.connect(2, True)
print(f"Generating optional {lib} operators for server {core.SERVER.version}...")
code_gen.run()
time.sleep(0.1)
except Exception as e:
print(f"Could not generate operators for optional library {lib}:\n{str(e)}")

# Call the dpf/core/operators/build.py script
# Requires to have pip installed requirements_build.txt
path_to_script = r"../ansys/dpf/core/operators/build.py"
print("Re-generating operators according to operator.mustache file...")
out = subprocess.check_output([sys.executable, path_to_script])
print(out.decode(encoding="utf-8"))
core.server.shutdown_all_session_servers()
8 changes: 4 additions & 4 deletions ansys/dpf/core/operators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from . import math
from . import result
from . import utility
from . import min_max
from . import result
from . import scoping
from . import filter
from . import logic
from . import metadata
from . import serialization
from . import min_max
from . import mesh
from . import geo
from . import serialization
from . import averaging
from . import geo
from . import invariant
from . import mapping
22 changes: 11 additions & 11 deletions ansys/dpf/core/operators/averaging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from .elemental_difference import elemental_difference
from .elemental_nodal_to_nodal import elemental_nodal_to_nodal
from .elemental_nodal_to_nodal_fc import elemental_nodal_to_nodal_fc
from .elemental_to_nodal import elemental_to_nodal
from .elemental_to_nodal_fc import elemental_to_nodal_fc
from .elemental_to_elemental_nodal import elemental_to_elemental_nodal
from .nodal_difference import nodal_difference
from .elemental_to_elemental_nodal_fc import elemental_to_elemental_nodal_fc
from .nodal_difference_fc import nodal_difference_fc
from .elemental_difference_fc import elemental_difference_fc
from .nodal_fraction_fc import nodal_fraction_fc
from .elemental_nodal_to_nodal_elemental_fc import elemental_nodal_to_nodal_elemental_fc
from .elemental_fraction_fc import elemental_fraction_fc
from .to_nodal import to_nodal
from .nodal_difference import nodal_difference
from .elemental_to_elemental_nodal import elemental_to_elemental_nodal
from .to_nodal_fc import to_nodal_fc
from .nodal_extend_to_mid_nodes import nodal_extend_to_mid_nodes
from .nodal_difference_fc import nodal_difference_fc
from .elemental_to_elemental_nodal_fc import elemental_to_elemental_nodal_fc
from .elemental_nodal_to_nodal_elemental import elemental_nodal_to_nodal_elemental
from .extend_to_mid_nodes import extend_to_mid_nodes
from .extend_to_mid_nodes_fc import extend_to_mid_nodes_fc
from .nodal_fraction_fc import nodal_fraction_fc
from .elemental_nodal_to_nodal_elemental_fc import elemental_nodal_to_nodal_elemental_fc
from .elemental_mean import elemental_mean
from .elemental_mean_fc import elemental_mean_fc
from .to_elemental_fc import to_elemental_fc
from .gauss_to_node_fc import gauss_to_node_fc
from .nodal_to_elemental import nodal_to_elemental
from .nodal_to_elemental_fc import nodal_to_elemental_fc
from .to_elemental_nodal_fc import to_elemental_nodal_fc
from .elemental_fraction_fc import elemental_fraction_fc
from .elemental_difference import elemental_difference
from .elemental_difference_fc import elemental_difference_fc
from .extend_to_mid_nodes_fc import extend_to_mid_nodes_fc
from .extend_to_mid_nodes import extend_to_mid_nodes
6 changes: 6 additions & 0 deletions ansys/dpf/core/operators/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ def build_operator(

print(f"Generated {succeeded} out of {len(available_operators)}")
dpf.SERVER.shutdown()
if succeeded == len(available_operators):
print("Success")
exit(0)
else:
print("Terminated with errors")
exit(1)
6 changes: 3 additions & 3 deletions ansys/dpf/core/operators/geo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .normals_provider_nl import normals_provider_nl
from .rotate_in_cylindrical_cs_fc import rotate_in_cylindrical_cs_fc
from .elements_volumes_over_time import elements_volumes_over_time
from .normals_provider_nl import normals_provider_nl
from .rotate_in_cylindrical_cs import rotate_in_cylindrical_cs
from .rotate import rotate
from .rotate_fc import rotate_fc
from .to_polar_coordinates import to_polar_coordinates
from .elements_volumes_over_time import elements_volumes_over_time
from .gauss_to_node import gauss_to_node
from .elements_facets_surfaces_over_time import elements_facets_surfaces_over_time
from .gauss_to_node import gauss_to_node
from .elements_volume import elements_volume
from .element_nodal_contribution import element_nodal_contribution
from .integrate_over_elements import integrate_over_elements
Expand Down
65 changes: 51 additions & 14 deletions ansys/dpf/core/operators/geo/rotate_in_cylindrical_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class rotate_in_cylindrical_cs(Operator):
3-3 rotation matrix and origin coordinates
must be set here to define a
coordinate system.
mesh : MeshedRegion, optional
Mesh support of the input field


Examples
Expand All @@ -40,25 +42,32 @@ class rotate_in_cylindrical_cs(Operator):
>>> op.inputs.field.connect(my_field)
>>> my_coordinate_system = dpf.Field()
>>> op.inputs.coordinate_system.connect(my_coordinate_system)
>>> my_mesh = dpf.MeshedRegion()
>>> op.inputs.mesh.connect(my_mesh)

>>> # Instantiate operator and connect inputs in one line
>>> op = dpf.operators.geo.rotate_in_cylindrical_cs(
... field=my_field,
... coordinate_system=my_coordinate_system,
... mesh=my_mesh,
... )

>>> # Get output data
>>> result_fields_container = op.outputs.fields_container()
>>> result_field = op.outputs.field()
"""

def __init__(self, field=None, coordinate_system=None, config=None, server=None):
def __init__(
self, field=None, coordinate_system=None, mesh=None, config=None, server=None
):
super().__init__(name="transform_cylindricalCS", config=config, server=server)
self._inputs = InputsRotateInCylindricalCs(self)
self._outputs = OutputsRotateInCylindricalCs(self)
if field is not None:
self.inputs.field.connect(field)
if coordinate_system is not None:
self.inputs.coordinate_system.connect(coordinate_system)
if mesh is not None:
self.inputs.mesh.connect(mesh)

@staticmethod
def _spec():
Expand All @@ -85,11 +94,17 @@ def _spec():
must be set here to define a
coordinate system.""",
),
2: PinSpecification(
name="mesh",
type_names=["abstract_meshed_region"],
optional=True,
document="""Mesh support of the input field""",
),
},
map_output_pin_spec={
0: PinSpecification(
name="fields_container",
type_names=["fields_container"],
name="field",
type_names=["field"],
optional=False,
document="""""",
),
Expand Down Expand Up @@ -146,6 +161,8 @@ class InputsRotateInCylindricalCs(_Inputs):
>>> op.inputs.field.connect(my_field)
>>> my_coordinate_system = dpf.Field()
>>> op.inputs.coordinate_system.connect(my_coordinate_system)
>>> my_mesh = dpf.MeshedRegion()
>>> op.inputs.mesh.connect(my_mesh)
"""

def __init__(self, op: Operator):
Expand All @@ -156,6 +173,8 @@ def __init__(self, op: Operator):
rotate_in_cylindrical_cs._spec().input_pin(1), 1, op, -1
)
self._inputs.append(self._coordinate_system)
self._mesh = Input(rotate_in_cylindrical_cs._spec().input_pin(2), 2, op, -1)
self._inputs.append(self._mesh)

@property
def field(self):
Expand Down Expand Up @@ -200,6 +219,26 @@ def coordinate_system(self):
"""
return self._coordinate_system

@property
def mesh(self):
"""Allows to connect mesh input to the operator.

Mesh support of the input field

Parameters
----------
my_mesh : MeshedRegion

Examples
--------
>>> from ansys.dpf import core as dpf
>>> op = dpf.operators.geo.rotate_in_cylindrical_cs()
>>> op.inputs.mesh.connect(my_mesh)
>>> # or
>>> op.inputs.mesh(my_mesh)
"""
return self._mesh


class OutputsRotateInCylindricalCs(_Outputs):
"""Intermediate class used to get outputs from
Expand All @@ -210,29 +249,27 @@ class OutputsRotateInCylindricalCs(_Outputs):
>>> from ansys.dpf import core as dpf
>>> op = dpf.operators.geo.rotate_in_cylindrical_cs()
>>> # Connect inputs : op.inputs. ...
>>> result_fields_container = op.outputs.fields_container()
>>> result_field = op.outputs.field()
"""

def __init__(self, op: Operator):
super().__init__(rotate_in_cylindrical_cs._spec().outputs, op)
self._fields_container = Output(
rotate_in_cylindrical_cs._spec().output_pin(0), 0, op
)
self._outputs.append(self._fields_container)
self._field = Output(rotate_in_cylindrical_cs._spec().output_pin(0), 0, op)
self._outputs.append(self._field)

@property
def fields_container(self):
"""Allows to get fields_container output of the operator
def field(self):
"""Allows to get field output of the operator

Returns
----------
my_fields_container : FieldsContainer
my_field : Field

Examples
--------
>>> from ansys.dpf import core as dpf
>>> op = dpf.operators.geo.rotate_in_cylindrical_cs()
>>> # Connect inputs : op.inputs. ...
>>> result_fields_container = op.outputs.fields_container()
>>> result_field = op.outputs.field()
""" # noqa: E501
return self._fields_container
return self._field
Loading