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

Add a test for USERD case file reader #502

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions src/ansys/pyensight/core/libuserd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ class LibUserd(object):

Parameters
----------
ansys_installation
ansys_installation : str
Optional location to search for an Ansys software installation.

Examples
Expand Down Expand Up @@ -1298,8 +1298,8 @@ def _launch_enshell(self) -> None:
)
self._cei_home = self._enshell.cei_home()
self._ansys_version = self._enshell.ansys_version()
print("CEI_HOME=", self._cei_home)
print("Ansys Version=", self._ansys_version)
# print("CEI_HOME=", self._cei_home)
# print("Ansys Version=", self._ansys_version)
grpc_port = self._service_host_port["grpc_private"][1]
ensight_args = f"-grpc_server {grpc_port}"
container_env_str = f"ENSIGHT_SECURITY_TOKEN={self._security_token}\n"
Expand Down Expand Up @@ -1695,7 +1695,7 @@ def nodes_per_element(self, element_type: int) -> int:

Parameters
----------
element_type
element_type : int
The element type: ElementType enum value

Returns
Expand All @@ -1720,7 +1720,7 @@ def element_is_ghost(self, element_type: int) -> bool:

Parameters
----------
element_type
element_type : int
The element type: ElementType enum value

Returns
Expand All @@ -1743,7 +1743,7 @@ def element_is_zoo(self, element_type: int) -> bool:

Parameters
----------
element_type
element_type : int
The element type: ElementType enum value

Returns
Expand All @@ -1766,7 +1766,7 @@ def element_is_nsided(self, element_type: int) -> bool:

Parameters
----------
element_type
element_type : int
The element type: ElementType enum value

Returns
Expand All @@ -1789,7 +1789,7 @@ def element_is_nfaced(self, element_type: int) -> bool:

Parameters
----------
element_type
element_type : int
The element type: ElementType enum value

Returns
Expand Down Expand Up @@ -1827,13 +1827,26 @@ def number_of_simple_element_types(self) -> int:
raise self.libuserd_exception(e)
return ret.result

def initialize(self) -> None:
def initialize(self, number_of_ranks: int = 0) -> None:
"""
This call initializes the libuserd system. It causes the library to scan for available
readers and set up any required reduction engine bits. It can only be called once.

Parameters
----------
number_of_ranks : int, optional
The degree of I/O parallelism to read data with. Zero is serial I/O. Note: this
option is not currently implemented and 0 should be used.
"""
self.connect_check()
pb = libuserd_pb2.Libuserd_initializeRequest()
if number_of_ranks:
self._number_of_ranks = number_of_ranks
try:
pb.parallel_node_count = number_of_ranks
except Exception:
# This exception is allowed to support older .proto versions
pass
try:
_ = self.stub.Libuserd_initialize(pb, metadata=self.metadata())
except grpc.RpcError as e:
Expand Down Expand Up @@ -1866,10 +1879,10 @@ def query_format(self, name1: str, name2: str = "") -> List["ReaderInfo"]:

Parameters
----------
name1
name1 : str
Primary input filename

name2
name2 : str
Optional, secondary input filename

Returns
Expand Down Expand Up @@ -1976,11 +1989,11 @@ def _download_files(uri: str, pathname: str, folder: bool = False):
Parameters:
----------

uri: str
uri : str
The uri to get files from
pathname: str
pathname : str
The location were to save the files. It could be either a file or a folder.
folder: bool
folder : bool
True if the uri will server files from a directory. In this case,
pathname will be used as the directory were to save the files.
"""
Expand Down
29 changes: 29 additions & 0 deletions tests/example_tests/test_libuserd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from ansys.pyensight.core.libuserd import LibUserd
import numpy
import pytest
Expand Down Expand Up @@ -76,3 +78,30 @@ def test_libuserd_synthetic_time(tmpdir, pytestconfig: pytest.Config):
assert not numpy.array_equal(centroid_5, centroid_0)

libuserd.shutdown()


def test_libuserd_userd_case(tmpdir, pytestconfig: pytest.Config):
data_dir = tmpdir.mkdir("datadir")
use_local = pytestconfig.getoption("use_local_launcher")
if use_local:
libuserd = LibUserd()
else:
libuserd = LibUserd(use_docker=True, use_dev=True, data_directory=data_dir)
libuserd.initialize()
readers = libuserd.query_format("example.case")
assert len(readers) == 1
assert readers[0].name == "USERD EnSight Case"

casedir = libuserd.download_pyansys_example("RC_Plane", "pyensight", folder=True)
casefile = os.path.join(casedir, "extra300_RC_Plane_nodal.case")

readers = libuserd.query_format(casefile)
data = readers[0].read_dataset(casefile)

assert len(data.parts()) == 15
assert len(data.variables()) == 6
assert len(data.timevalues()) == 1
assert data.variables()[0].unit_label == "Pa"
assert data.variables()[2].unit_label == "s^-1'"

libuserd.shutdown()
Loading