Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(): temperature_offset has same unit conversion as temperature #668

Merged
merged 8 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/migration_guide/extra_operating_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
ThermalState,
)
from flow360.component.simulation.unit_system import (
AbsoluteTemperatureType,
AngleType,
LengthType,
TemperatureType,
)
from flow360.log import log

Expand All @@ -24,7 +24,7 @@ def operating_condition_from_mach_muref(
project_length_unit: LengthType.Positive = pd.Field(
description="The Length unit of the project."
),
temperature: TemperatureType.Positive = 288.15 * u.K,
temperature: AbsoluteTemperatureType = 288.15 * u.K,
alpha: Optional[AngleType] = 0 * u.deg,
beta: Optional[AngleType] = 0 * u.deg,
reference_mach: Optional[pd.PositiveFloat] = None,
Expand Down
3 changes: 3 additions & 0 deletions flow360/component/simulation/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ def get_base_thermal_conductivity():
elif dimension == u.dimensions.temperature:
base_temperature = get_base_temperature()
flow360_conversion_unit_system.base_temperature = base_temperature
# Flow360 uses absolute temperature for scaling.
# So the base_delta_temperature and base_temperature can have same scaling.
flow360_conversion_unit_system.base_delta_temperature = base_temperature

elif dimension == u.dimensions.area:
base_length = get_base_length()
Expand Down
22 changes: 11 additions & 11 deletions flow360/component/simulation/models/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import flow360.component.simulation.units as u
from flow360.component.simulation.framework.base_model import Flow360BaseModel
from flow360.component.simulation.unit_system import (
AbsoluteTemperatureType,
DensityType,
PressureType,
SpecificHeatCapacityType,
TemperatureType,
ThermalConductivityType,
VelocityType,
ViscosityType,
Expand Down Expand Up @@ -50,23 +50,23 @@ class Sutherland(Flow360BaseModel):
reference_viscosity: ViscosityType.NonNegative = pd.Field(
description="The reference dynamic viscosity at the reference temperature."
)
reference_temperature: TemperatureType.Positive = pd.Field(
reference_temperature: AbsoluteTemperatureType = pd.Field(
description="The reference temperature associated with the reference viscosity."
)
effective_temperature: TemperatureType.Positive = pd.Field(
effective_temperature: AbsoluteTemperatureType = pd.Field(
description="The effective temperature constant used in Sutherland's formula."
)

@pd.validate_call
def get_dynamic_viscosity(
self, temperature: TemperatureType.Positive
self, temperature: AbsoluteTemperatureType
) -> ViscosityType.NonNegative:
"""
Calculates the dynamic viscosity at a given temperature using Sutherland's law.

Parameters
----------
temperature : TemperatureType.Positive
temperature : AbsoluteTemperatureType
The temperature at which to calculate the dynamic viscosity.

Returns
Expand Down Expand Up @@ -154,7 +154,7 @@ def prandtl_number(self) -> pd.PositiveFloat:

@pd.validate_call
def get_pressure(
self, density: DensityType.Positive, temperature: TemperatureType.Positive
self, density: DensityType.Positive, temperature: AbsoluteTemperatureType
) -> PressureType.Positive:
"""
Calculates the pressure of air using the ideal gas law.
Expand All @@ -163,7 +163,7 @@ def get_pressure(
----------
density : DensityType.Positive
The density of the air.
temperature : TemperatureType.Positive
temperature : AbsoluteTemperatureType
The temperature of the air.

Returns
Expand All @@ -174,13 +174,13 @@ def get_pressure(
return density * self.gas_constant * temperature

@pd.validate_call
def get_speed_of_sound(self, temperature: TemperatureType.Positive) -> VelocityType.Positive:
def get_speed_of_sound(self, temperature: AbsoluteTemperatureType) -> VelocityType.Positive:
"""
Calculates the speed of sound in air at a given temperature.

Parameters
----------
temperature : TemperatureType.Positive
temperature : AbsoluteTemperatureType
The temperature at which to calculate the speed of sound.

Returns
Expand All @@ -192,14 +192,14 @@ def get_speed_of_sound(self, temperature: TemperatureType.Positive) -> VelocityT

@pd.validate_call
def get_dynamic_viscosity(
self, temperature: TemperatureType.Positive
self, temperature: AbsoluteTemperatureType
) -> ViscosityType.NonNegative:
"""
Calculates the dynamic viscosity of air at a given temperature.

Parameters
----------
temperature : TemperatureType.Positive
temperature : AbsoluteTemperatureType
The temperature at which to calculate the dynamic viscosity.

Returns
Expand Down
6 changes: 3 additions & 3 deletions flow360/component/simulation/models/surface_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
SurfacePair,
)
from flow360.component.simulation.unit_system import (
AbsoluteTemperatureType,
HeatFluxType,
LengthType,
MassFlowRateType,
PressureType,
TemperatureType,
)

# pylint: disable=fixme
Expand Down Expand Up @@ -90,7 +90,7 @@ class Temperature(SingleAttributeModel):

type_name: Literal["Temperature"] = pd.Field("Temperature", frozen=True)
# pylint: disable=no-member
value: Union[StringExpression, TemperatureType.Positive] = pd.Field(
value: Union[StringExpression, AbsoluteTemperatureType] = pd.Field(
description="The temperature value."
)

Expand Down Expand Up @@ -378,7 +378,7 @@ class Inflow(BoundaryBaseWithTurbulenceQuantities):
name: Optional[str] = pd.Field(None, description="Name of the `Inflow` boundary condition.")
type: Literal["Inflow"] = pd.Field("Inflow", frozen=True)
# pylint: disable=no-member
total_temperature: TemperatureType.Positive = pd.Field(
total_temperature: AbsoluteTemperatureType = pd.Field(
description="Specify the total temperature at the `Inflow` boundary."
)
velocity_direction: Optional[Axis] = pd.Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
StandardAtmosphereModel,
)
from flow360.component.simulation.unit_system import (
AbsoluteTemperatureType,
AngleType,
DeltaTemperatureType,
DensityType,
LengthType,
PressureType,
TemperatureType,
VelocityType,
ViscosityType,
)
Expand All @@ -45,7 +46,7 @@ class ThermalStateCache(Flow360BaseModel):

# pylint: disable=no-member
altitude: Optional[LengthType] = None
temperature_offset: Optional[TemperatureType] = None
temperature_offset: Optional[DeltaTemperatureType] = None


class ThermalState(MultiConstructorBaseModel):
Expand All @@ -65,9 +66,9 @@ class ThermalState(MultiConstructorBaseModel):
"""

# pylint: disable=fixme
# TODO: romove frozen and throw warning if temperature/density is modified after construction from atmospheric model
# TODO: remove frozen and throw warning if temperature/density is modified after construction from atmospheric model
type_name: Literal["ThermalState"] = pd.Field("ThermalState", frozen=True)
temperature: TemperatureType.Positive = pd.Field(
temperature: AbsoluteTemperatureType = pd.Field(
288.15 * u.K, frozen=True, description="The temperature of the fluid."
)
density: DensityType.Positive = pd.Field(
Expand All @@ -87,7 +88,7 @@ class ThermalState(MultiConstructorBaseModel):
def from_standard_atmosphere(
cls,
altitude: LengthType = 0 * u.m,
temperature_offset: TemperatureType = 0 * u.K,
temperature_offset: DeltaTemperatureType = 0 * u.K,
):
"""
Constructs a :class:`ThermalState` instance from the standard atmosphere model.
Expand All @@ -96,7 +97,7 @@ def from_standard_atmosphere(
----------
altitude : LengthType, optional
The altitude at which the thermal state is calculated. Defaults to ``0 * u.m``.
temperature_offset : TemperatureType, optional
temperature_offset : DeltaTemperatureType, optional
The temperature offset to be applied to the standard temperature at the given altitude.
Defaults to ``0 * u.K``.

Expand All @@ -122,11 +123,11 @@ def from_standard_atmosphere(
>>> thermal_state.density
<calculated_density>

Apply a temperature offset of -5 Kelvin at 5,000 meters:
Apply a temperature offset of -5 Fahrenheit at 5,000 meters:

>>> thermal_state = ThermalState.from_standard_atmosphere(
... altitude=5000 * u.m,
... temperature_offset=-5 * u.K
... temperature_offset=-5 * u.delta_degF
... )
>>> thermal_state.temperature
<adjusted_temperature>
Expand All @@ -147,16 +148,16 @@ def from_standard_atmosphere(
@property
def altitude(self) -> Optional[LengthType]:
"""Return user specified altitude."""
if not self._cached.altitude:
if not self.private_attribute_input_cache.altitude:
log.warning("Altitude not provided from input")
return self._cached.altitude
return self.private_attribute_input_cache.altitude

@property
def temperature_offset(self) -> Optional[TemperatureType]:
def temperature_offset(self) -> Optional[DeltaTemperatureType]:
"""Return user specified temperature offset."""
if not self._cached.altitude:
if not self.private_attribute_input_cache.temperature_offset:
log.warning("Temperature offset not provided from input")
return self._cached.temperature_offset
return self.private_attribute_input_cache.temperature_offset

@property
def speed_of_sound(self) -> VelocityType.Positive:
Expand Down Expand Up @@ -410,7 +411,7 @@ def operating_condition_from_mach_reynolds(
project_length_unit: LengthType.Positive = pd.Field(
description="The Length unit of the project."
),
temperature: TemperatureType.Positive = 288.15 * u.K,
temperature: AbsoluteTemperatureType = 288.15 * u.K,
alpha: Optional[AngleType] = 0 * u.deg,
beta: Optional[AngleType] = 0 * u.deg,
reference_mach: Optional[pd.PositiveFloat] = None,
Expand All @@ -430,7 +431,7 @@ def operating_condition_from_mach_reynolds(
Freestream Reynolds number defined with mesh unit (must be positive).
project_length_unit: LengthType.Positive
Project length unit.
temperature : TemperatureType.Positive, optional
temperature : AbsoluteTemperatureType, optional
Freestream static temperature (must be a positive temperature value). Default is 288.15 Kelvin.
alpha : AngleType, optional
Angle of attack. Default is 0 degrees.
Expand Down
Loading
Loading