From 97c45fc9edb6f0437a8f7545a8f7583e3f14d665 Mon Sep 17 00:00:00 2001 From: Runda Ji Date: Wed, 12 Nov 2025 12:02:29 -0500 Subject: [PATCH] add relative size to translator --- .../translator/volume_meshing_translator.py | 3 ++- ...to_json_legacy_farfield_relative_size.json | 14 +++++++++++ .../test_volume_meshing_translator.py | 24 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/simulation/translator/ref/volume_meshing/ref_param_to_json_legacy_farfield_relative_size.json diff --git a/flow360/component/simulation/translator/volume_meshing_translator.py b/flow360/component/simulation/translator/volume_meshing_translator.py index 0f0a663bd..b757fe7c9 100644 --- a/flow360/component/simulation/translator/volume_meshing_translator.py +++ b/flow360/component/simulation/translator/volume_meshing_translator.py @@ -278,7 +278,8 @@ def get_volume_meshing_json(input_params: SimulationParams, mesh_units): if isinstance(zone, AutomatedFarfield): translated["farfield"] = { - "planarFaceTolerance": meshing_params.defaults.planar_face_tolerance + "planarFaceTolerance": meshing_params.defaults.planar_face_tolerance, + "relativeSize": zone.relative_size, } if zone.method == "quasi-3d-periodic": translated["farfield"]["type"] = "quasi-3d" diff --git a/tests/simulation/translator/ref/volume_meshing/ref_param_to_json_legacy_farfield_relative_size.json b/tests/simulation/translator/ref/volume_meshing/ref_param_to_json_legacy_farfield_relative_size.json new file mode 100644 index 000000000..4aae336b9 --- /dev/null +++ b/tests/simulation/translator/ref/volume_meshing/ref_param_to_json_legacy_farfield_relative_size.json @@ -0,0 +1,14 @@ +{ + "faces": {}, + "farfield": { + "planarFaceTolerance": 1e-06, + "relativeSize": 100.0, + "type": "quasi-3d" + }, + "refinementFactor": 1.0, + "volume": { + "firstLayerThickness": 1e-03, + "gapTreatmentStrength": 0.0, + "growthRate": 1.25 + } +} \ No newline at end of file diff --git a/tests/simulation/translator/test_volume_meshing_translator.py b/tests/simulation/translator/test_volume_meshing_translator.py index 2b8079b96..6501c9625 100644 --- a/tests/simulation/translator/test_volume_meshing_translator.py +++ b/tests/simulation/translator/test_volume_meshing_translator.py @@ -5,6 +5,7 @@ import flow360.component.simulation.units as u from flow360.component.simulation.framework.param_utils import AssetCache +from flow360.component.simulation.framework.updater_utils import compare_values from flow360.component.simulation.meshing_param.face_params import ( BoundaryLayer, PassiveSpacing, @@ -15,6 +16,7 @@ MeshingParams, ) from flow360.component.simulation.meshing_param.volume_params import ( + AutomatedFarfield, AxisymmetricRefinement, CustomZones, RotationVolume, @@ -556,3 +558,25 @@ def test_surface_mesh_user_defined_farfield_disallow_any_ghost(): ) with pytest.raises(pd.ValidationError): PassiveSpacing(entities=[GhostCircularPlane(name="symmetric")], type="projected") + + +def test_farfield_relative_size(): + with SI_unit_system: + param = SimulationParams( + meshing=MeshingParams( + defaults=MeshingDefaults( + boundary_layer_first_layer_thickness=1e-3, boundary_layer_growth_rate=1.25 + ), + volume_zones=[AutomatedFarfield(method="quasi-3d", relative_size=100.0)], + ) + ) + translated = get_volume_meshing_json(param, u.m) + ref_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "ref", + "volume_meshing", + "ref_param_to_json_legacy_farfield_relative_size.json", + ) + with open(ref_path, "r") as fh: + ref_dict = json.load(fh) + assert compare_values(translated, ref_dict)