Skip to content

Commit 2121e38

Browse files
committed
Add updater for two new validations
1 parent 12deb23 commit 2121e38

File tree

2 files changed

+306
-0
lines changed

2 files changed

+306
-0
lines changed

flow360/component/simulation/framework/updater.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,68 @@ def _to_25_7_6(params_as_dict):
386386
return remove_entity_bucket_field(params_as_dict=params_as_dict)
387387

388388

389+
def _to_25_7_7(params_as_dict):
390+
"""
391+
1. Reset frequency and frequency_offset to defaults for steady simulations
392+
2. Remove invalid output fields based on transition model
393+
"""
394+
395+
# 1. Handle frequency settings in steady simulations
396+
if params_as_dict.get("time_stepping", {}).get("type_name") == "Steady":
397+
outputs = params_as_dict.get("outputs") or []
398+
for output in outputs:
399+
# Output types that have frequency/frequency_offset settings
400+
if output.get("output_type") in [
401+
"VolumeOutput",
402+
"TimeAverageVolumeOutput",
403+
"SurfaceOutput",
404+
"TimeAverageSurfaceOutput",
405+
"SliceOutput",
406+
"TimeAverageSliceOutput",
407+
"IsosurfaceOutput",
408+
"TimeAverageIsosurfaceOutput",
409+
"SurfaceSliceOutput",
410+
]:
411+
# Reset to defaults: frequency=-1, frequency_offset=0
412+
if "frequency" in output:
413+
output["frequency"] = -1
414+
if "frequency_offset" in output:
415+
output["frequency_offset"] = 0
416+
417+
# 2. Remove invalid output fields based on transition model
418+
# Get transition model type from models
419+
transition_model_type = "None"
420+
models = params_as_dict.get("models") or []
421+
for model in models:
422+
if model.get("type") == "Fluid":
423+
transition_solver = model.get("transition_model_solver") or {}
424+
transition_model_type = transition_solver.get("type_name")
425+
break
426+
427+
# If transition model is None or not found, remove transition-specific fields
428+
if transition_model_type == "None":
429+
transition_output_fields = [
430+
"residualTransition",
431+
"solutionTransition",
432+
"linearResidualTransition",
433+
]
434+
435+
outputs = params_as_dict.get("outputs") or []
436+
for output in outputs:
437+
if output.get("output_type") in ["AeroAcousticOutput", "StreamlineOutput"]:
438+
continue
439+
if "output_fields" in output:
440+
output_fields = output["output_fields"]
441+
if isinstance(output_fields, dict) and "items" in output_fields:
442+
items = output_fields["items"]
443+
# Remove invalid fields
444+
output_fields["items"] = [
445+
field for field in items if field not in transition_output_fields
446+
]
447+
448+
return params_as_dict
449+
450+
389451
VERSION_MILESTONES = [
390452
(Flow360Version("24.11.1"), _to_24_11_1),
391453
(Flow360Version("24.11.7"), _to_24_11_7),
@@ -400,6 +462,7 @@ def _to_25_7_6(params_as_dict):
400462
(Flow360Version("25.6.6"), _to_25_6_6),
401463
(Flow360Version("25.7.2"), _to_25_7_2),
402464
(Flow360Version("25.7.6"), _to_25_7_6),
465+
(Flow360Version("25.7.7"), _to_25_7_7),
403466
] # A list of the Python API version tuple with there corresponding updaters.
404467

405468

tests/simulation/test_updater.py

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,246 @@ def test_updater_to_25_7_6_rename_rotation_cylinder():
877877

