Skip to content

Commit

Permalink
Fix the reconstructionGradientLimiter updater (#195)
Browse files Browse the repository at this point in the history
* Fix the reconstructionGradientLimiter updater

* Comments addressed

* Let the class handle defaults

* Format

* Lint
  • Loading branch information
benflexcompute authored Mar 8, 2024
1 parent 8ed2fcc commit af833be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 12 additions & 2 deletions flow360/component/flow360_params/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class TurbulenceModelSolver(GenericFlowSolverSettings, metaclass=ABCMeta):
"maxEdgeLength", alias="gridSizeForLES"
)
reconstruction_gradient_limiter: Optional[pd.confloat(ge=0, le=2)] = pd.Field(
1.0, alias="reconstructionGradientLimiter"
alias="reconstructionGradientLimiter"
)
quadratic_constitutive_relation: Optional[bool] = pd.Field(
False, alias="quadraticConstitutiveRelation"
Expand All @@ -337,6 +337,9 @@ class KOmegaSST(TurbulenceModelSolver):

model_type: Literal["kOmegaSST"] = pd.Field("kOmegaSST", alias="modelType", const=True)
model_constants: Optional[TurbulenceModelConstantsSST] = pd.Field(alias="modelConstants")
reconstruction_gradient_limiter: Optional[pd.confloat(ge=0, le=2)] = pd.Field(
1.0, alias="reconstructionGradientLimiter"
)


class SpalartAllmaras(TurbulenceModelSolver):
Expand Down Expand Up @@ -547,6 +550,7 @@ class TurbulenceModelSolverLegacy(TurbulenceModelSolver, LegacyModel):
rotation_correction: Optional[bool] = pd.Field(alias="rotationCorrection")

def update_model(self):

model = {
"absoluteTolerance": self.absolute_tolerance,
"relativeTolerance": self.relative_tolerance,
Expand All @@ -559,15 +563,21 @@ def update_model(self):
"DDES": self.DDES,
"gridSizeForLES": self.grid_size_for_LES,
"quadraticConstitutiveRelation": self.quadratic_constitutive_relation,
"reconstructionGradientLimiter": self.reconstruction_gradient_limiter,
"modelConstants": self.model_constants,
}

try_set(model, "rotationCorrection", self.rotation_correction)

if self.reconstruction_gradient_limiter is not None:
model["reconstructionGradientLimiter"] = self.reconstruction_gradient_limiter

if self.linear_iterations is not None and model["linearSolverConfig"] is not None:
model["linearSolverConfig"]["maxIterations"] = self.linear_iterations

if self.model_type == SpalartAllmaras.__fields__["model_type"].default:
return SpalartAllmaras(**model)
if self.model_type == KOmegaSST.__fields__["model_type"].default:
return KOmegaSST(**model)
return model


Expand Down
5 changes: 2 additions & 3 deletions tests/data/cases/case_7.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,15 @@
"equationEvalFrequency": 1
},
"turbulenceModelSolver": {
"modelType": "SpalartAllmaras",
"modelType": "kOmegaSST",
"absoluteTolerance": 1e-8,
"relativeTolerance": 0.001,
"linearIterations": 35,
"kappaMUSCL": -1,
"DDES": true,
"orderOfAccuracy": 2,
"updateJacobianFrequency": 1,
"equationEvalFrequency": 1,
"rotationCorrection": true
"equationEvalFrequency": 1
},
"freestream": {
"muRef": 0.00004291607,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def test_updater_from_files():
assert params
params.flow360_json()

params = fl.Flow360Params(f"data/cases/case_5.json")
assert params.turbulence_model_solver.reconstruction_gradient_limiter == 0.5
params = fl.Flow360Params(f"data/cases/case_7.json")
assert params.turbulence_model_solver.reconstruction_gradient_limiter == 1.0


def test_version_update():
files = ["test_version_b16.json"]
Expand Down

0 comments on commit af833be

Please sign in to comment.