Skip to content

Commit

Permalink
Merge branch 'master' into fix/meilisearch
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgepiloto authored Feb 12, 2024
2 parents 9736bc7 + 2a7b995 commit e4cb58d
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 29 deletions.
12 changes: 6 additions & 6 deletions doc/source/_static/dpf_operators.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/03-harmonic_analyses/00-multi_harmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
field2 = fields[1]

###############################################################################
# Plot the minimum and maximum displacements over time.
# Plot the maximum displacements over time for Node ID 2 and 18

pyplot.plot(field1.data, "r", label="Field 1")
pyplot.plot(field2.data, "b", label="Field 2")
pyplot.plot(field1.data, "r", label="NODE-ID 2")
pyplot.plot(field2.data, "b", label="NODE-ID 18")
pyplot.xlabel("Frequency (Hz)")
pyplot.ylabel("Displacement (m)")
pyplot.legend()
Expand Down
2 changes: 1 addition & 1 deletion examples/06-plotting/03-labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@
# position, focal point, and view respectively.
plot.show_figure(
show_axes=True,
cpos=[(0.123, 0.095, 1.069), (-0.121, -0.149, 0.825), (0.0, 0.0, 1.0)],
cpos=[(0.123, 0.095, 1.069), (-0.121, -0.149, 0.825), (0.0, 0.0, 1.0)]
)
28 changes: 28 additions & 0 deletions src/ansys/dpf/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np

from ansys.dpf.core.check_version import version_requires
from ansys.dpf.core.server_types import BaseServer
from ansys.dpf.core.scoping import Scoping
from ansys.dpf.core.label_space import LabelSpace
Expand Down Expand Up @@ -74,6 +75,33 @@ def _server(self, value):
# step3: init environment
self._api.init_collection_environment(self) # creates stub when gRPC

@property
@version_requires("8.0")
def name(self):
"""Name of the Collection.
Notes
-----
Available starting with DPF 2024 R2 pre0.
Returns
-------
str
"""
out = self._api.collection_get_name(self)
return out if out != '' else None

@name.setter
@version_requires("8.0")
def name(self, name: str):
"""Set the name of the Collection.
Notes
-----
Available starting with DPF 2024 R2 pre0.
"""
self._api.collection_set_name(self, name=name)

@abc.abstractmethod
def create_subtype(self, obj_by_copy):
pass
Expand Down
20 changes: 17 additions & 3 deletions src/ansys/dpf/core/generic_data_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
if TYPE_CHECKING: # pragma: no cover
from ansys.dpf.core import Field, Scoping, StringField, GenericDataContainer

from ansys.dpf.core.dpf_operator import _write_output_type_to_type


