-
Notifications
You must be signed in to change notification settings - Fork 63
[FXC-1512]: Add natural convection BC #2696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
a058736
bbe0d31
4e30131
fa13026
6541620
e7036eb
c3ea537
144650f
3494f6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
"""Defines heat material specifications""" | ||
|
||
from __future__ import annotations | ||
|
||
import pydantic.v1 as pd | ||
|
||
from typing import Union | ||
from tidy3d.components.tcad.boundary.abstract import HeatChargeBC | ||
from tidy3d.constants import HEAT_FLUX, HEAT_TRANSFER_COEFF, KELVIN | ||
|
||
|
||
class TemperatureBC(HeatChargeBC): | ||
|
@@ -39,6 +40,100 @@ | |
units=HEAT_FLUX, | ||
) | ||
|
||
#TODO Should I adapt to Tidy3D units (e.g. micrometers), or keep the original ones? | ||
THERMAL_CONDUCTIVITY_UNITS = "W/(m*K)" | ||
DYNAMIC_VISCOSITY_UNITS = "Pa*s" | ||
SPECIFIC_HEAT_UNITS = "J/(kg*K)" | ||
DENSITY_UNITS = "kg/m**3" | ||
THERMAL_EXPANSIVITY_UNITS = "1/K" | ||
LENGTH_UNITS = "m" | ||
ACCELERATION_UNITS = "m/s**2" | ||
damiano-flex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class NaturalConvectionVerticalSpec(HeatChargeBC): | ||
damiano-flex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Specification for natural convection from a vertical plate. | ||
|
||
This class calculates the heat transfer coefficient (h) based on fluid | ||
properties and an expected temperature difference, then provides these | ||
values as 'base' and 'exponent' for a generalized heat flux equation | ||
q = base * (T_surf - T_fluid)^exponent. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add in the docstring that one can define the constants in SI with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it can help readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add an example of how to create this BC. It'll be good for our docs |
||
# --- Input Parameters --- | ||
fluid_k: pd.NonNegativeFloat = pd.Field( | ||
title="Fluid Thermal Conductivity", | ||
description="Thermal conductivity (k) of the fluid.", | ||
units=THERMAL_CONDUCTIVITY_UNITS, | ||
) | ||
fluid_mu: pd.NonNegativeFloat = pd.Field( | ||
title="Fluid Dynamic Viscosity", | ||
description="Dynamic viscosity (μ) of the fluid.", | ||
units=DYNAMIC_VISCOSITY_UNITS, | ||
) | ||
fluid_Cp: pd.NonNegativeFloat = pd.Field( | ||
title="Fluid Specific Heat", | ||
description="Specific heat capacity (Cp) of the fluid at constant pressure.", | ||
units=SPECIFIC_HEAT_UNITS, | ||
) | ||
fluid_rho: pd.NonNegativeFloat = pd.Field( | ||
title="Fluid Density", | ||
description="Density (ρ) of the fluid.", | ||
units=DENSITY_UNITS, | ||
) | ||
fluid_beta: pd.NonNegativeFloat = pd.Field( | ||
title="Fluid Thermal Expansivity", | ||
description="Thermal expansion coefficient (β) of the fluid.", | ||
units=THERMAL_EXPANSIVITY_UNITS, | ||
) | ||
plate_L: pd.NonNegativeFloat = pd.Field( | ||
title="Plate Characteristic Length", | ||
description="Characteristic length (L), defined as the height of the vertical plate.", | ||
units=LENGTH_UNITS, | ||
) | ||
|
||
gravity: pd.NonNegativeFloat = pd.Field( | ||
default=9.80665, | ||
title="Gravitational Acceleration", | ||
description="Gravitational acceleration (g).", | ||
units=ACCELERATION_UNITS, | ||
) | ||
|
||
def _compute_parameters(self): | ||
damiano-flex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Calculate the Rayleigh Number (Ra_L) | ||
rayleigh_numerator_notemp = ( | ||
self.gravity | ||
* self.fluid_beta | ||
* self.fluid_rho ** 2 | ||
* self.fluid_Cp | ||
* self.plate_L ** 3 | ||
) | ||
rayleigh_denominator = self.fluid_mu * self.fluid_k | ||
Ra_L = rayleigh_numerator_notemp / rayleigh_denominator | ||
|
||
# Calculate the denominator term from the Nusselt number correlation | ||
# This term is related to the Prandtl Number (Pr = mu * Cp / k) | ||
pr_term_inner_num = 0.492 * self.fluid_k | ||
pr_term_inner_den = self.fluid_mu * self.fluid_Cp | ||
|
||
pr_term_inner = pr_term_inner_num / pr_term_inner_den | ||
pr_denominator = (1 + pr_term_inner ** (9 / 16)) ** (4 / 9) | ||
|
||
# Select formula based on flow regime (determined by Ra_L) | ||
if Ra_L <= 1e9: | ||
# Laminar Flow | ||
h_factor_linear = 0.68 | ||
h_factor_non_linear = (0.670 * Ra_L ** (1 / 6)) / pr_denominator | ||
elif 1e9 < Ra_L <= 1e13: | ||
# Turbulent Flow | ||
h_factor_linear = 0.825 | ||
h_factor_non_linear = (0.387 * Ra_L ** (1 / 6)) / pr_denominator | ||
else: | ||
raise ValueError(f"Ra_l={Ra_L} should be smaller than 1e13 for NaturalConvectionVerticalSpec") | ||
damiano-flex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
h = (self.fluid_k / self.plate_L) * h_factor_linear | ||
h_nonlinear = (self.fluid_k / self.plate_L) * h_factor_non_linear | ||
exponent = 1 + 1/6 | ||
return h, h_nonlinear, exponent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Method returns computed values but they're not used anywhere. Consider if this method should modify instance state or be called differently. |
||
|
||
class ConvectionBC(HeatChargeBC): | ||
"""Convective thermal boundary conditions. | ||
|
@@ -55,8 +150,12 @@ | |
units=KELVIN, | ||
) | ||
|
||
transfer_coeff: pd.NonNegativeFloat = pd.Field( | ||
transfer_coeff: Union[pd.NonNegativeFloat, NaturalConvectionVerticalSpec] = pd.Field( | ||
title="Heat Transfer Coefficient", | ||
description=f"Heat flux value in units of {HEAT_TRANSFER_COEFF}.", | ||
units=HEAT_TRANSFER_COEFF, | ||
) | ||
|
||
#TODO Maybe I should find a better place for these lines. | ||
NaturalConvectionVerticalSpec.update_forward_refs() | ||
ConvectionBC.update_forward_refs() | ||
damiano-flex marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.