Skip to content

[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

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

damiano-flex
Copy link

@damiano-flex damiano-flex commented Jul 24, 2025

Greptile Summary

This PR introduces a new NaturalConvectionVerticalSpec class to enhance thermal boundary condition modeling in the Tidy3D framework. The class enables automatic calculation of heat transfer coefficients for natural convection from vertical plates based on fluid properties rather than requiring manual coefficient specification.

The implementation follows standard heat transfer engineering practices by using Rayleigh number calculations and appropriate Nusselt number correlations to determine heat transfer coefficients. It supports both laminar and turbulent flow regimes based on critical Rayleigh number thresholds. The class accepts comprehensive fluid property inputs including thermal conductivity, viscosity, density, specific heat, and thermal expansion coefficient.

The integration is achieved by extending the existing ConvectionBC.transfer_coeff field to accept either a simple float (existing behavior) or the new NaturalConvectionVerticalSpec object, maintaining backward compatibility. The class is properly exported through the main package interface and integrated into the TCAD types system, following established patterns in the codebase for thermal boundary conditions.

Confidence score: 2/5

  • This PR has significant issues that could cause problems if merged, particularly around unit consistency and incomplete implementation
  • The unit system mismatch between SI units and Tidy3D's micrometer-based system could lead to incorrect calculations, and the _compute_parameters method returns unused values suggesting incomplete integration
  • Files tidy3d/components/tcad/boundary/heat.py needs immediate attention for unit consistency, parameter validation, and completion of the computation logic

@damiano-flex damiano-flex requested a review from marc-flex July 24, 2025 15:54
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 5 comments

Edit Code Review Bot Settings | Greptile

Comment on lines 133 to 136
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
Copy link

Choose a reason for hiding this comment

The 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.

@damiano-flex damiano-flex force-pushed the damiano/natural_convection_BC branch from bbe0d31 to f737cae Compare July 24, 2025 16:00

This comment was marked as outdated.

@damiano-flex damiano-flex force-pushed the damiano/natural_convection_BC branch from f737cae to bbe0d31 Compare July 28, 2025 17:14
@damiano-flex damiano-flex changed the title [FXC-1512]: [DRAFT]: Add natural convection BC [FXC-1512]: Add natural convection BC Jul 30, 2025
Copy link
Contributor

@marc-flex marc-flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @damiano-flex ! This is looking very good from the get-go!

Apart from the minor comments that I left we're missing unit tests. I think once you add these we'll be good to go

Comment on lines 58 to 64
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.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The 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 from_si_units and maybe add a couple of examples like with the rest of the BC classes: one using the standard constructor and another one with the from_si_units function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can help readability.

Copy link
Contributor

@dbochkov-flexcompute dbochkov-flexcompute left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks all makes sense, but I would add all required fluid parameters into FluidMedium (probably using more explicit names like viscosity, expansivity, etc, to be consistent with SolidMedium) and make this new convection bc automatically get those parameters from fluids it touches. It means that we also need to add a validator that checks that these pararmeters are defined for fluid mediums in our simulations if natural convection is used.

Additionally, I would also move _compute_parameters to the backend

Comment on lines 67 to 95
fluid_k: pd.NonNegativeFloat = pd.Field(
title="Fluid Thermal Conductivity",
description="Thermal conductivity (k) of the fluid.",
units=THERMAL_CONDUCTIVITY,
)
fluid_mu: pd.NonNegativeFloat = pd.Field(
title="Fluid Dynamic Viscosity",
description="Dynamic viscosity (μ) of the fluid.",
units=DYNAMIC_VISCOSITY,
)
fluid_Cp: pd.NonNegativeFloat = pd.Field(
title="Fluid Specific Heat",
description="Specific heat of the fluid at constant pressure.",
units=SPECIFIC_HEAT,
)
fluid_rho: pd.NonNegativeFloat = pd.Field(
title="Fluid Density",
description="Density (ρ) of the fluid.",
units=DENSITY,
)
fluid_beta: pd.NonNegativeFloat = pd.Field(
title="Fluid Thermal Expansivity",
description="Thermal expansion coefficient (β) of the fluid.",
units=THERMAL_EXPANSIVITY,
)
plate_L: pd.NonNegativeFloat = pd.Field(
title="Plate Characteristic Length",
description="Characteristic length (L), defined as the height of the vertical plate.",
units=MICROMETER,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should all fluid properties be pulled automatically from medium properties that touches that boundary? Sounds like we should expand heat_spec with these additional properties. For other parameters I would use more explicit names: plate_L -> plate_length

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some thoughts before answer this comment. Ultimately, I agree, pulling medium properties seems indeed an appropriate choice. If one wants to add 4 natural convection walls the code would look like much more cleaner.

@dbochkov-flexcompute
Copy link
Contributor

I would add all required fluid parameters into FluidMedium (probably using more explicit names like viscosity, expansivity, etc, to be consistent with SolidMedium) and make this new convection bc automatically get those parameters from fluids it touches. It means that we also need to add a validator that checks that these pararmeters are defined for fluid mediums in our simulations if natural convection is used.

Some more out-loud thinking:

Probably still need to have a medium parameter in the natural convection if one wants to define it on a simulation boundary, something like

h_spec = NaturalConvectionVerticalSpec(medium=None, plate_length=1)  # automatically determine which mediums are touched
h_spec = NaturalConvectionVerticalSpec(medium=oil, plate_length=1)  # use parameters defined in oil

Might also make sense to restrict automatic medium=None to StructureStructureInterface and MediumMediumInterface boundary placements only so that we can easily validate that one medium is solid and the other is fluid with all necessary parameters. And always require medium for other boundary placements

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants