Skip to content

Commit 0832d3f

Browse files
rundajibenflexcompute
authored andcommitted
Add GhostCircularPlane to GhostSurfacePair (#1564)
* add GhostCircularPlane to GhostSurfacePair * update unit test * code style clean * add ClassVar to GhostSurfaceType * Removed GhostSurfaceTypes --------- Co-authored-by: benflexcompute <ben@flexcompute.com> Co-authored-by: Ben <106089368+benflexcompute@users.noreply.github.com>
1 parent c4ebc5b commit 0832d3f

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

flow360/component/simulation/entity_info.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@
4545
pd.Field(discriminator="private_attribute_entity_type_name"),
4646
]
4747

48-
GhostSurfaceTypes = Annotated[
49-
Union[GhostSphere, GhostCircularPlane],
50-
pd.Field(discriminator="private_attribute_entity_type_name"),
51-
]
52-
5348

5449
class EntityInfoModel(Flow360BaseModel, metaclass=ABCMeta):
5550
"""Base model for asset entity info JSON"""
5651

5752
# entities that appear in simulation JSON but did not appear in EntityInfo)
5853
draft_entities: List[DraftEntityTypes] = pd.Field([])
59-
ghost_entities: List[GhostSurfaceTypes] = pd.Field([])
54+
ghost_entities: List[
55+
Annotated[
56+
Union[GhostSphere, GhostCircularPlane],
57+
pd.Field(discriminator="private_attribute_entity_type_name"),
58+
]
59+
] = pd.Field([])
6060

6161
@abstractmethod
6262
def get_boundaries(self, attribute_name: str = None) -> list[Surface]:

flow360/component/simulation/primitives.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,17 @@ class GhostSurfacePair(SurfacePairBase):
747747
Represents a pair of ghost surfaces.
748748
749749
Attributes:
750-
pair (Tuple[GhostSurface, GhostSurface]): A tuple containing two GhostSurface objects representing the pair.
750+
pair (Tuple[GhostSurfaceType, GhostSurfaceType]):
751+
A tuple containing two GhostSurfaceType objects representing the pair.
752+
GhostSurface is for Python API, GhostCircularPlane is for Web UI.
751753
"""
752754

753-
pair: Tuple[GhostSurface, GhostSurface]
755+
GhostSurfaceType: ClassVar[type] = Annotated[
756+
Union[GhostSurface, GhostCircularPlane],
757+
pd.Field(discriminator="private_attribute_entity_type_name"),
758+
]
759+
760+
pair: Tuple[GhostSurfaceType, GhostSurfaceType]
754761

755762

756763
@final

tests/simulation/params/test_validators_params.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
GhostCircularPlane,
9393
GhostSphere,
9494
GhostSurface,
95-
GhostSurfacePair,
9695
Surface,
9796
SurfacePrivateAttributes,
9897
)
@@ -2255,7 +2254,7 @@ def test_check_custom_volume_in_volume_zones():
22552254

22562255

22572256
def test_ghost_surface_pair_requires_quasi_3d_periodic_farfield():
2258-
# Create two dummy ghost surfaces
2257+
# Create two dummy ghost surfaces (Python workflow)
22592258
periodic_1 = GhostSurface(name="periodic_1")
22602259
periodic_2 = GhostSurface(name="periodic_2")
22612260

@@ -2268,3 +2267,17 @@ def test_ghost_surface_pair_requires_quasi_3d_periodic_farfield():
22682267
# Case 2: Farfield method IS "quasi-3d-periodic" → should pass
22692268
with SI_unit_system, ValidationContext(CASE, quasi_3d_periodic_farfield_context):
22702269
Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational())
2270+
2271+
# Create two dummy ghost circular plane (Web UI workflow)
2272+
periodic_1 = GhostCircularPlane(name="periodic_1")
2273+
periodic_2 = GhostCircularPlane(name="periodic_2")
2274+
2275+
# Case 3: Farfield method NOT "quasi-3d-periodic" → should raise ValueError
2276+
with SI_unit_system, ValidationContext(CASE, quasi_3d_farfield_context), pytest.raises(
2277+
ValueError, match="Farfield type must be 'quasi-3d-periodic' when using GhostSurfacePair."
2278+
):
2279+
Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational())
2280+
2281+
# Case 4: Farfield method IS "quasi-3d-periodic" → should pass
2282+
with SI_unit_system, ValidationContext(CASE, quasi_3d_periodic_farfield_context):
2283+
Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational())

0 commit comments

Comments
 (0)