878878
assert params_new["version"] == "25.7.6"
879879
assert params_new["meshing"]["volume_zones"][0]["type"] == "RotationVolume"
880+
881+
882+
def test_updater_to_25_7_7():
883+
"""Test updater for version 25.7.7 which handles:
884+
1. Resetting frequency/frequency_offset to defaults for steady simulations
885+
2. Removing transition-specific output fields when transition model is None
886+
"""
887+
888+
# Construct test params with:
889+
# - Steady simulation with non-default frequency settings
890+
# - Transition model set to None with transition-specific output fields
891+
params_as_dict = {
892+
"version": "25.7.6",
893+
"time_stepping": {
894+
"type_name": "Steady",
895+
"max_steps": 1000,
896+
},
897+
"models": [
898+
{
899+
"type": "Fluid",
900+
"transition_model_solver": {
901+
"type_name": "None",
902+
},
903+
"turbulence_model_solver": {
904+
"type_name": "SpalartAllmaras",
905+
},
906+
}
907+
],
908+
"outputs": [
909+
{
910+
"output_type": "VolumeOutput",
911+
"name": "Volume output",
912+
"frequency": 10,
913+
"frequency_offset": 5,
914+
"output_format": "paraview",
915+
"output_fields": {
916+
"items": [
917+
"primitiveVars",
918+
"residualNavierStokes",
919+
"residualTransition",
920+
"Mach",
921+
]
922+
},
923+
},
924+
{
925+
"output_type": "SurfaceOutput",
926+
"name": "Surface output",
927+
"frequency": 20,
928+
"frequency_offset": 10,
929+
"output_format": "paraview",
930+
"entities": {"stored_entities": []},
931+
"output_fields": {
932+
"items": [
933+
"Cp",
934+
"Cf",
935+
"solutionTransition",
936+
]
937+
},
938+
},
939+
{
940+
"output_type": "SliceOutput",
941+
"name": "Slice output",
942+
"frequency": 15,
943+
"frequency_offset": 2,
944+
"output_format": "paraview",
945+
"entities": {"stored_entities": []},
946+
"output_fields": {
947+
"items": [
948+
"vorticity",
949+
"linearResidualTransition",
950+
]
951+
},
952+
},
953+
{
954+
"output_type": "ProbeOutput",
955+
"name": "Probe output",
956+
"entities": {"stored_entities": []},
957+
"output_fields": {
958+
"items": [
959+
"primitiveVars",
960+
"residualTransition",
961+
]
962+
},
963+
},
964+
{
965+
"output_type": "AeroAcousticOutput",
966+
"name": "Aeroacoustic output",
967+
"observers": [],
968+
},
969+
],
970+
}
971+
972+
params_new = updater(
973+
version_from="25.7.6",
974+
version_to="25.7.7",
975+
params_as_dict=params_as_dict,
976+
)
977+
978+
# Test 1: Verify frequency settings were reset to defaults for steady simulation
979+
assert (
980+
params_new["outputs"][0]["frequency"] == -1
981+
), "VolumeOutput frequency should be reset to -1"
982+
assert (
983+
params_new["outputs"][0]["frequency_offset"] == 0
984+
), "VolumeOutput frequency_offset should be reset to 0"
985+
986+
assert (
987+
params_new["outputs"][1]["frequency"] == -1
988+
), "SurfaceOutput frequency should be reset to -1"
989+
assert (
990+
params_new["outputs"][1]["frequency_offset"] == 0
991+
), "SurfaceOutput frequency_offset should be reset to 0"
992+
993+
assert (
994+
params_new["outputs"][2]["frequency"] == -1
995+
), "SliceOutput frequency should be reset to -1"
996+
assert (
997+
params_new["outputs"][2]["frequency_offset"] == 0
998+
), "SliceOutput frequency_offset should be reset to 0"
999+
1000+
# Test 2: Verify transition-specific output fields were removed
1001+
volume_output_fields = params_new["outputs"][0]["output_fields"]["items"]
1002+
assert "residualTransition" not in volume_output_fields, "residualTransition should be removed"
1003+
assert "primitiveVars" in volume_output_fields, "primitiveVars should remain"
1004+
assert "residualNavierStokes" in volume_output_fields, "residualNavierStokes should remain"
1005+
assert "Mach" in volume_output_fields, "Mach should remain"
1006+
1007+
surface_output_fields = params_new["outputs"][1]["output_fields"]["items"]
1008+
assert "solutionTransition" not in surface_output_fields, "solutionTransition should be removed"
1009+
assert "Cp" in surface_output_fields, "Cp should remain"
1010+
assert "Cf" in surface_output_fields, "Cf should remain"
1011+
1012+
slice_output_fields = params_new["outputs"][2]["output_fields"]["items"]
1013+
assert (
1014+
"linearResidualTransition" not in slice_output_fields
1015+
), "linearResidualTransition should be removed"
1016+
assert "vorticity" in slice_output_fields, "vorticity should remain"
1017+
1018+
probe_output_fields = params_new["outputs"][3]["output_fields"]["items"]
1019+
assert (
1020+
"residualTransition" not in probe_output_fields
1021+
), "residualTransition should be removed from ProbeOutput"
1022+
assert "primitiveVars" in probe_output_fields, "primitiveVars should remain"
1023+
1024+
# Test 3: Verify version was updated
1025+
assert params_new["version"] == "25.7.7"
1026+
1027+
1028+
def test_updater_to_25_7_7_unsteady_no_frequency_change():
1029+
"""Test that frequency settings are NOT changed for unsteady simulations"""
1030+
1031+
params_as_dict = {
1032+
"version": "25.7.6",
1033+
"time_stepping": {
1034+
"type_name": "Unsteady",
1035+
"max_steps": 1000,
1036+
},
1037+
"models": [
1038+
{
1039+
"type": "Fluid",
1040+
"transition_model_solver": {
1041+
"type_name": "None",
1042+
},
1043+
}
1044+
],
1045+
"outputs": [
1046+
{
1047+
"output_type": "VolumeOutput",
1048+
"name": "Volume output",
1049+
"frequency": 10,
1050+
"frequency_offset": 5,
1051+
"output_format": "paraview",
1052+
"output_fields": {"items": ["primitiveVars", "Mach"]},
1053+
},
1054+
],
1055+
}
1056+
1057+
params_new = updater(
1058+
version_from="25.7.6",
1059+
version_to="25.7.7",
1060+
params_as_dict=params_as_dict,
1061+
)
1062+
1063+
assert params_new["outputs"][0]["frequency"] == 10, "Unsteady frequency should not be changed"
1064+
assert (
1065+
params_new["outputs"][0]["frequency_offset"] == 5
1066+
), "Unsteady frequency_offset should not be changed"
1067+
1068+
1069+
def test_updater_to_25_7_7_with_transition_model():
1070+
"""Test that transition output fields are NOT removed when transition model is enabled"""
1071+
1072+
params_as_dict = {
1073+
"version": "25.7.6",
1074+
"time_stepping": {
1075+
"type_name": "Steady",
1076+
"max_steps": 1000,
1077+
},
1078+
"models": [
1079+
{
1080+
"type": "Fluid",
1081+
"transition_model_solver": {
1082+
"type_name": "AmplificationFactorTransport",
1083+
},
1084+
}
1085+
],
1086+
"outputs": [
1087+
{
1088+
"output_type": "VolumeOutput",
1089+
"name": "Volume output",
1090+
"frequency": 10,
1091+
"frequency_offset": 5,
1092+
"output_format": "paraview",
1093+
"output_fields": {
1094+
"items": [
1095+
"primitiveVars",
1096+
"residualTransition",
1097+
"solutionTransition",
1098+
]
1099+
},
1100+
},
1101+
],
1102+
}
1103+
1104+
params_new = updater(
1105+
version_from="25.7.6",
1106+
version_to="25.7.7",
1107+
params_as_dict=params_as_dict,
1108+
)
1109+
1110+
# Frequency settings should still be reset for steady simulation
1111+
assert params_new["outputs"][0]["frequency"] == -1
1112+
assert params_new["outputs"][0]["frequency_offset"] == 0
1113+
1114+
# Transition output fields should NOT be removed when transition model is enabled
1115+
volume_output_fields = params_new["outputs"][0]["output_fields"]["items"]
1116+
assert (
1117+
"residualTransition" in volume_output_fields
1118+
), "residualTransition should remain with AmplificationFactorTransport"
1119+
assert (
1120+
"solutionTransition" in volume_output_fields
1121+
), "solutionTransition should remain with AmplificationFactorTransport"
1122+
assert "primitiveVars" in volume_output_fields, "primitiveVars should remain"

0 commit comments

Comments
 (0)