diff --git a/flow360/component/simulation/framework/updater.py b/flow360/component/simulation/framework/updater.py index 7086efd1a..f8ce82586 100644 --- a/flow360/component/simulation/framework/updater.py +++ b/flow360/component/simulation/framework/updater.py @@ -24,6 +24,8 @@ from flow360.log import log from flow360.version import __version__ +DEFAULT_PLANAR_FACE_TOLERANCE = 1e-6 + def _to_24_11_1(params_as_dict): # Check and remove the 'meshing' node if conditions are met @@ -284,6 +286,17 @@ def _to_25_6_2(params_as_dict): return params_as_dict +def _to_25_6_4(params_as_dict): + if params_as_dict.get("meshing") is None: + return params_as_dict + if "defaults" not in params_as_dict["meshing"]: + return params_as_dict + meshing_defaults = params_as_dict["meshing"].get("defaults", {}) + if meshing_defaults.get("planar_face_tolerance") is None: + meshing_defaults["planar_face_tolerance"] = DEFAULT_PLANAR_FACE_TOLERANCE + return params_as_dict + + VERSION_MILESTONES = [ (Flow360Version("24.11.1"), _to_24_11_1), (Flow360Version("24.11.7"), _to_24_11_7), @@ -292,7 +305,8 @@ def _to_25_6_2(params_as_dict): (Flow360Version("25.2.1"), _to_25_2_1), (Flow360Version("25.2.3"), _to_25_2_3), (Flow360Version("25.4.1"), _to_25_4_1), - (Flow360Version("25.6.4"), _to_25_6_2), + (Flow360Version("25.6.2"), _to_25_6_2), + (Flow360Version("25.6.4"), _to_25_6_4), ] # A list of the Python API version tuple with there corresponding updaters. diff --git a/flow360/component/simulation/meshing_param/params.py b/flow360/component/simulation/meshing_param/params.py index 99c9a4d61..d810ed2a2 100644 --- a/flow360/component/simulation/meshing_param/params.py +++ b/flow360/component/simulation/meshing_param/params.py @@ -7,6 +7,7 @@ import flow360.component.simulation.units as u from flow360.component.simulation.framework.base_model import Flow360BaseModel +from flow360.component.simulation.framework.updater import DEFAULT_PLANAR_FACE_TOLERANCE from flow360.component.simulation.meshing_param.edge_params import SurfaceEdgeRefinement from flow360.component.simulation.meshing_param.face_params import ( BoundaryLayer, @@ -105,7 +106,7 @@ class MeshingDefaults(Flow360BaseModel): ) planar_face_tolerance: pd.NonNegativeFloat = pd.Field( - 1e-6, + DEFAULT_PLANAR_FACE_TOLERANCE, description="Tolerance used for detecting planar faces in the input surface mesh / geometry" " that need to be remeshed, such as symmetry planes." " This tolerance is non-dimensional, and represents a distance" diff --git a/flow360/component/simulation/models/surface_models.py b/flow360/component/simulation/models/surface_models.py index 1dac5e4b1..8dae817c5 100644 --- a/flow360/component/simulation/models/surface_models.py +++ b/flow360/component/simulation/models/surface_models.py @@ -42,7 +42,7 @@ from flow360.component.simulation.validation.validation_utils import ( check_deleted_surface_in_entity_list, check_deleted_surface_pair, - check_symmetric_boundary_existence_for_inhouse, + check_symmetric_boundary_existence, ) # pylint: disable=fixme @@ -57,7 +57,7 @@ class EntityListAllowingGhost(EntityList): # Define EntityList to include valid @classmethod def ghost_entity_validator(cls, value): """Run all validators""" - return check_symmetric_boundary_existence_for_inhouse(value) + return check_symmetric_boundary_existence(value) class BoundaryBase(Flow360BaseModel, metaclass=ABCMeta): diff --git a/flow360/component/simulation/validation/validation_utils.py b/flow360/component/simulation/validation/validation_utils.py index 6d6558c1e..3881eb3f2 100644 --- a/flow360/component/simulation/validation/validation_utils.py +++ b/flow360/component/simulation/validation/validation_utils.py @@ -117,7 +117,7 @@ def check_deleted_surface_pair(value): return value -def check_symmetric_boundary_existence_for_inhouse(stored_entities): +def check_symmetric_boundary_existence(stored_entities): """Check according to the criteria if the symmetric plane exists.""" validation_info = get_validation_info() diff --git a/tests/simulation/service/test_services_v2.py b/tests/simulation/service/test_services_v2.py index add76f3c7..392c4737f 100644 --- a/tests/simulation/service/test_services_v2.py +++ b/tests/simulation/service/test_services_v2.py @@ -985,10 +985,7 @@ def test_front_end_JSON_with_multi_constructor(): def test_generate_process_json(): params_data = { "meshing": { - "defaults": { - # "boundary_layer_first_layer_thickness": "1*m", - # "surface_max_edge_length": "1*m", - }, + "defaults": {}, "volume_zones": [ { "method": "auto", @@ -1062,7 +1059,7 @@ def test_generate_process_json(): with pytest.raises( ValueError, match=re.escape( - "[{'type': 'missing', 'loc': ('meshing', 'surface_max_edge_length'), 'msg': 'Field required', 'input': None, 'ctx': {'relevant_for': ['SurfaceMesh']}, 'url': 'https://errors.pydantic.dev/2.11/v/missing'}]" + "[{'type': 'missing', 'loc': ('meshing', 'defaults', 'surface_max_edge_length'), 'msg': 'Field required', 'input': None, 'ctx': {'relevant_for': ['SurfaceMesh']}, 'url': 'https://errors.pydantic.dev/2.11/v/missing'}]" ), ): res1, res2, res3 = services.generate_process_json( diff --git a/tests/simulation/test_updater.py b/tests/simulation/test_updater.py index 01cf3e105..f917bc8b5 100644 --- a/tests/simulation/test_updater.py +++ b/tests/simulation/test_updater.py @@ -494,7 +494,7 @@ def test_updater_to_25_6_2(): def _update_to_25_6_2(pre_update_param_as_dict, version_from): params_new = updater( version_from=version_from, - version_to=f"25.6.4", + version_to=f"25.6.2", params_as_dict=pre_update_param_as_dict, ) return params_new @@ -711,3 +711,21 @@ def test_deserialization_with_updater(): validated_by=ValidationCalledBy.LOCAL, validation_level=ALL, ) + + +def test_updater_to_25_6_4(): + with open("../data/simulation/simulation_pre_25_4_1.json", "r") as fp: + params_as_dict = json.load(fp) + + params_new = updater( + version_from="25.4.0b1", + version_to=f"25.6.4", + params_as_dict=params_as_dict, + ) + assert params_new["meshing"]["defaults"]["planar_face_tolerance"] == 1e-6 + params_new, _, _ = validate_model( + params_as_dict=params_new, + validated_by=ValidationCalledBy.LOCAL, + root_item_type="Geometry", + ) + assert params_new