from ansys.dpf.core import server as server_module
from ansys.dpf.core import errors
from ansys.dpf.core import errors, types
from ansys.dpf.core.any import Any
from ansys.dpf.core import collection
from ansys.dpf.core.mapping_types import map_types_to_python
Expand Down Expand Up @@ -104,21 +107,32 @@ def set_property(
any_dpf = Any.new_from(prop, self._server)
self._api.generic_data_container_set_property_any(self, property_name, any_dpf)

def get_property(self, property_name):
def get_property(self, property_name, output_type: Union[None, type, types] = None):
"""Get property with given name.
Parameters
----------
property_name : str
Property name.
output_type : None, type, types, optional
Expected type of the output. By default, type is deduced using
`GenericDataContainer.get_property_description`.
Returns
-------
Property object instance.
"""
any_ptr = self._api.generic_data_container_get_property_any(self, property_name)
any_dpf = Any(any_ptr, self._server)
output_type = self.get_property_description()[property_name]
if output_type is None:
output_type = self.get_property_description()[property_name]
else:
if not isinstance(output_type, type):
output_type = _write_output_type_to_type(output_type)

output_type = str(output_type.__name__)

class_ = getattr(builtins, output_type, None)
if class_ is None:
from ansys.dpf import core
Expand Down
15 changes: 7 additions & 8 deletions src/ansys/dpf/core/operators/geo/normals_provider_nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@


class normals_provider_nl(Operator):
"""Computes the normals on nodes/faces/elements based on integration
points (more accurate for non-linear elements) on a skin mesh.
"""Computes the normals on nodes/elements based on integration points
(more accurate for non-linear elements) on a skin mesh.
Parameters
----------
mesh : MeshedRegion
Skin, face, or shell mesh region.
Skin or shell mesh region.
mesh_scoping : Scoping, optional
Elemental, elementalnodal, or nodal scoping.
location derived from this.
Expand Down Expand Up @@ -75,17 +75,16 @@ def __init__(

@staticmethod
def _spec():
description = """Computes the normals on nodes/faces/elements based on integration
points (more accurate for non-linear elements) on a skin
mesh."""
description = """Computes the normals on nodes/elements based on integration points
(more accurate for non-linear elements) on a skin mesh."""
spec = Specification(
description=description,
map_input_pin_spec={
0: PinSpecification(
name="mesh",
type_names=["abstract_meshed_region"],
optional=False,
document="""Skin, face, or shell mesh region.""",
document="""Skin or shell mesh region.""",
),
1: PinSpecification(
name="mesh_scoping",
Expand Down Expand Up @@ -183,7 +182,7 @@ def __init__(self, op: Operator):
def mesh(self):
"""Allows to connect mesh input to the operator.
Skin, face, or shell mesh region.
Skin or shell mesh region.
Parameters
----------
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/dpf/core/operators/utility/server_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class server_path(Operator):
0 (default): root of the server, 1:
"dpf/bin/platform", 2:
"aisol/bin(dll)/platform", 3:
"dpf/plugins".
"dpf/plugins", 4: "dpf/workflows".
Examples
Expand Down Expand Up @@ -67,7 +67,7 @@ def _spec():
0 (default): root of the server, 1:
"dpf/bin/platform", 2:
"aisol/bin(dll)/platform", 3:
"dpf/plugins".""",
"dpf/plugins", 4: "dpf/workflows".""",
),
},
map_output_pin_spec={
Expand Down Expand Up @@ -144,7 +144,7 @@ def subpath(self):
0 (default): root of the server, 1:
"dpf/bin/platform", 2:
"aisol/bin(dll)/platform", 3:
"dpf/plugins".
"dpf/plugins", 4: "dpf/workflows".
Parameters
----------
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dpf/core/server_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ def __init__(
# Load DPFClientAPI
from ansys.dpf.core.misc import is_pypim_configured

self.live = False
super().__init__(ansys_path=ansys_path, load_operators=load_operators)
# Load Ans.Dpf.GrpcClient
self._grpc_client_path = load_api.load_grpc_client(ansys_path=ansys_path)
Expand Down Expand Up @@ -1017,11 +1018,11 @@ def __init__(
# Use ansys.grpc.dpf
from ansys.dpf.core.misc import is_pypim_configured

self.live = False
super().__init__()

self._info_instance = None
self._own_process = launch_server
self.live = False
self._local_server = False
self._stubs = {}
self.channel = None
Expand Down
12 changes: 12 additions & 0 deletions src/ansys/dpf/gate/collection_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ def collection_get_num_labels(collection):
def collection_get_label(collection, labelIndex):
return CollectionGRPCAPI._list(collection).labels.labels[labelIndex]

@staticmethod
def collection_get_name(collection):
return CollectionGRPCAPI._list(collection).name

@staticmethod
def collection_set_name(collection, name):
from ansys.grpc.dpf import collection_pb2
request = collection_pb2.UpdateCollectionRequest()
request.collection.CopyFrom(collection._internal_obj)
request.string_properties.update({"name": name})
_get_stub(collection._server).Update(request)

@staticmethod
def collection_get_size(collection):
if isinstance(collection._internal_obj, list):
Expand Down
Binary file modified src/ansys/dpf/gatebin/Ans.Dpf.GrpcClient.dll
Binary file not shown.
Binary file modified src/ansys/dpf/gatebin/DPFClientAPI.dll
Binary file not shown.
Binary file modified src/ansys/dpf/gatebin/libAns.Dpf.GrpcClient.so
Binary file not shown.
Binary file modified src/ansys/dpf/gatebin/libDPFClientAPI.so
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/entry/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def _get_test_files_directory():
] = "/tmp/test_files"


SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0 = meets_version(
get_server_version(core._global_server()), "8.0"
)
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_1 = meets_version(
get_server_version(core._global_server()), "6.1"
)
Expand Down
13 changes: 10 additions & 3 deletions tests/entry/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@
reason="Tests ANSYS_DPF_ACCEPT_LA",
)
def test_license_agr(restore_accept_la_env):
# store the server version beforehand
server_ge_8 = conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0
dpf.server.shutdown_global_server()
config = dpf.AvailableServerConfigs.InProcessServer
init_val = os.environ["ANSYS_DPF_ACCEPT_LA"]
del os.environ["ANSYS_DPF_ACCEPT_LA"]
with pytest.raises(errors.DPFServerException):
if server_ge_8:
dpf.start_local_server(config=config, as_global=True)
with pytest.raises(errors.DPFServerException):
dpf.Operator("stream_provider")
else:
with pytest.raises(errors.DPFServerException):
dpf.start_local_server(config=config, as_global=True)
with pytest.raises(errors.DPFServerException):
dpf.Operator("stream_provider")
os.environ["ANSYS_DPF_ACCEPT_LA"] = init_val
dpf.start_local_server(config=config, as_global=True)
assert "static" in examples.find_static_rst()
Expand All @@ -34,7 +40,8 @@ def test_license_agr(restore_accept_la_env):
@pytest.mark.order(2)
@pytest.mark.skipif(
os.environ.get("ANSYS_DPF_ACCEPT_LA", "") == ""
or not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0,
or not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0 or
conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
reason="Tests ANSYS_DPF_ACCEPT_LA",
)
def test_license_agr_remote(remote_config_server_type, restore_accept_la_env):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_fieldscontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def test_create_fields_container(server_type):
assert fc._internal_obj is not None


@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
reason="Renaming collections is supported via gRPC starting server version 8.0",
)
def test_rename_fields_container(server_type):
fc = FieldsContainer(server=server_type)
assert fc.name is None
fc.name = "test"
assert fc.name == "test"


def test_empty_index(server_type):
fc = FieldsContainer(server=server_type)
with pytest.raises(IndexError):
Expand Down
66 changes: 65 additions & 1 deletion tests/test_generic_data_container.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ansys.dpf import core as dpf
from conftest import (
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
)
import pytest

Expand Down Expand Up @@ -68,3 +68,67 @@ def test_get_property_description_generic_data_container(server_type):
"my-string": "str",
"my-field": "Field",
}


@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Available for servers >=7.0"
)
def test_get_by_type_generic_data_container(server_type):
gdc = dpf.GenericDataContainer(server=server_type)
entity = 42
gdc.set_property("my-int", entity)
new_entity = gdc.get_property("my-int")
assert 42 == new_entity
new_entity = gdc.get_property("my-int", int)
assert 42 == new_entity
new_entity = gdc.get_property("my-int", dpf.types.int)
assert 42 == new_entity

entity = 4.2
gdc.set_property("my-float", entity)
new_entity = gdc.get_property("my-float")
assert 4.2 == new_entity
new_entity = gdc.get_property("my-float", float)
assert 4.2 == new_entity
new_entity = gdc.get_property("my-float", dpf.types.double)
assert 4.2 == new_entity

entity = "hello world"
gdc.set_property("my-string", entity)
new_entity = gdc.get_property("my-string")
assert "hello world" == new_entity
new_entity = gdc.get_property("my-string", str)
assert "hello world" == new_entity
new_entity = gdc.get_property("my-string", dpf.types.string)
assert "hello world" == new_entity

entity = dpf.Field(location="phase", nature=dpf.natures.scalar, server=server_type)
gdc.set_property("my-field", entity)
new_entity = gdc.get_property("my-field")
assert isinstance(new_entity, dpf.Field)

new_entity = gdc.get_property("my-field", dpf.Field)
assert isinstance(new_entity, dpf.Field)

new_entity = gdc.get_property("my-field", dpf.types.field)
assert isinstance(new_entity, dpf.Field)


@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, reason="Available for servers >=8.0"
)
def test_get_bytes_generic_data_container(server_type):
gdc = dpf.GenericDataContainer(server=server_type)

entity = "hello world"
gdc.set_property("my-string", entity)
new_entity = gdc.get_property("my-string")
assert "hello world" == new_entity
new_entity = gdc.get_property("my-string", str)
assert "hello world" == new_entity
new_entity = gdc.get_property("my-string", dpf.types.string)
assert "hello world" == new_entity
new_entity = gdc.get_property("my-string", bytes)
assert b"hello world" == new_entity
new_entity = gdc.get_property("my-string", dpf.types.bytes)
assert b"hello world" == new_entity
1 change: 1 addition & 0 deletions tests/test_remote_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def test_remote_workflow_info(local_server):
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_3_0,
reason="Connecting data from different servers is " "supported starting server version 3.0",
)
@pytest.mark.skipif(running_docker, reason="Currently hanging on Docker, under investigation.")
def test_multi_process_local_remote_local_remote_workflow(server_type_remote_process):
files = examples.download_distributed_files(server=server_type_remote_process)
wf = core.Workflow(server=server_type_remote_process)
Expand Down

0 comments on commit e4cb58d

Please sign in to comment.