Skip to content

Commit

Permalink
Feilin/rc 24.2/unsteady require steps (#215)
Browse files Browse the repository at this point in the history
* UnsteadyTimeStepping requires physical_steps and time_step_size (#213)

* make physical_steps and time_step_size required for UnsteadyTimeStepping

* fix format

* disable pylint dangerous default value for _find_update_path

* change version to 24.2.1, partially fix tests

* add updater for 24.2.*
  • Loading branch information
feilin-flexcompute committed Mar 21, 2024
1 parent 728aeec commit 0ee7e6a
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 252 deletions.
4 changes: 2 additions & 2 deletions flow360/component/flow360_params/time_stepping.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class UnsteadyTimeStepping(BaseTimeStepping):
"""

model_type: Literal["Unsteady"] = pd.Field("Unsteady", alias="modelType", const=True)
physical_steps: Optional[PositiveInt] = pd.Field(alias="physicalSteps")
time_step_size: Optional[TimeType.Positive] = pd.Field(alias="timeStepSize")
physical_steps: PositiveInt = pd.Field(alias="physicalSteps")
time_step_size: TimeType.Positive = pd.Field(alias="timeStepSize")
CFL: Optional[Union[RampCFL, AdaptiveCFL]] = pd.Field(
displayed="CFL",
options=["Ramp CFL", "Adaptive CFL"],
Expand Down
2 changes: 2 additions & 0 deletions flow360/component/flow360_params/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def _no_update(params_as_dict):
("0.2.0b18", "23.3.0", _no_update),
("23.3.0", "23.3.*", _no_update),
("23.3.*", "24.2.*", _no_update),
("24.2.*", "24.2.*", _no_update),
]


Expand All @@ -26,6 +27,7 @@ def _version_match(version_1, version_2):
return pattern_1.match(version_2) or pattern_2.match(version_1)


# pylint: disable=dangerous-default-value
def _find_update_path(version_from, version_to, update_map=UPDATE_MAP):
path = []

Expand Down
2 changes: 1 addition & 1 deletion flow360/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
version
"""

__version__ = "24.2.0"
__version__ = "24.2.1"
22 changes: 14 additions & 8 deletions tests/params/test_time_stepping.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def test_time_stepping():
exported_json = json.loads(params.flow360_json())
assert "meshUnit" not in exported_json["geometry"]

ts = UnsteadyTimeStepping.parse_obj({"maxPhysicalSteps": 3})
ts = UnsteadyTimeStepping.parse_obj({"maxPhysicalSteps": 3, "timeStepSize": 0.1 * u.s})
assert ts.physical_steps == 3

ts = UnsteadyTimeStepping.parse_obj({"physicalSteps": 2})
ts = UnsteadyTimeStepping.parse_obj({"physicalSteps": 2, "timeStepSize": 0.2 * u.s})
assert ts.physical_steps == 2

with pytest.raises(ValueError):
Expand All @@ -98,19 +98,25 @@ def assert_CFL(ts, trueValue):
ts, fl.AdaptiveCFL(max=1e4, convergence_limiting_factor=0.25, max_relative_change=1000)
)

ts = UnsteadyTimeStepping()
ts = UnsteadyTimeStepping(physical_steps=20, time_step_size=0.1 * u.s)
assert_CFL(ts, fl.AdaptiveCFL.default_unsteady())
ts = UnsteadyTimeStepping(CFL=fl.RampCFL())
ts = UnsteadyTimeStepping(CFL=fl.RampCFL(), physical_steps=20, time_step_size=0.1 * u.s)
assert_CFL(ts, fl.RampCFL.default_unsteady())
ts = UnsteadyTimeStepping(CFL=fl.RampCFL(final=1000))
ts = UnsteadyTimeStepping(
CFL=fl.RampCFL(final=1000), physical_steps=20, time_step_size=0.1 * u.s
)
assert_CFL(ts, fl.RampCFL(initial=1, final=1000, ramp_steps=30))
ts = UnsteadyTimeStepping(CFL=fl.AdaptiveCFL())
ts = UnsteadyTimeStepping(CFL=fl.AdaptiveCFL(), physical_steps=20, time_step_size=0.1 * u.s)
assert_CFL(ts, fl.AdaptiveCFL.default_unsteady())
ts = UnsteadyTimeStepping(CFL=fl.AdaptiveCFL(maxRelativeChange=1000))
ts = UnsteadyTimeStepping(
CFL=fl.AdaptiveCFL(maxRelativeChange=1000), physical_steps=20, time_step_size=0.1 * u.s
)
assert_CFL(
ts, fl.AdaptiveCFL(max=1e6, convergence_limiting_factor=1.0, max_relative_change=1000)
)
ts = UnsteadyTimeStepping(CFL=fl.AdaptiveCFL(maxRelativeChange=1000))
ts = UnsteadyTimeStepping(
CFL=fl.AdaptiveCFL(maxRelativeChange=1000), physical_steps=20, time_step_size=0.1 * u.s
)
assert_CFL(
ts,
fl.AdaptiveCFL(max=1e6, convergence_limiting_factor=1.0, max_relative_change=1000),
Expand Down
7 changes: 4 additions & 3 deletions tests/params/test_validator_cht_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import flow360 as fl
from flow360 import units as u
from flow360.component.flow360_params.boundaries import (
SolidAdiabaticWall,
SolidIsothermalWall,
Expand Down Expand Up @@ -215,7 +216,7 @@ def test_cht_solver_has_heat_transfer_zone():

with fl.SI_unit_system:
param = Flow360Params(
time_stepping=UnsteadyTimeStepping(),
time_stepping=UnsteadyTimeStepping(physical_steps=10, time_step_size=0.1 * u.s),
volume_zones={
"blk-1": HeatTransferVolumeZone(
thermal_conductivity=0.1,
Expand All @@ -234,7 +235,7 @@ def test_cht_solver_has_heat_transfer_zone():
):
with fl.SI_unit_system:
param = Flow360Params(
time_stepping=UnsteadyTimeStepping(),
time_stepping=UnsteadyTimeStepping(physical_steps=10, time_step_size=0.1 * u.s),
volume_zones={
"blk-1": HeatTransferVolumeZone(thermal_conductivity=0.1),
"blk-2": FluidDynamicsVolumeZone(),
Expand All @@ -248,7 +249,7 @@ def test_cht_solver_has_heat_transfer_zone():
):
with fl.SI_unit_system:
param = Flow360Params(
time_stepping=UnsteadyTimeStepping(),
time_stepping=UnsteadyTimeStepping(physical_steps=10, time_step_size=0.1 * u.s),
volume_zones={
"blk-1": HeatTransferVolumeZone(thermal_conductivity=0.1, heat_capacity=0.1),
"blk-2": FluidDynamicsVolumeZone(),
Expand Down
3 changes: 2 additions & 1 deletion tests/params/test_validator_consistency_ddes_unsteady.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import flow360 as fl
from flow360 import units as u
from flow360.component.flow360_params.flow360_params import (
Flow360Params,
SteadyTimeStepping,
Expand All @@ -22,7 +23,7 @@ def change_test_dir(request, monkeypatch):
def test_consistency_ddes_unsteady():
with fl.SI_unit_system:
param = Flow360Params(
time_stepping=UnsteadyTimeStepping(),
time_stepping=UnsteadyTimeStepping(physical_steps=20, time_step_size=0.1 * u.s),
turbulence_model_solver=SpalartAllmaras(DDES=True),
boundaries={},
freestream=fl.FreestreamFromMach(Mach=1, temperature=1, mu_ref=1),
Expand Down
13 changes: 10 additions & 3 deletions tests/params/test_validator_equation_eval_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import flow360 as fl
from flow360 import units as u
from flow360.component.flow360_params.flow360_params import (
Flow360Params,
SteadyTimeStepping,
Expand All @@ -25,7 +26,9 @@ def change_test_dir(request, monkeypatch):
def test_equation_eval_frequency_for_unsteady_simulations():
with fl.SI_unit_system:
param = Flow360Params(
time_stepping=UnsteadyTimeStepping(max_pseudo_steps=30),
time_stepping=UnsteadyTimeStepping(
max_pseudo_steps=30, physical_steps=20, time_step_size=0.1 * u.s
),
turbulence_model_solver=SpalartAllmaras(equation_eval_frequency=2),
transition_model_solver=TransitionModelSolver(equation_eval_frequency=4),
boundaries={},
Expand All @@ -47,7 +50,9 @@ def test_equation_eval_frequency_for_unsteady_simulations():
):
with fl.SI_unit_system:
param = Flow360Params(
time_stepping=UnsteadyTimeStepping(max_pseudo_steps=2),
time_stepping=UnsteadyTimeStepping(
max_pseudo_steps=2, physical_steps=20, time_step_size=0.1 * u.s
),
turbulence_model_solver=SpalartAllmaras(equation_eval_frequency=3),
boundaries={},
freestream=fl.FreestreamFromMach(Mach=1, temperature=1, mu_ref=1),
Expand All @@ -58,7 +63,9 @@ def test_equation_eval_frequency_for_unsteady_simulations():
):
with fl.SI_unit_system:
param = Flow360Params(
time_stepping=UnsteadyTimeStepping(max_pseudo_steps=2),
time_stepping=UnsteadyTimeStepping(
max_pseudo_steps=2, physical_steps=20, time_step_size=0.1 * u.s
),
transition_model_solver=TransitionModelSolver(equation_eval_frequency=3),
boundaries={},
freestream=fl.FreestreamFromMach(Mach=1, temperature=1, mu_ref=1),
Expand Down
96 changes: 52 additions & 44 deletions tests/ref/case_params/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"unitSystem": {
"name": "SI"
},
"version": "24.2.0",
"version": "24.2.1",
"geometry": {
"refArea": {
"value": 1.0,
Expand All @@ -15,46 +15,29 @@
"name": "freestream",
"velocityType": "relative"
},
"2": {
"type": "SlipWall",
"name": "symmetry"
},
"1": {
"type": "NoSlipWall",
"name": "wing",
"velocityType": "relative"
},
"2": {
"type": "SlipWall",
"name": "symmetry"
}
},
"timeStepping": {
"maxPseudoSteps": 2000,
"orderOfAccuracy": 2,
"modelType": "Steady",
"physicalSteps": 1,
"timeStepSize": "inf",
"CFL": {
"type": "adaptive",
"min": 0.1,
"max": 10000.0,
"maxRelativeChange": 1.0,
"convergenceLimitingFactor": 0.25
}
},
"navierStokesSolver": {
"absoluteTolerance": 1e-10,
"relativeTolerance": 0.0,
"orderOfAccuracy": 2,
"CFLMultiplier": 1.0,
"updateJacobianFrequency": 4,
"maxForceJacUpdatePhysicalSteps": 0,
"kappaMUSCL": -1.0,
"equationEvalFrequency": 1,
"numericalDissipationFactor": 1.0,
"limitVelocity": false,
"limitPressureDensity": false,
"linearSolver": {
"maxIterations": 30
},
"modelType": "Compressible"
"modelType": "Steady",
"physicalSteps": 1,
"timeStepSize": "inf"
},
"freestream": {
"modelType": "FromVelocity",
Expand All @@ -79,14 +62,22 @@
"primitiveVars"
],
"surfaces": {
"symmetry": {
"outputFields": [ "T", "heatFlux" ]
},
"freestream": {
"outputFields": [ "Cp", "Mach" ]
"outputFields": [
"Cp",
"Mach"
]
},
"wing": {
"outputFields": [ "CfVec" ]
"outputFields": [
"CfVec"
]
},
"symmetry": {
"outputFields": [
"T",
"heatFlux"
]
}
}
},
Expand All @@ -111,43 +102,60 @@
"Cp"
],
"slices": {
"x0": {
"y1": {
"sliceNormal": [
1,
0,
1,
0
],
"sliceOrigin": {
"value": [
0.0,
0.0,
0.0
2,
1,
0
],
"units": "flow360_length_unit"
},
"outputFields": [
"Mach"
"T"
]
},
"y1": {
"x0": {
"sliceNormal": [
0,
1,
0,
0
],
"sliceOrigin": {
"value": [
2.0,
1.0,
0.0
0,
0,
0
],
"units": "flow360_length_unit"
},
"outputFields": [
"T"
"Mach"
]
}
}
},
"hash": "4e53306a82417657da36cde280ca20a95582e422a919a4e193c00137c31fc5d5"
}
"navierStokesSolver": {
"absoluteTolerance": 1e-10,
"relativeTolerance": 0.0,
"orderOfAccuracy": 2,
"CFLMultiplier": 1.0,
"updateJacobianFrequency": 4,
"maxForceJacUpdatePhysicalSteps": 0,
"kappaMUSCL": -1.0,
"equationEvalFrequency": 1,
"numericalDissipationFactor": 1.0,
"limitVelocity": false,
"limitPressureDensity": false,
"linearSolver": {
"maxIterations": 30
},
"modelType": "Compressible"
},
"hash": "48a1ec07eea6efb38a22abde0f1187fca9c561601227f24c07d390b8173340e2"
}
4 changes: 2 additions & 2 deletions tests/ref/case_params/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ geometry:
refArea:
units: 2*m**2
value: 1.0
hash: 4e53306a82417657da36cde280ca20a95582e422a919a4e193c00137c31fc5d5
hash: 48a1ec07eea6efb38a22abde0f1187fca9c561601227f24c07d390b8173340e2
navierStokesSolver:
CFLMultiplier: 1.0
absoluteTolerance: 1.0e-10
Expand Down Expand Up @@ -108,7 +108,7 @@ timeStepping:
timeStepSize: inf
unitSystem:
name: SI
version: 24.2.0
version: 24.2.1
volumeOutput:
animationFrequency: -1
animationFrequencyOffset: 0
Expand Down
Loading

0 comments on commit 0ee7e6a

Please sign in to comment.