From 983cd2783cc56b5b6b96d6208e1bf51e8d69c5d7 Mon Sep 17 00:00:00 2001 From: BenYuan Date: Wed, 6 Aug 2025 17:40:15 +0000 Subject: [PATCH 1/2] [FSC-2006] Disable boundary completness and deletion validation --- flow360/component/simulation/primitives.py | 2 + .../user_defined_dynamics.py | 29 +- .../validation_simulation_params.py | 4 + .../simulation/validation/validation_utils.py | 70 ++-- .../params/test_automated_farfield.py | 9 +- .../params/test_validators_params.py | 308 ++++++++++-------- 6 files changed, 226 insertions(+), 196 deletions(-) diff --git a/flow360/component/simulation/primitives.py b/flow360/component/simulation/primitives.py index cb0b1f33e..3aa2a0f9c 100644 --- a/flow360/component/simulation/primitives.py +++ b/flow360/component/simulation/primitives.py @@ -514,6 +514,8 @@ class Surface(_SurfaceEntityBase): private_attribute_sub_components: Optional[List[str]] = pd.Field( [], description="The face ids in geometry that composed into this `Surface`." ) + # pylint: disable=fixme + # TODO: This should be deprecated since it is not very useful or easy to use. private_attribute_potential_issues: List[_SurfaceIssueEnums] = pd.Field( [], description="Issues (not necessarily problems) found on this `Surface` after inspection by " diff --git a/flow360/component/simulation/user_defined_dynamics/user_defined_dynamics.py b/flow360/component/simulation/user_defined_dynamics/user_defined_dynamics.py index b64c7f525..dda3667ce 100644 --- a/flow360/component/simulation/user_defined_dynamics/user_defined_dynamics.py +++ b/flow360/component/simulation/user_defined_dynamics/user_defined_dynamics.py @@ -8,9 +8,6 @@ from flow360.component.simulation.framework.entity_base import EntityList from flow360.component.simulation.framework.expressions import StringExpression from flow360.component.simulation.primitives import Cylinder, GenericVolume, Surface -from flow360.component.simulation.validation.validation_context import ( - get_validation_info, -) from flow360.component.simulation.validation.validation_utils import ( check_deleted_surface_in_entity_list, ) @@ -115,17 +112,19 @@ def ensure_surface_existence(cls, value): @classmethod def ensure_output_surface_existence(cls, value): """Ensure that the output target surface is not a deleted surface""" - validation_info = get_validation_info() - if validation_info is None or validation_info.auto_farfield_method is None: - # validation not necessary now. - return value - # - Check if the surfaces are deleted. - # pylint: disable=protected-access - if isinstance(value, Surface) and value._will_be_deleted_by_mesher( - validation_info.auto_farfield_method - ): - raise ValueError( - f"Boundary `{value.name}` will likely be deleted after mesh generation. Therefore it cannot be used." - ) + # --- Disabled for FXC-2006 + # validation_info = get_validation_info() + # if validation_info is None or validation_info.auto_farfield_method is None: + # # validation not necessary now. + # return value + + # # - Check if the surfaces are deleted. + # # pylint: disable=protected-access + # if isinstance(value, Surface) and value._will_be_deleted_by_mesher( + # validation_info.auto_farfield_method + # ): + # raise ValueError( + # f"Boundary `{value.name}` will likely be deleted after mesh generation. Therefore it cannot be used." + # ) return value diff --git a/flow360/component/simulation/validation/validation_simulation_params.py b/flow360/component/simulation/validation/validation_simulation_params.py index 8c2332e06..3267278e4 100644 --- a/flow360/component/simulation/validation/validation_simulation_params.py +++ b/flow360/component/simulation/validation/validation_simulation_params.py @@ -313,6 +313,10 @@ def _check_complete_boundary_condition_and_unknown_surface( ): # pylint:disable=too-many-branches ## Step 1: Get all boundaries patches from asset cache + return params + + # --- Disabled for FXC-2006 + # pylint: disable=unreachable current_lvls = get_validation_levels() if get_validation_levels() else [] if all(level not in current_lvls for level in (ALL, CASE)): return params diff --git a/flow360/component/simulation/validation/validation_utils.py b/flow360/component/simulation/validation/validation_utils.py index 74dd255df..4912959af 100644 --- a/flow360/component/simulation/validation/validation_utils.py +++ b/flow360/component/simulation/validation/validation_utils.py @@ -7,7 +7,6 @@ from flow360.component.simulation.entity_info import DraftEntityTypes from flow360.component.simulation.primitives import ( - Surface, _SurfaceEntityBase, _VolumeEntityBase, ) @@ -68,25 +67,27 @@ def check_deleted_surface_in_entity_list(value): Check if any boundary is meant to be deleted value--> EntityList """ - validation_info = get_validation_info() - if ( - validation_info is None - or validation_info.auto_farfield_method is None - or validation_info.is_beta_mesher is True - ): - # validation not necessary now. - return value - - # - Check if the surfaces are deleted. - for surface in value.stored_entities: - if isinstance( - surface, Surface - ) and surface._will_be_deleted_by_mesher( # pylint:disable=protected-access - validation_info.auto_farfield_method - ): - raise ValueError( - f"Boundary `{surface.name}` will likely be deleted after mesh generation. Therefore it cannot be used." - ) + # --- Disabled for FXC-2006 + # validation_info = get_validation_info() + # if ( + # validation_info is None + # or validation_info.auto_farfield_method is None + # or validation_info.is_beta_mesher is True + # ): + # # validation not necessary now. + # return value + + # # - Check if the surfaces are deleted. + # for surface in value.stored_entities: + # if isinstance( + # surface, Surface + # ) and surface._will_be_deleted_by_mesher( # pylint:disable=protected-access + # validation_info.auto_farfield_method + # ): + # raise ValueError( + # f"Boundary `{surface.name}` will likely be deleted after mesh generation. " + # "Therefore it cannot be used." + # ) return value @@ -96,19 +97,22 @@ def check_deleted_surface_pair(value): Check if any boundary is meant to be deleted value--> SurfacePair """ - validation_info = get_validation_info() - if validation_info is None or validation_info.auto_farfield_method is None: - # validation not necessary now. - return value - - # - Check if the surfaces are deleted. - for surface in value.pair: - if surface._will_be_deleted_by_mesher( # pylint:disable=protected-access - validation_info.auto_farfield_method - ): - raise ValueError( - f"Boundary `{surface.name}` will likely be deleted after mesh generation. Therefore it cannot be used." - ) + + # --- Disabled for FXC-2006 + # validation_info = get_validation_info() + # if validation_info is None or validation_info.auto_farfield_method is None: + # # validation not necessary now. + # return value + + # # - Check if the surfaces are deleted. + # for surface in value.pair: + # if surface._will_be_deleted_by_mesher( # pylint:disable=protected-access + # validation_info.auto_farfield_method + # ): + # raise ValueError( + # f"Boundary `{surface.name}` will likely be deleted after mesh generation. " + # "Therefore it cannot be used." + # ) return value diff --git a/tests/simulation/params/test_automated_farfield.py b/tests/simulation/params/test_automated_farfield.py index 785f7bce7..723d5917c 100644 --- a/tests/simulation/params/test_automated_farfield.py +++ b/tests/simulation/params/test_automated_farfield.py @@ -190,10 +190,11 @@ def _run_validation(params): # Valid Symmetric but did not use it errors = _run_validation(params) - assert len(errors) == 1 - assert ( - "The following boundaries do not have a boundary condition: symmetric." in errors[0]["msg"] - ) + # --- Disabled for FXC-2006 + # assert len(errors) == 1 + # assert ( + # "The following boundaries do not have a boundary condition: symmetric." in errors[0]["msg"] + # ) params.models.append(SymmetryPlane(surfaces=[farfield.symmetry_planes])) errors = _run_validation(params) diff --git a/tests/simulation/params/test_validators_params.py b/tests/simulation/params/test_validators_params.py index 42fef7d70..ddf8b3fd2 100644 --- a/tests/simulation/params/test_validators_params.py +++ b/tests/simulation/params/test_validators_params.py @@ -582,12 +582,14 @@ def test_BC_geometry(): root_item_type="Geometry", validation_level="All", ) - assert len(errors) == 1 - assert errors[0]["loc"] == ("models", 3, "entities") - assert errors[0]["msg"] == ( - "Value error, Boundary `symmetry11` will likely be deleted after mesh generation. " - "Therefore it cannot be used." - ) + # --- Disabled for FXC-2006 + assert errors is None + # assert len(errors) == 1 + # assert errors[0]["loc"] == ("models", 3, "entities") + # assert errors[0]["msg"] == ( + # "Value error, Boundary `symmetry11` will likely be deleted after mesh generation. " + # "Therefore it cannot be used." + # ) ##### Ghost entities not used ##### with SI_unit_system: @@ -612,11 +614,14 @@ def test_BC_geometry(): root_item_type="Geometry", validation_level="All", ) - assert len(errors) == 1 - assert errors[0]["msg"] == ( - "Value error, The following boundaries do not have a boundary condition: farfield, symmetric." - " Please add them to a boundary condition model in the `models` section." - ) + + # --- Disabled for FXC-2006 + assert errors is None + # assert len(errors) == 1 + # assert errors[0]["msg"] == ( + # "Value error, The following boundaries do not have a boundary condition: farfield, symmetric." + # " Please add them to a boundary condition model in the `models` section." + # ) ##### QUASI 3D METHOD ##### auto_farfield = AutomatedFarfield(name="my_farfield", method="quasi-3d") @@ -646,17 +651,19 @@ def test_BC_geometry(): root_item_type="Geometry", validation_level="All", ) - assert len(errors) == 2 - assert errors[0]["loc"] == ("models", 3, "entities") - assert errors[0]["msg"] == ( - "Value error, Boundary `symmetry11` will likely be deleted after mesh generation. " - "Therefore it cannot be used." - ) - assert errors[1]["loc"] == ("models", 4, "entities") - assert errors[1]["msg"] == ( - "Value error, Boundary `symmetry22` will likely be deleted after mesh generation. " - "Therefore it cannot be used." - ) + # --- Disabled for FXC-2006 + assert errors is None + # assert len(errors) == 2 + # assert errors[0]["loc"] == ("models", 3, "entities") + # assert errors[0]["msg"] == ( + # "Value error, Boundary `symmetry11` will likely be deleted after mesh generation. " + # "Therefore it cannot be used." + # ) + # assert errors[1]["loc"] == ("models", 4, "entities") + # assert errors[1]["msg"] == ( + # "Value error, Boundary `symmetry22` will likely be deleted after mesh generation. " + # "Therefore it cannot be used." + # ) ##### Ghost entities not used ##### auto_farfield = AutomatedFarfield(name="my_farfield", method="quasi-3d") @@ -681,11 +688,13 @@ def test_BC_geometry(): root_item_type="Geometry", validation_level="All", ) - assert len(errors) == 1 - assert errors[0]["msg"] == ( - "Value error, The following boundaries do not have a boundary condition: farfield, " - "symmetric-1, symmetric-2. Please add them to a boundary condition model in the `models` section." - ) + # --- Disabled for FXC-2006 + assert errors is None + # assert len(errors) == 1 + # assert errors[0]["msg"] == ( + # "Value error, The following boundaries do not have a boundary condition: farfield, " + # "symmetric-1, symmetric-2. Please add them to a boundary condition model in the `models` section." + # ) # --------------------------------------------------------# # >>>>>>> Group sides of airfoil as SINGLE boundary <<<<<<< @@ -723,10 +732,12 @@ def test_BC_geometry(): root_item_type="Geometry", validation_level="All", ) - assert len(errors) == 1 - assert errors[0]["msg"] == ( - "Value error, Boundary `symmetry` will likely be deleted after mesh generation. Therefore it cannot be used." - ) + # --- Disabled for FXC-2006 + assert errors is None + # assert len(errors) == 1 + # assert errors[0]["msg"] == ( + # "Value error, Boundary `symmetry` will likely be deleted after mesh generation. Therefore it cannot be used." + # ) def test_incomplete_BC_volume_mesh(): @@ -745,59 +756,62 @@ def test_incomplete_BC_volume_mesh(): ), ) - with pytest.raises( - ValueError, - match=re.escape( - r"The following boundaries do not have a boundary condition: no_bc. Please add them to a boundary condition model in the `models` section." - ), - ): - with ValidationContext(ALL): - with SI_unit_system: - SimulationParams( - meshing=MeshingParams( - defaults=MeshingDefaults( - boundary_layer_first_layer_thickness=1e-10, - surface_max_edge_length=1e-10, - ) - ), - models=[ - Fluid(), - Wall(entities=wall_1), - Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), - SlipWall(entities=[i_exist]), - ], - private_attribute_asset_cache=asset_cache, - ) - with pytest.raises( - ValueError, - match=re.escape( - r"The following boundaries are not known `Surface` entities but appear in the `models` section: plz_dont_do_this." + # --- Disabled for FXC-2006 + # with pytest.raises( + # ValueError, + # match=re.escape( + # r"The following boundaries do not have a boundary condition: no_bc. Please add them to a boundary condition model in the `models` section." + # ), + # ): + with ValidationContext(ALL): + with SI_unit_system: + SimulationParams( + meshing=MeshingParams( + defaults=MeshingDefaults( + boundary_layer_first_layer_thickness=1e-10, + surface_max_edge_length=1e-10, + ) + ), + models=[ + Fluid(), + Wall(entities=wall_1), + Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), + SlipWall(entities=[i_exist]), + ], + private_attribute_asset_cache=asset_cache, + ) + + # --- Disabled for FXC-2006 + # with pytest.raises( + # ValueError, + # match=re.escape( + # r"The following boundaries are not known `Surface` entities but appear in the `models` section: plz_dont_do_this." + # ), + # ): + with ValidationContext( + ALL, + info=ParamsValidationInfo( + param_as_dict={}, + referenced_expressions=[], ), ): - with ValidationContext( - ALL, - info=ParamsValidationInfo( - param_as_dict={}, - referenced_expressions=[], - ), - ): - with SI_unit_system: - SimulationParams( - meshing=MeshingParams( - defaults=MeshingDefaults( - boundary_layer_first_layer_thickness=1e-10, - surface_max_edge_length=1e-10, - ) - ), - models=[ - Fluid(), - Wall(entities=[wall_1]), - Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), - SlipWall(entities=[i_exist]), - SlipWall(entities=[Surface(name="plz_dont_do_this"), no_bc]), - ], - private_attribute_asset_cache=asset_cache, - ) + with SI_unit_system: + SimulationParams( + meshing=MeshingParams( + defaults=MeshingDefaults( + boundary_layer_first_layer_thickness=1e-10, + surface_max_edge_length=1e-10, + ) + ), + models=[ + Fluid(), + Wall(entities=[wall_1]), + Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), + SlipWall(entities=[i_exist]), + SlipWall(entities=[Surface(name="plz_dont_do_this"), no_bc]), + ], + private_attribute_asset_cache=asset_cache, + ) def test_incomplete_BC_surface_mesh(): @@ -850,69 +864,72 @@ def test_incomplete_BC_surface_mesh(): private_attribute_asset_cache=asset_cache, ) - with pytest.raises( - ValueError, - match=re.escape( - r"The following boundaries do not have a boundary condition: no_bc. Please add them to a boundary condition model in the `models` section." + # --- Disabled for FXC-2006 + # with pytest.raises( + # ValueError, + # match=re.escape( + # r"The following boundaries do not have a boundary condition: no_bc. Please add them to a boundary condition model in the `models` section." + # ), + # ): + with ValidationContext( + ALL, + info=ParamsValidationInfo( + param_as_dict={}, + referenced_expressions=[], ), ): - with ValidationContext( - ALL, - info=ParamsValidationInfo( - param_as_dict={}, - referenced_expressions=[], - ), - ): - with SI_unit_system: - SimulationParams( - meshing=MeshingParams( - defaults=MeshingDefaults( - boundary_layer_first_layer_thickness=1e-10, - surface_max_edge_length=1e-10, - ), - volume_zones=[auto_farfield], + with SI_unit_system: + SimulationParams( + meshing=MeshingParams( + defaults=MeshingDefaults( + boundary_layer_first_layer_thickness=1e-10, + surface_max_edge_length=1e-10, ), - models=[ - Fluid(), - Wall(entities=wall_1), - Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), - SlipWall(entities=[i_exist]), - Freestream(entities=auto_farfield.farfield), - ], - private_attribute_asset_cache=asset_cache, - ) - with pytest.raises( - ValueError, - match=re.escape( - r"The following boundaries are not known `Surface` entities but appear in the `models` section: plz_dont_do_this." + volume_zones=[auto_farfield], + ), + models=[ + Fluid(), + Wall(entities=wall_1), + Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), + SlipWall(entities=[i_exist]), + Freestream(entities=auto_farfield.farfield), + ], + private_attribute_asset_cache=asset_cache, + ) + + # --- Disabled for FXC-2006 + # with pytest.raises( + # ValueError, + # match=re.escape( + # r"The following boundaries are not known `Surface` entities but appear in the `models` section: plz_dont_do_this." + # ), + # ): + with ValidationContext( + ALL, + info=ParamsValidationInfo( + param_as_dict={}, + referenced_expressions=[], ), ): - with ValidationContext( - ALL, - info=ParamsValidationInfo( - param_as_dict={}, - referenced_expressions=[], - ), - ): - with SI_unit_system: - SimulationParams( - meshing=MeshingParams( - defaults=MeshingDefaults( - boundary_layer_first_layer_thickness=1e-10, - surface_max_edge_length=1e-10, - ), - volume_zones=[auto_farfield], + with SI_unit_system: + SimulationParams( + meshing=MeshingParams( + defaults=MeshingDefaults( + boundary_layer_first_layer_thickness=1e-10, + surface_max_edge_length=1e-10, ), - models=[ - Fluid(), - Wall(entities=[wall_1]), - Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), - SlipWall(entities=[i_exist]), - Freestream(entities=auto_farfield.farfield), - SlipWall(entities=[Surface(name="plz_dont_do_this"), no_bc]), - ], - private_attribute_asset_cache=asset_cache, - ) + volume_zones=[auto_farfield], + ), + models=[ + Fluid(), + Wall(entities=[wall_1]), + Periodic(surface_pairs=(periodic_1, periodic_2), spec=Translational()), + SlipWall(entities=[i_exist]), + Freestream(entities=auto_farfield.farfield), + SlipWall(entities=[Surface(name="plz_dont_do_this"), no_bc]), + ], + private_attribute_asset_cache=asset_cache, + ) def test_duplicate_entities_in_models(): @@ -1524,11 +1541,14 @@ def test_deleted_surfaces(): root_item_type="Geometry", validation_level="All", ) - assert len(errors) == 1 - assert ( - errors[0]["msg"] == "Value error, Boundary `body0001_face0003` will likely" - " be deleted after mesh generation. Therefore it cannot be used." - ) + + # --- Disabled for FXC-2006 + assert errors is None + # assert len(errors) == 1 + # assert ( + # errors[0]["msg"] == "Value error, Boundary `body0001_face0003` will likely" + # " be deleted after mesh generation. Therefore it cannot be used." + # ) with SI_unit_system: params = SimulationParams( From 2d7d0aab4bf29523d5aa7eca215e693ba22aff7e Mon Sep 17 00:00:00 2001 From: BenYuan Date: Wed, 6 Aug 2025 18:00:51 +0000 Subject: [PATCH 2/2] Fix unit test --- tests/simulation/params/test_validators_params.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/simulation/params/test_validators_params.py b/tests/simulation/params/test_validators_params.py index ddf8b3fd2..85b3d78db 100644 --- a/tests/simulation/params/test_validators_params.py +++ b/tests/simulation/params/test_validators_params.py @@ -1575,12 +1575,14 @@ def test_deleted_surfaces(): root_item_type="Geometry", validation_level="All", ) - assert len(errors) == 1 - assert ( - errors[0]["msg"] == "Value error, Boundary `body0001_face0004` will likely" - " be deleted after mesh generation. Therefore it cannot be used." - ) - assert errors[0]["loc"] == ("models", 2, "entity_pairs") + # --- Disabled for FXC-2006 + assert errors is None + # assert len(errors) == 1 + # assert ( + # errors[0]["msg"] == "Value error, Boundary `body0001_face0004` will likely" + # " be deleted after mesh generation. Therefore it cannot be used." + # ) + # assert errors[0]["loc"] == ("models", 2, "entity_pairs") def test_validate_liquid_operating_condition():