Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
mariostieriansys committed Dec 9, 2024
1 parent cf016d3 commit 5917387
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions tests/example_tests/test_dvs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
import threading
import time

from ansys.pyensight.core import DockerLauncher, LocalLauncher
from ansys.pyensight.core.dvs import DVS
from ansys.pyensight.core.utils.dsg_server import UpdateHandler, DSGSession
import threading
import time
from ansys.pyensight.core.utils.dsg_server import DSGSession, UpdateHandler
import numpy
import pytest


def handle_update(dsg_link):
dsg_link.start()
Expand All @@ -15,38 +16,44 @@ def handle_update(dsg_link):
dsg_link.end()
dsg_link._callback_handler.shutdown()


class LocalUpdateHandler(UpdateHandler):
def __init__(self):
super().__init__()
self._conn = None
self._coords = None
self._tcoords = None

def finalize_part(self, part):
vals = super().finalize_part(part)
self._conn = part.conn_tris
self._coords = part.coords
self._tcoords = part.tcoords
return vals


def wait_for_data(handler):
available = False
start = time.time()
while not available and time.time() - start < 60:
if handler._conn is not None and handler._coords is not None and handler._tcoords is not None:
if (
handler._conn is not None
and handler._coords is not None
and handler._tcoords is not None
):
available = True
time.sleep(0.5)
return available


def build_numpy_conn_simba_format(conn):
replacement = 3
num_insertions = int(conn.size / replacement)
new_values = numpy.full(num_insertions, replacement)
face_array = numpy.insert(
conn, numpy.arange(0, int(conn.size), replacement), new_values
)
face_array = numpy.insert(conn, numpy.arange(0, int(conn.size), replacement), new_values)
return face_array


def test_dvs_data(tmpdir, pytestconfig: pytest.Config):
data_dir = tmpdir.mkdir("datadir")
use_local = pytestconfig.getoption("use_local_launcher")
Expand All @@ -55,8 +62,8 @@ def test_dvs_data(tmpdir, pytestconfig: pytest.Config):
else:
launcher = DockerLauncher(data_directory=data_dir, use_dev=True)
session = launcher.start()
cas_file = session.download_pyansys_example("mixing_elbow.cas.h5","pyfluent/mixing_elbow")
dat_file = session.download_pyansys_example("mixing_elbow.dat.h5","pyfluent/mixing_elbow")
cas_file = session.download_pyansys_example("mixing_elbow.cas.h5", "pyfluent/mixing_elbow")
dat_file = session.download_pyansys_example("mixing_elbow.dat.h5", "pyfluent/mixing_elbow")
session.load_data(cas_file, result_file=dat_file)
dvs = None
if use_local:
Expand All @@ -65,11 +72,11 @@ def test_dvs_data(tmpdir, pytestconfig: pytest.Config):
dvs = DVS(session=session)
update_handler = LocalUpdateHandler()
link = DSGSession(
port = session._grpc_port,
port=session._grpc_port,
host=session.hostname,
security_code=session.secret_key,
vrmode=False,
handler= update_handler
handler=update_handler,
)
dsg_thread = threading.Thread(target=handle_update, args=(link,))
dsg_thread.start()
Expand All @@ -79,7 +86,9 @@ def test_dvs_data(tmpdir, pytestconfig: pytest.Config):
part.COLORBYPALETTE = "Static_Pressure"
variable = session.ensight.objs.core.VARIABLES.find("Static_Pressure")[0]
session.cmd("import enspyqtgui_int", do_eval=False)
session.cmd('enspyqtgui_int.dynamic_scene_graph_command("dynamicscenegraph://localhost/client/update")')
session.cmd(
'enspyqtgui_int.dynamic_scene_graph_command("dynamicscenegraph://localhost/client/update")'
)
assert wait_for_data(update_handler)
conn = build_numpy_conn_simba_format(update_handler._conn)
dvs.start_dvs_servers(3, 0, 1)
Expand All @@ -88,21 +97,19 @@ def test_dvs_data(tmpdir, pytestconfig: pytest.Config):
dvs.begin_updates(session.ensight.objs.core.TIMEVALUES[0][1])
dvs.send_connectivity(part.PARTNUMBER, conn)
dvs.send_coordinates(part.PARTNUMBER, update_handler._coords)
var_location = dvs.LOCATION_ELEMENT if variable.LOCATION == session.ensight.objs.enums.ENS_VAR_ELEM else dvs.LOCATION_NODE
var_location = (
dvs.LOCATION_ELEMENT
if variable.LOCATION == session.ensight.objs.enums.ENS_VAR_ELEM
else dvs.LOCATION_NODE
)
var_type = dvs.VARTYPE_SCALAR
dvs.create_variable(
variable.ID,
variable.DESCRIPTION,
variable.ID,
variable.DESCRIPTION,
var_type,
var_location,
variable.ENS_UNITS_DIMS,
variable.ENS_UNITS_LABEL,
variable.metadata
variable.metadata,
)
dvs.send_variable_data(variable.ID, part.PARTNUMBER, update_handler._tcoords)






0 comments on commit 5917387

Please sign in to comment.