Skip to content

Commit 25706ce

Browse files
fix(): planar_face_tolerance might be missing and causing validation to fail (#1344)
* fix(): planar_face_tolerance might be missing and causing validaiton to fail * ensure valid param * Fixed test
1 parent 7f40ddc commit 25706ce

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

flow360/component/simulation/framework/updater.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from flow360.log import log
2525
from flow360.version import __version__
2626

27+
DEFAULT_PLANAR_FACE_TOLERANCE = 1e-6
28+
2729

2830
def _to_24_11_1(params_as_dict):
2931
# Check and remove the 'meshing' node if conditions are met
@@ -284,6 +286,17 @@ def _to_25_6_2(params_as_dict):
284286
return params_as_dict
285287

286288

289+
def _to_25_6_4(params_as_dict):
290+
if params_as_dict.get("meshing") is None:
291+
return params_as_dict
292+
if "defaults" not in params_as_dict["meshing"]:
293+
return params_as_dict
294+
meshing_defaults = params_as_dict["meshing"].get("defaults", {})
295+
if meshing_defaults.get("planar_face_tolerance") is None:
296+
meshing_defaults["planar_face_tolerance"] = DEFAULT_PLANAR_FACE_TOLERANCE
297+
return params_as_dict
298+
299+
287300
VERSION_MILESTONES = [
288301
(Flow360Version("24.11.1"), _to_24_11_1),
289302
(Flow360Version("24.11.7"), _to_24_11_7),
@@ -292,7 +305,8 @@ def _to_25_6_2(params_as_dict):
292305
(Flow360Version("25.2.1"), _to_25_2_1),
293306
(Flow360Version("25.2.3"), _to_25_2_3),
294307
(Flow360Version("25.4.1"), _to_25_4_1),
295-
(Flow360Version("25.6.4"), _to_25_6_2),
308+
(Flow360Version("25.6.2"), _to_25_6_2),
309+
(Flow360Version("25.6.4"), _to_25_6_4),
296310
] # A list of the Python API version tuple with there corresponding updaters.
297311

298312

flow360/component/simulation/meshing_param/params.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import flow360.component.simulation.units as u
99
from flow360.component.simulation.framework.base_model import Flow360BaseModel
10+
from flow360.component.simulation.framework.updater import DEFAULT_PLANAR_FACE_TOLERANCE
1011
from flow360.component.simulation.meshing_param.edge_params import SurfaceEdgeRefinement
1112
from flow360.component.simulation.meshing_param.face_params import (
1213
BoundaryLayer,
@@ -105,7 +106,7 @@ class MeshingDefaults(Flow360BaseModel):
105106
)
106107

107108
planar_face_tolerance: pd.NonNegativeFloat = pd.Field(
108-
1e-6,
109+
DEFAULT_PLANAR_FACE_TOLERANCE,
109110
description="Tolerance used for detecting planar faces in the input surface mesh / geometry"
110111
" that need to be remeshed, such as symmetry planes."
111112
" This tolerance is non-dimensional, and represents a distance"

flow360/component/simulation/models/surface_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from flow360.component.simulation.validation.validation_utils import (
4343
check_deleted_surface_in_entity_list,
4444
check_deleted_surface_pair,
45-
check_symmetric_boundary_existence_for_inhouse,
45+
check_symmetric_boundary_existence,
4646
)
4747

4848
# pylint: disable=fixme
@@ -57,7 +57,7 @@ class EntityListAllowingGhost(EntityList): # Define EntityList to include valid
5757
@classmethod
5858
def ghost_entity_validator(cls, value):
5959
"""Run all validators"""
60-
return check_symmetric_boundary_existence_for_inhouse(value)
60+
return check_symmetric_boundary_existence(value)
6161

6262

6363
class BoundaryBase(Flow360BaseModel, metaclass=ABCMeta):

flow360/component/simulation/validation/validation_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def check_deleted_surface_pair(value):
117117
return value
118118

119119

120-
def check_symmetric_boundary_existence_for_inhouse(stored_entities):
120+
def check_symmetric_boundary_existence(stored_entities):
121121
"""Check according to the criteria if the symmetric plane exists."""
122122
validation_info = get_validation_info()
123123

tests/simulation/service/test_services_v2.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,7 @@ def test_front_end_JSON_with_multi_constructor():
985985
def test_generate_process_json():
986986
params_data = {
987987
"meshing": {
988-
"defaults": {
989-
# "boundary_layer_first_layer_thickness": "1*m",
990-
# "surface_max_edge_length": "1*m",
991-
},
988+
"defaults": {},
992989
"volume_zones": [
993990
{
994991
"method": "auto",
@@ -1062,7 +1059,7 @@ def test_generate_process_json():
10621059
with pytest.raises(
10631060
ValueError,
10641061
match=re.escape(
1065-
"[{'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'}]"
1062+
"[{'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'}]"
10661063
),
10671064
):
10681065
res1, res2, res3 = services.generate_process_json(

tests/simulation/test_updater.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def test_updater_to_25_6_2():
494494
def _update_to_25_6_2(pre_update_param_as_dict, version_from):
495495
params_new = updater(
496496
version_from=version_from,
497-
version_to=f"25.6.4",
497+
version_to=f"25.6.2",
498498
params_as_dict=pre_update_param_as_dict,
499499
)
500500
return params_new
@@ -711,3 +711,21 @@ def test_deserialization_with_updater():
711711
validated_by=ValidationCalledBy.LOCAL,
712712
validation_level=ALL,
713713
)
714+
715+
716+
def test_updater_to_25_6_4():
717+
with open("../data/simulation/simulation_pre_25_4_1.json", "r") as fp:
718+
params_as_dict = json.load(fp)
719+
720+
params_new = updater(
721+
version_from="25.4.0b1",
722+
version_to=f"25.6.4",
723+
params_as_dict=params_as_dict,
724+
)
725+
assert params_new["meshing"]["defaults"]["planar_face_tolerance"] == 1e-6
726+
params_new, _, _ = validate_model(
727+
params_as_dict=params_new,
728+
validated_by=ValidationCalledBy.LOCAL,
729+
root_item_type="Geometry",
730+
)
731+
assert params_new

0 commit comments

Comments
 (0)