Skip to content

Commit

Permalink
change connectivity format coming from simba (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariostieriansys authored Jan 27, 2025
1 parent 8eed26a commit 87f77d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
43 changes: 19 additions & 24 deletions src/ansys/pyensight/core/dvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,37 +627,30 @@ def _split_list(lst: Union[List[int], List[float]], num_parts: int):
start = end
return parts

def _disassemble_simba_connectivity(self, faces):
i = 0
vertices_per_face = []
connectivity_1d = []
indices = []
while i < len(faces):
indices.append(i)
i += faces[i] + 1
mask = numpy.zeros(faces.shape, dtype=bool)
mask[indices] = True
vertices_per_face = numpy.array(faces[mask])
connectivity_1d = numpy.array(faces[~mask])
connectivity_split = numpy.split(connectivity_1d, numpy.cumsum(vertices_per_face[:-1]))
all_same = numpy.all(numpy.array(vertices_per_face) == vertices_per_face[0])
return connectivity_split, vertices_per_face, all_same

def send_connectivity(self, part_id, faces: Union[List, numpy.ndarray], ghost=False):
def send_connectivity(
self,
part_id,
offsets: Union[List, numpy.ndarray],
faces: Union[List, numpy.ndarray],
ghost=False,
):
"""Send the connectivity data for the input part.
The data will be used for building an element block in DVS.
The connectivity array will be split among all the available ranks.
The data are assumed in the following format:
The faces data are assumed in the following format:
[n, i1, i2, ...in, m, j1, j2, ...jn, p, k1, k2, ...kp, ...]
i.e. the first element declares how many vertices are available on the face,
then the following elements will be the indices of the vertices for the specific
face, and so on.
The offsets data instead:
[0, n, n+m, n+m+p ....]
The faces list indicates the IDs of the vertices of each face, in order.
The offsets lists indicates the index where to find a specific face.
Parameters
----------
part_id: int
the part to define the connectivity for
offsets: List[int] or numpy array
the offsets values. The format is described above.
faces: List[int] or numpy array
the connectivity value. The format is described above.
ghost: bool
Expand All @@ -671,10 +664,12 @@ def send_connectivity(self, part_id, faces: Union[List, numpy.ndarray], ghost=Fa
)
if not isinstance(faces, numpy.ndarray):
faces = numpy.array(faces)
connectivity_split, vertices_per_face, all_same = self._disassemble_simba_connectivity(
faces
)
if not isinstance(offsets, numpy.ndarray):
offsets = numpy.array(offsets)
vertices_per_face = numpy.diff(offsets)
connectivity_split = numpy.split(faces, numpy.cumsum(vertices_per_face[:-1]))
elem_type = self.ELEMTYPE_N_SIDED_POLYGON
all_same = numpy.all(numpy.array(vertices_per_face) == vertices_per_face[0])
if all_same:
num_vertices = vertices_per_face[0]
_elem_type = self._elem_type_map.get(num_vertices)
Expand Down
6 changes: 4 additions & 2 deletions tests/example_tests/test_dvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def test_dvs_data(tmpdir, pytestconfig: pytest.Config):
'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)
num_tris = int(update_handler._conn.size / 3)
offsets = numpy.full(num_tris, 3)
offsets = numpy.concatenate([[0], numpy.cumsum(offsets)])
dvs.start_dvs_servers(3, 0, 1)
dvs.start_dvs_clients("TestDatasetSimbaFormat")
dvs.begin_initialization()
Expand All @@ -109,7 +111,7 @@ def test_dvs_data(tmpdir, pytestconfig: pytest.Config):
)
dvs.end_initialization()
dvs.begin_updates(session.ensight.objs.core.TIMEVALUES[0][1])
dvs.send_connectivity(part.PARTNUMBER, conn)
dvs.send_connectivity(part.PARTNUMBER, offsets, update_handler._conn)
dvs.send_coordinates(part.PARTNUMBER, update_handler._coords)
dvs.send_variable_data(variable.ID, part.PARTNUMBER, update_handler._tcoords)
dvs.end_updates()
Expand Down

0 comments on commit 87f77d2

Please sign in to comment.