Skip to content

Commit

Permalink
Cherry pick on 24.2 (#207)
Browse files Browse the repository at this point in the history
* Found a issue that the unit conversion is skipped for some reason (#194)

* Found a issue that the unit conversion is skipped for some reason

* fixed dimensioned values for slices

---------

Co-authored-by: Maciej Skarysz <maciej@flexcompute.com>

* Fix model_type missing in the turb solver updater (#200)

* Add constants Field in expression Initial condition (#201)

* Add constants Field in expression Initial condition

Remove the comments

* Fix unit test

* Added missing temperature -1 in the legacy uipdater (#204)

Format

* Added legacy volume zone name converter (#202)

* remove CfTagent and CfNormal as they are no longer supported (#154)

* remove CfTagent and CfNormal as they are no longer supported

* fix test

---------

Co-authored-by: Maciej Skarysz <maciej@flexcompute.com>
  • Loading branch information
benflexcompute and maciej-flexcompute committed Mar 19, 2024
1 parent 24fa92f commit 641e343
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 38 deletions.
6 changes: 1 addition & 5 deletions flow360/component/flow360_params/flow360_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@

SurfaceFieldNamesFull = Literal[
CommonFieldNamesFull,
"Viscous stress coefficient vector",
"Skin friction coefficient vector",
"Magnitude of CfVec",
"Magnitude of CfVec normal to the wall",
"Magnitude of CfVec tangent to the wall",
"Non-dimensional heat flux",
"Wall normals",
"Spalart-Allmaras variable",
Expand All @@ -71,8 +69,6 @@
CommonFieldNames,
"CfVec",
"Cf",
"CfNormal",
"CfTangent",
"heatFlux",
"nodeNormals",
"nodeForcesPerUnitArea",
Expand Down
26 changes: 17 additions & 9 deletions flow360/component/flow360_params/flow360_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def schema_extra(schema, model):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> SurfaceOutput:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
# Add boundaries that are not listed into `surfaces` and applying shared fields.
boundary_names = []
for boundary_name in params.boundaries.names():
Expand Down Expand Up @@ -331,7 +332,8 @@ def schema_extra(schema, model):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> SliceOutput:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
_distribute_shared_output_fields(solver_values, "slices")
return SliceOutput(**solver_values)

Expand All @@ -357,7 +359,8 @@ def schema_extra(schema, model):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> VolumeOutput:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
fields = solver_values.pop("output_fields")
fields = [to_short(field) for field in fields]
return VolumeOutput(**solver_values, output_fields=fields)
Expand Down Expand Up @@ -390,7 +393,8 @@ def schema_extra(schema, model):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> SurfaceIntegralMonitor:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
fields = solver_values.pop("output_fields")
fields = [to_short(field) for field in fields]
return SurfaceIntegralMonitor(**solver_values, output_fields=fields)
Expand All @@ -417,7 +421,8 @@ def schema_extra(schema, model):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> ProbeMonitor:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
fields = solver_values.pop("output_fields")
fields = [to_short(field) for field in fields]
return ProbeMonitor(**solver_values, output_fields=fields)
Expand Down Expand Up @@ -470,7 +475,8 @@ def schema_extra(schema, model):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> MonitorOutput:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
_distribute_shared_output_fields(solver_values, "monitors")
return MonitorOutput(**solver_values)

Expand All @@ -497,7 +503,8 @@ def schema_extra(schema, model):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> IsoSurface:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
fields = solver_values.pop("output_fields")
fields = [to_short(field) for field in fields]
return IsoSurface(**solver_values, output_fields=fields)
Expand Down Expand Up @@ -536,7 +543,8 @@ class IsoSurfaceOutput(Flow360BaseModel, AnimatedOutput):

# pylint: disable=arguments-differ
def to_solver(self, params, **kwargs) -> IsoSurfaceOutput:
solver_values = self._convert_dimensions_to_solver(params, **kwargs)
solver_model = super().to_solver(params, **kwargs)
solver_values = solver_model.__dict__
_distribute_shared_output_fields(solver_values, "iso_surfaces")
return IsoSurfaceOutput(**solver_values)

Expand Down Expand Up @@ -644,7 +652,7 @@ class SliceNamedLegacy(Flow360BaseModel):
slice_name: str = pd.Field(alias="sliceName")
slice_normal: Axis = pd.Field(alias="sliceNormal")
slice_origin: Coordinate = pd.Field(alias="sliceOrigin")
output_fields: Optional[List[str]] = pd.Field(alias="outputFields")
output_fields: Optional[List[str]] = pd.Field([], alias="outputFields")


class SliceOutputLegacy(SliceOutput, LegacyOutputFormat, LegacyModel):
Expand Down
20 changes: 17 additions & 3 deletions flow360/component/flow360_params/flow360_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@
_check_periodic_boundary_mapping,
_check_tri_quad_boundaries,
)
from .volume_zones import FluidDynamicsVolumeZone, ReferenceFrameType, VolumeZoneType
from .volume_zones import (
FluidDynamicsVolumeZone,
HeatTransferVolumeZone,
ReferenceFrameType,
VolumeZoneType,
)


# pylint: disable=invalid-name
Expand Down Expand Up @@ -1401,11 +1406,13 @@ def update_model(self) -> Flow360BaseModel:
class FreestreamLegacy(LegacyModel):
""":class: `FreestreamLegacy` class"""

Reynolds: Optional[PositiveFloat] = pd.Field()
Reynolds: Optional[Union[pd.confloat(gt=0, allow_inf_nan=False), Literal["inf"]]] = pd.Field(
displayed="Reynolds number"
)
Mach: Optional[NonNegativeFloat] = pd.Field()
Mach_Ref: Optional[PositiveFloat] = pd.Field(alias="MachRef")
mu_ref: Optional[PositiveFloat] = pd.Field(alias="muRef")
temperature: PositiveFloat = pd.Field(alias="Temperature")
temperature: Union[Literal[-1], PositiveFloat] = pd.Field(alias="Temperature")
alpha: Optional[float] = pd.Field(alias="alphaAngle")
beta: Optional[float] = pd.Field(alias="betaAngle", default=0)
turbulent_viscosity_ratio: Optional[NonNegativeFloat] = pd.Field(
Expand Down Expand Up @@ -1623,6 +1630,13 @@ class _ReferenceFrameTempModel(pd.BaseModel):
)
value["referenceFrame"] = model["field"]

volume_zone_type = value.get("modelType")

if volume_zone_type == "HeatEquation":
value["modelType"] = HeatTransferVolumeZone.__fields__["model_type"].default
if volume_zone_type == "NavierStokes":
value["modelType"] = FluidDynamicsVolumeZone.__fields__["model_type"].default

super().__init__(*args, **kwargs)


Expand Down
3 changes: 2 additions & 1 deletion flow360/component/flow360_params/initial_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import annotations

from typing import Union
from typing import Dict, Optional, Union

import pydantic as pd
from typing_extensions import Literal
Expand All @@ -28,6 +28,7 @@ class ExpressionInitialCondition(InitialCondition):
""":class:`ExpressionInitialCondition` class"""

type: Literal["expression"] = pd.Field("expression", const=True)
constants: Optional[Dict[str, str]] = pd.Field(alias="constants")
rho: str = pd.Field(displayed="rho [non-dim]")
u: str = pd.Field(displayed="u [non-dim]")
v: str = pd.Field(displayed="v [non-dim]")
Expand Down
27 changes: 25 additions & 2 deletions flow360/component/flow360_params/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class TurbulenceModelConstantsSA(Flow360BaseModel):
class TurbulenceModelConstantsSST(Flow360BaseModel):
""":class:`TurbulenceModelConstantsSST` class"""

model_type: Literal[" kOmegaSSTConsts"] = pd.Field(
model_type: Literal["kOmegaSSTConsts"] = pd.Field(
"kOmegaSSTConsts", alias="modelType", const=True
)
C_DES1: Optional[NonNegativeFloat] = pd.Field(0.78)
Expand Down Expand Up @@ -549,8 +549,31 @@ class TurbulenceModelSolverLegacy(TurbulenceModelSolver, LegacyModel):
)
rotation_correction: Optional[bool] = pd.Field(alias="rotationCorrection")

def update_model(self):
# pylint: disable=no-self-argument
@pd.root_validator(pre=True)
def populate_model_constant_type(cls, values):
"""
Add modelConstants->modelType before updater as it is required by discriminator
"""
turbulence_model_type = values.get("modelType")
model_constants = values.get("modelConstants")
if (
turbulence_model_type is None
or model_constants is None
or "modelType" in model_constants
):
return values
if turbulence_model_type == SpalartAllmaras.__fields__["model_type"].default:
values["modelConstants"]["modelType"] = TurbulenceModelConstantsSA.__fields__[
"model_type"
].default
if turbulence_model_type == KOmegaSST.__fields__["model_type"].default:
values["modelConstants"]["modelType"] = TurbulenceModelConstantsSST.__fields__[
"model_type"
].default
return values

def update_model(self):
model = {
"absoluteTolerance": self.absolute_tolerance,
"relativeTolerance": self.relative_tolerance,
Expand Down
2 changes: 0 additions & 2 deletions flow360/examples/actuatorDisk/flow360.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"primitiveVars": false,
"Cp": true,
"Cf": true,
"CfTangent": false,
"CfNormal": false,
"CfVec": true,
"yPlus": true,
"wallDistance": false,
Expand Down
2 changes: 0 additions & 2 deletions flow360/examples/betDisk/flow360.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"primitiveVars": false,
"Cp": true,
"Cf": true,
"CfTangent": false,
"CfNormal": false,
"CfVec": true,
"yPlus": true,
"wallDistance": false,
Expand Down
2 changes: 0 additions & 2 deletions flow360/examples/betLine/flow360.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"primitiveVars": false,
"Cp": true,
"Cf": true,
"CfTangent": false,
"CfNormal": false,
"CfVec": true,
"yPlus": true,
"wallDistance": false,
Expand Down
2 changes: 0 additions & 2 deletions flow360/examples/betLine/release-21.3.3.0ge/flow360.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"primitiveVars": false,
"Cp": true,
"Cf": true,
"CfTangent": false,
"CfNormal": false,
"CfVec": true,
"yPlus": true,
"wallDistance": false,
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cases/case_10.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"muRef": 0.0000017020069150311915,
"Mach": 0,
"MachRef": 0.69,
"Temperature": 288.15,
"Temperature": -1.0,
"alphaAngle": 0,
"betaAngle": 0
},
Expand Down
6 changes: 5 additions & 1 deletion tests/data/cases/case_5.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
"linearIterations": 25,
"updateJacobianFrequency": 4,
"equationEvalFrequency": 4,
"orderOfAccuracy": 2
"orderOfAccuracy": 2,
"modelConstants": {
"C_DES": 0.72,
"C_d": 8.0
}
},
"freestream": {
"Reynolds": 4840000,
Expand Down
70 changes: 70 additions & 0 deletions tests/data/cases/case_HeatTransfer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"boundaries": {
"outerBlock/farfield": {
"type": "Freestream"
}
},
"volumeZones": {
"outerBlock": {
"modelType": "FluidDynamics"
},
"innerBlock": {
"modelType": "HeatEquation",
"thermalConductivity": 0.03472,
"initialCondition": {
"T": 1
}
}
},
"freestream": {
"Mach": 0.0,
"MachRef": 0.1,
"muRef": 1e-5,
"Temperature": 288.15,
"alphaAngle": 0.0,
"betaAngle": 0.0
},
"geometry": {
"refArea": 1.0
},
"navierStokesSolver": {
"equationEvalFrequency": 1,
"linearIterations": 50,
"modelType": "Compressible",
"orderOfAccuracy": 2,
"numericalDissipationFactor": 0.01
},
"heatEquationSolver": {
"modelType": "HeatEquation",
"linearSolver": {
"maxIterations": 100,
"absoluteTolerance": 1e-12
},
"equationEvalFrequency": 20
},
"turbulenceModelSolver": {
"modelType": "None"
},
"surfaceOutput": {
"surfaces": {
"outerBlock/Interface_innerBlock": {
"outputFields": [
"T"
]
}
}
},
"timeStepping": {
"maxPseudoSteps": 1,
"physicalSteps": 1,
"timeStepSize": "inf"
},
"volumeOutput": {
"outputFormat": "paraview",
"outputFields": [
"solutionNavierStokes",
"T",
"primitiveVars"
]
}
}
8 changes: 1 addition & 7 deletions tests/data/cases/case_customDynamics1.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,11 @@
"linearIterations" : 25,
"kappaMUSCL" : -1.0
},
"turbulenceModelSolver" : {
"modelType" : "None",
"tolerance" : 1e-8,
"linearIterations" : 15,
"kappaMUSCL" : -1.0
},
"freestream" :
{
"Reynolds" : "inf",
"Mach" : 0.5,
"Temperature" : -1,
"Temperature" : 283,
"alphaAngle" : 3.12,
"betaAngle" : 0.0
},
Expand Down
4 changes: 4 additions & 0 deletions tests/data/cases/case_udd.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
"maxIterations": 20,
"absoluteTolerance": 1e-10
},
"modelConstants": {
"C_DES": 0.72,
"C_d": 8.0
},
"rotationCorrection": false
},
"freestream": {
Expand Down
3 changes: 3 additions & 0 deletions tests/params/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
AeroacousticOutput,
Flow360Params,
FreestreamFromMach,
Geometry,
)
from tests.utils import array_equality_override, to_file_from_file_test

Expand Down Expand Up @@ -216,6 +217,7 @@ def test_slice_output():
slice_output=output,
boundaries={},
freestream=FreestreamFromMach(Mach=1, temperature=1, mu_ref=1),
geometry=Geometry(mesh_unit=1),
)
solver_params = params.to_solver()
for slice_name, slice_item in solver_params.slice_output.slices.dict().items():
Expand Down Expand Up @@ -337,6 +339,7 @@ def test_monitor_output():
monitor_output=output,
boundaries={},
freestream=FreestreamFromMach(Mach=1, temperature=1, mu_ref=1),
geometry=Geometry(mesh_unit=1),
)
solver_params = params.to_solver()

Expand Down
Loading

0 comments on commit 641e343

Please sign in to comment.