5
5
# pylint: disable=unused-import
6
6
from __future__ import annotations
7
7
8
+ import json
8
9
import math
9
10
import os
10
11
from abc import ABCMeta , abstractmethod
66
67
ProbeMonitor ,
67
68
SliceOutput ,
68
69
SliceOutputLegacy ,
69
- Slices ,
70
70
SurfaceIntegralMonitor ,
71
71
SurfaceOutput ,
72
72
SurfaceOutputLegacy ,
@@ -485,7 +485,7 @@ class Geometry(Flow360BaseModel):
485
485
:class: Geometry component
486
486
"""
487
487
488
- ref_area : Optional [AreaType .Positive ] = pd .Field (alias = "refArea" )
488
+ ref_area : Optional [AreaType .Positive ] = pd .Field (alias = "refArea" , displayed = "Reference area" )
489
489
moment_center : Optional [LengthType .Point ] = pd .Field (alias = "momentCenter" )
490
490
moment_length : Optional [LengthType .Moment ] = pd .Field (alias = "momentLength" )
491
491
mesh_unit : Optional [LengthType ] = pd .Field (alias = "meshUnit" )
@@ -508,8 +508,8 @@ class FreestreamBase(Flow360BaseModel, metaclass=ABCMeta):
508
508
"""
509
509
510
510
model_type : str
511
- alpha : Optional [float ] = pd .Field (alias = "alphaAngle" , default = 0 )
512
- beta : Optional [float ] = pd .Field (alias = "betaAngle" , default = 0 )
511
+ alpha : Optional [float ] = pd .Field (alias = "alphaAngle" , default = 0 , displayed = "Alpha angle [deg]" )
512
+ beta : Optional [float ] = pd .Field (alias = "betaAngle" , default = 0 , displayed = "Beta angle [deg]" )
513
513
turbulent_viscosity_ratio : Optional [NonNegativeFloat ] = pd .Field (
514
514
alias = "turbulentViscosityRatio"
515
515
)
@@ -532,10 +532,10 @@ class FreestreamFromMach(FreestreamBase):
532
532
"""
533
533
534
534
model_type : Literal ["FromMach" ] = pd .Field ("FromMach" , alias = "modelType" , const = True )
535
- Mach : PositiveFloat = pd .Field ()
536
- Mach_ref : Optional [PositiveFloat ] = pd .Field (alias = "MachRef" )
537
- mu_ref : PositiveFloat = pd .Field (alias = "muRef" )
538
- temperature : PositiveFloat = pd .Field (alias = "Temperature" )
535
+ Mach : PositiveFloat = pd .Field (displayed = "Mach number" )
536
+ Mach_ref : Optional [PositiveFloat ] = pd .Field (alias = "MachRef" , displayed = "Reference Mach number" )
537
+ mu_ref : PositiveFloat = pd .Field (alias = "muRef" , displayed = "Dynamic viscosity [non-dim]" )
538
+ temperature : PositiveFloat = pd .Field (alias = "Temperature" , displayed = "Temperature [K]" )
539
539
540
540
# pylint: disable=arguments-differ, unused-argument
541
541
def to_solver (self , params : Flow360Params , ** kwargs ) -> FreestreamFromMach :
@@ -553,10 +553,10 @@ class FreestreamFromMachReynolds(FreestreamBase):
553
553
model_type : Literal ["FromMachReynolds" ] = pd .Field (
554
554
"FromMachReynolds" , alias = "modelType" , const = True
555
555
)
556
- Mach : PositiveFloat = pd .Field ()
557
- Mach_ref : Optional [PositiveFloat ] = pd .Field (alias = "MachRef" )
558
- Reynolds : PositiveFloat = pd .Field ()
559
- temperature : PositiveFloat = pd .Field (alias = "Temperature" )
556
+ Mach : PositiveFloat = pd .Field (displayed = "Mach number" )
557
+ Mach_ref : Optional [PositiveFloat ] = pd .Field (alias = "MachRef" , displayed = "Reference Mach number" )
558
+ Reynolds : PositiveFloat = pd .Field (displayed = "Reynolds number" )
559
+ temperature : PositiveFloat = pd .Field (alias = "Temperature" , displayed = "Temperature [K]" )
560
560
561
561
# pylint: disable=arguments-differ, unused-argument
562
562
def to_solver (self , params : Flow360Params , ** kwargs ) -> FreestreamFromMach :
@@ -572,10 +572,10 @@ class ZeroFreestream(FreestreamBase):
572
572
"""
573
573
574
574
model_type : Literal ["ZeroMach" ] = pd .Field ("ZeroMach" , alias = "modelType" , const = True )
575
- Mach : Literal [0 ] = pd .Field (0 , const = True )
576
- Mach_ref : pd .confloat (gt = 1.0e-12 ) = pd .Field (alias = "MachRef" )
577
- mu_ref : PositiveFloat = pd .Field (alias = "muRef" )
578
- temperature : PositiveFloat = pd .Field (alias = "Temperature" )
575
+ Mach : Literal [0 ] = pd .Field (0 , const = True , displayed = "Mach number" )
576
+ Mach_ref : pd .confloat (gt = 1.0e-12 ) = pd .Field (alias = "MachRef" , displayed = "Reference Mach number" )
577
+ mu_ref : PositiveFloat = pd .Field (alias = "muRef" , displayed = "Dynamic viscosity [non-dim]" )
578
+ temperature : PositiveFloat = pd .Field (alias = "Temperature" , displayed = "Temperature [K]" )
579
579
580
580
# pylint: disable=arguments-differ, unused-argument
581
581
def to_solver (self , params : Flow360Params , ** kwargs ) -> ZeroFreestream :
@@ -592,7 +592,9 @@ class FreestreamFromVelocity(FreestreamBase):
592
592
593
593
model_type : Literal ["FromVelocity" ] = pd .Field ("FromVelocity" , alias = "modelType" , const = True )
594
594
velocity : VelocityType .Positive = pd .Field ()
595
- velocity_ref : Optional [VelocityType .Positive ] = pd .Field (alias = "velocityRef" )
595
+ velocity_ref : Optional [VelocityType .Positive ] = pd .Field (
596
+ alias = "velocityRef" , displayed = "Reference velocity"
597
+ )
596
598
597
599
# pylint: disable=arguments-differ
598
600
def to_solver (self , params : Flow360Params , ** kwargs ) -> FreestreamFromMach :
@@ -637,7 +639,9 @@ class ZeroFreestreamFromVelocity(FreestreamBase):
637
639
638
640
model_type : Literal ["ZeroVelocity" ] = pd .Field ("ZeroVelocity" , alias = "modelType" , const = True )
639
641
velocity : Literal [0 ] = pd .Field (0 , const = True )
640
- velocity_ref : VelocityType .Positive = pd .Field (alias = "velocityRef" )
642
+ velocity_ref : VelocityType .Positive = pd .Field (
643
+ alias = "velocityRef" , displayed = "Reference velocity"
644
+ )
641
645
642
646
# pylint: disable=arguments-differ
643
647
def to_solver (self , params : Flow360Params , ** kwargs ) -> ZeroFreestream :
@@ -721,7 +725,7 @@ class AirPressureTemperature(Flow360BaseModel):
721
725
722
726
"""
723
727
724
- model_type : str = pd .Field ("AirPressure" , alias = "modelType" , const = True )
728
+ model_type : Literal [ "AirPressure" ] = pd .Field ("AirPressure" , alias = "modelType" , const = True )
725
729
pressure : PressureType = pd .Field ()
726
730
temperature : TemperatureType = pd .Field ()
727
731
@@ -754,7 +758,7 @@ class AirDensityTemperature(Flow360BaseModel):
754
758
755
759
"""
756
760
757
- model_type : str = pd .Field ("AirDensity" , alias = "modelType" , const = True )
761
+ model_type : Literal [ "AirDensity" ] = pd .Field ("AirDensity" , alias = "modelType" , const = True )
758
762
temperature : TemperatureType = pd .Field ()
759
763
density : DensityType = pd .Field ()
760
764
@@ -949,7 +953,9 @@ class Flow360Params(Flow360BaseModel):
949
953
version : str = pd .Field (__version__ , mutable = False )
950
954
951
955
geometry : Optional [Geometry ] = pd .Field ()
952
- fluid_properties : Optional [FluidPropertyTypes ] = pd .Field (alias = "fluidProperties" )
956
+ fluid_properties : Optional [FluidPropertyTypes ] = pd .Field (
957
+ alias = "fluidProperties" , discriminator = "model_type"
958
+ )
953
959
boundaries : Boundaries = pd .Field ()
954
960
initial_condition : Optional [InitialConditions ] = pd .Field (
955
961
alias = "initialCondition" , discriminator = "type"
@@ -1065,7 +1071,7 @@ def to_solver(self) -> Flow360Params:
1065
1071
return super ().to_solver (self , exclude = ["fluid_properties" ])
1066
1072
return super ().to_solver (self , exclude = ["fluid_properties" ])
1067
1073
1068
- def to_flow360_json (self ) -> dict :
1074
+ def to_flow360_json (self ) -> str :
1069
1075
"""Generate a JSON representation of the model, as required by Flow360
1070
1076
1071
1077
Returns
@@ -1083,6 +1089,22 @@ def to_flow360_json(self) -> dict:
1083
1089
solver_params_json = solver_params .json (encoder = flow360_json_encoder )
1084
1090
return solver_params_json
1085
1091
1092
+ def to_flow360_dict (self ) -> dict :
1093
+ """Generate a dict representation of the model, as required by Flow360
1094
+
1095
+ Returns
1096
+ -------
1097
+ dict
1098
+ Returns dict representation of the model.
1099
+
1100
+ Example
1101
+ -------
1102
+ >>> params.to_flow360_dict() # doctest: +SKIP
1103
+ """
1104
+
1105
+ flow360_dict = json .loads (self .to_flow360_json ())
1106
+ return flow360_dict
1107
+
1086
1108
def append (self , params : Flow360Params , overwrite : bool = False ):
1087
1109
if not isinstance (params , Flow360Params ):
1088
1110
raise ValueError ("params must be type of Flow360Params" )
0 commit comments