Skip to content

Commit

Permalink
Added tri connectivity property for FE zones with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lamkina committed Nov 8, 2024
1 parent 449c9b9 commit c2baf7c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions baseclasses/utils/tecplotIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ def __init__(
def nElements(self) -> int:
return self.connectivity.shape[0]

@property
def triConnectivity(self) -> npt.NDArray:
if self.zoneType == ZoneType.FETRIANGLE:
return self.connectivity
elif self.zoneType == ZoneType.FEQUADRILATERAL:
return np.row_stack((self.connectivity[:, [0, 1, 2]], self.connectivity[:, [0, 2, 3]]))
else:
raise TypeError(f"'triConnectivity' not supported for {self.zoneType.name} zone type.")

def _validateZoneType(self) -> None:
supportedZones = [zone.name for zone in ZoneType if zone.name != "ORDERED"]
if isinstance(self.zoneType, str):
Expand Down
59 changes: 59 additions & 0 deletions tests/test_tecplotIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,62 @@ def test_BinaryReadWriteExternal(self):
title, zones = readTecplot(self.externalFileBinary)
except Exception as e:
self.fail(f"Reading external binary file {self.externalFileBinary} failed with error: {e}")

def test_TriToTriConn(self):
# Create a fe ordered tri zone
ni, nj = 10, 10
nodes, connectivity = createTriGrid(ni, nj)
zone = TecplotFEZone(
"TriGrid", {"X": nodes[:, 0], "Y": nodes[:, 1]}, connectivity, zoneType=ZoneType.FETRIANGLE
)

triConn = zone.triConnectivity

np.testing.assert_array_equal(triConn, zone.connectivity)

def test_QuadToTriConn(self):
# Create a fe ordered quad zone
ni, nj = 10, 10
nodes, connectivity = createQuadGrid(ni, nj)
zone = TecplotFEZone(
"QuadGrid", {"X": nodes[:, 0], "Y": nodes[:, 1]}, connectivity, zoneType=ZoneType.FEQUADRILATERAL
)

triConn = zone.triConnectivity

self.assertEqual(triConn.shape, (zone.nElements * 2, 3))

def test_TriConnBadZoneType(self):
# Create an line seg zone
ni = 10
nodes, connectivity = createLineSegGrid(ni)
zone = TecplotFEZone("LineSeg", {"X": nodes[:, 0], "Y": nodes[:, 1]}, connectivity, zoneType=ZoneType.FELINESEG)

with self.assertRaises(TypeError):
triConn = zone.triConnectivity

# Create a tet zone
ni, nj, nk = 10, 10, 10
nodes, connectivity = createTetGrid(ni, nj, nk)
zone = TecplotFEZone(
"TetGrid",
{"X": nodes[:, 0], "Y": nodes[:, 1], "Z": nodes[:, 2]},
connectivity,
zoneType=ZoneType.FETETRAHEDRON,
)

with self.assertRaises(TypeError):
triConn = zone.triConnectivity

# Create a brick zone
ni, nj, nk = 10, 10, 10
nodes, connectivity = createBrickGrid(ni, nj, nk)
zone = TecplotFEZone(
"BrickGrid",
{"X": nodes[:, 0], "Y": nodes[:, 1], "Z": nodes[:, 2]},
connectivity,
zoneType=ZoneType.FEBRICK,
)

with self.assertRaises(TypeError):
triConn = zone.triConnectivity

0 comments on commit c2baf7c

Please sign in to comment.