# thermalBC

Specify boundary conditions for a thermal model

**Domain-specific heat transfer workflow is not recommended. New features might not be
compatible with this workflow. For help migrating your existing code to the unified
finite element workflow, see Migration from Domain-Specific to Unified Workflow.**

## Syntax

## Description

`thermalBC(`

adds a temperature boundary condition to `thermalmodel`

,`RegionType`

,`RegionID`

,"Temperature",`Tval`

)`thermalmodel`

. The
boundary condition applies to regions of type `RegionType`

with
ID numbers in `RegionID`

.

`thermalBC(`

adds a heat flux boundary condition to `thermalmodel`

,`RegionType`

,`RegionID`

,"HeatFlux",`HFval`

)`thermalmodel`

. The
boundary condition applies to regions of type `RegionType`

with
ID numbers in `RegionID`

.

**Note**

Use `thermalBC`

with the `HeatFlux`

parameter to specify a heat flux to or from an external source. To specify
internal heat generation, that is, heat sources that belong to the geometry
of the model, use `internalHeatSource`

.

`thermalBC(`

adds a convection boundary condition to `thermalmodel`

,`RegionType`

,`RegionID`

,"ConvectionCoefficient",`CCval`

,"AmbientTemperature",`ATval`

)`thermalmodel`

. The
boundary condition applies to regions of type `RegionType`

with
ID numbers in `RegionID`

.

`thermalBC(`

adds a radiation boundary condition to `thermalmodel`

,`RegionType`

,`RegionID`

,"Emissivity",`REval`

,"AmbientTemperature",`ATval`

)`thermalmodel`

. The
boundary condition applies to regions of type `RegionType`

with
ID numbers in `RegionID`

.

`thermalBC(___,"Label",`

adds a label for the thermal boundary condition to be used by the `labeltext`

)`linearizeInput`

function. This function lets you pass thermal
boundary conditions to the `linearize`

function that extracts sparse linear models for use with Control System Toolbox™.

returns the thermal boundary condition object.`thermalBC`

= thermalBC(___)

## Examples

### Specify Temperature on the Boundary

Apply temperature boundary condition on two edges of a square.

thermalmodel = createpde("thermal"); geometryFromEdges(thermalmodel,@squareg); thermalBC(thermalmodel,"Edge",[1,3],"Temperature",100)

ans = ThermalBC with properties: RegionType: 'Edge' RegionID: [1 3] Temperature: 100 HeatFlux: [] ConvectionCoefficient: [] Emissivity: [] AmbientTemperature: [] Vectorized: 'off' Label: []

### Specify Heat Coming Through the Boundary

Apply heat flux boundary condition on two faces of a block.

thermalmodel = createpde("thermal","transient"); gm = importGeometry(thermalmodel,"Block.stl"); thermalBC(thermalmodel,"Face",[1,3],"HeatFlux",20)

ans = ThermalBC with properties: RegionType: 'Face' RegionID: [1 3] Temperature: [] HeatFlux: 20 ConvectionCoefficient: [] Emissivity: [] AmbientTemperature: [] Vectorized: 'off' Label: []

### Specify Convection on the Boundary

Apply convection boundary condition on four faces of a block.

thermalModel = createpde("thermal","transient"); gm = importGeometry(thermalModel,"Block.stl"); thermalBC(thermalModel,"Face",[2 4 5 6], ... "ConvectionCoefficient",5, ... "AmbientTemperature",27)

ans = ThermalBC with properties: RegionType: 'Face' RegionID: [2 4 5 6] Temperature: [] HeatFlux: [] ConvectionCoefficient: 5 Emissivity: [] AmbientTemperature: 27 Vectorized: 'off' Label: []

### Specify Radiation Through the Boundary

Apply radiation boundary condition on four faces of a block.

thermalmodel = createpde("thermal","transient"); gm = importGeometry(thermalmodel,"Block.stl"); thermalmodel.StefanBoltzmannConstant = 5.670373E-8; thermalBC(thermalmodel,"Face",[2,4,5,6],... "Emissivity",0.1,... "AmbientTemperature",300)

ans = ThermalBC with properties: RegionType: 'Face' RegionID: [2 4 5 6] Temperature: [] HeatFlux: [] ConvectionCoefficient: [] Emissivity: 0.1000 AmbientTemperature: 300 Vectorized: 'off' Label: []

### Specify Nonconstant Thermal Boundary Conditions

Use function handles to specify thermal boundary conditions that depend on coordinates.

Create a thermal model for transient analysis and include the geometry. The geometry is a rod with a circular cross section. The 2-D model is a rectangular strip whose *y*-dimension extends from the axis of symmetry to the outer surface, and whose *x*-dimension extends over the actual length of the rod.

thermalmodel = createpde("thermal","transient"); g = decsg([3 4 -1.5 1.5 1.5 -1.5 0 0 .2 .2]'); geometryFromEdges(thermalmodel,g);

Plot the geometry.

figure pdegplot(thermalmodel,"EdgeLabels","on"); xlim([-2 2]); ylim([-2 2]); title 'Rod Section Geometry with Edge Labels'

Assume that there is a heat source at the left end of the rod and a fixed temperature at the right end. The outer surface of the rod exchanges heat with the environment due to convection.

Define the boundary conditions for the model. The edge at *y *= 0 (edge 1) is along the axis of symmetry. No heat is transferred in the direction normal to this edge. This boundary is modeled as an insulated boundary, by default.

The temperature at the right end of the rod (edge 2) is a fixed temperature, T = 100 C. Specify the boundary condition for edge 2 as follows.

thermalBC(thermalmodel,"Edge",2,"Temperature",100)

ans = ThermalBC with properties: RegionType: 'Edge' RegionID: 2 Temperature: 100 HeatFlux: [] ConvectionCoefficient: [] Emissivity: [] AmbientTemperature: [] Vectorized: 'off' Label: []

The convection coefficient for the outer surface of the rod (edge 3) depends on the *y*-coordinate, 50*y.* Specify the boundary condition for this edge as follows.

outerCC = @(location,~) 50*location.y; thermalBC(thermalmodel,"Edge",3,... "ConvectionCoefficient",outerCC,... "AmbientTemperature",100)

ans = ThermalBC with properties: RegionType: 'Edge' RegionID: 3 Temperature: [] HeatFlux: [] ConvectionCoefficient: @(location,~)50*location.y Emissivity: [] AmbientTemperature: 100 Vectorized: 'off' Label: []

The heat flux at the left end of the rod (edge 4) is also a function of the *y*-coordinate, 5000*y. *Specify the boundary condition for this edge as follows.

leftHF = @(location,~) 5000*location.y; thermalBC(thermalmodel,"Edge",4,"HeatFlux",leftHF)

ans = ThermalBC with properties: RegionType: 'Edge' RegionID: 4 Temperature: [] HeatFlux: @(location,~)5000*location.y ConvectionCoefficient: [] Emissivity: [] AmbientTemperature: [] Vectorized: 'off' Label: []

## Input Arguments

`thermalmodel`

— Thermal model

`ThermalModel`

object

Thermal model, specified as a `ThermalModel`

object.
The model contains the geometry, mesh, thermal properties of the material,
internal heat source, boundary conditions, and initial conditions.

**Example: **`thermalmodel = createpde("thermal","steadystate")`

`RegionType`

— Geometric region type

`"Edge"`

for a 2-D model | `"Face"`

for a 3-D model

Geometric region type, specified as `"Edge"`

or
`"Face"`

.

**Example: **`thermalBC(thermalmodel,"Face",1,"Temperature",72)`

**Data Types: **`char`

`RegionID`

— Geometric region ID

vector of positive integers

Geometric region ID, specified as a vector of positive integers. Find the
region IDs by using `pdegplot`

with the
`"FaceLabels"`

(3-D) or `"EdgeLabels"`

(2-D) value set to `"on"`

.

**Example: **`thermalBC(thermalmodel,"Edge",2:5,"Temperature",72)`

**Data Types: **`double`

`Tval`

— Temperature boundary condition

number | function handle

Temperature boundary condition, specified as a number or a function handle. Use a function handle to specify the temperature that depends on space and time. For details, see More About.

**Example: **`thermalBC(thermalmodel,"Face",1,"Temperature",72)`

**Data Types: **`double`

| `function_handle`

`HFval`

— Heat flux boundary condition

number | function handle

Heat flux boundary condition, specified as a number or a function handle. Use a function handle to specify the heat flux that depends on space and time. For details, see More About.

**Example: **`thermalBC(thermalmodel,"Face",[1,3],"HeatFlux",20)`

**Data Types: **`double`

| `function_handle`

`CCval`

— Coefficient for convection to ambient heat transfer condition

number | function handle

Convection to ambient boundary condition, specified as a number or a function handle. Use a function handle to specify the convection coefficient that depends on space and time. For details, see More About.

Specify ambient temperature using the
`AmbientTemperature`

argument. The value of
`ConvectionCoefficient`

is positive for heat convection
into the ambient environment.

**Example: **`thermalBC(thermalmodel,"Edge",[2,4],"ConvectionCoefficient",5,"AmbientTemperature",60)`

**Data Types: **`double`

| `function_handle`

`REval`

— Radiation emissivity coefficient

number in the range (0,1)

Radiation emissivity coefficient, specified as a number in the range (0,1). Use a function handle to specify the radiation emissivity that depends on space and time. For details, see More About.

Specify ambient temperature using the
`AmbientTemperature`

argument and the Stefan-Boltzmann
constant using the thermal model properties. The value of
`Emissivity`

is positive for heat radiation into the
ambient environment.

**Example: **```
thermalmodel.StefanBoltzmannConstant = 5.670373E-8;
thermalBC(thermalmodel,"Edge",[2,4,5,6],"Emissivity",0.1,"AmbientTemperature",300)
```

**Data Types: **`double`

| `function_handle`

`ATval`

— Ambient temperature

number

Ambient temperature, specified as a number. The ambient temperature value is required for specifying convection and radiation boundary conditions.

**Example: **`thermalBC(thermalmodel,"Edge",[2,4],"ConvectionCoefficient",5,"AmbientTemperature",60)`

**Data Types: **`double`

`labeltext`

— Label for thermal boundary condition

character vector | string

Label for the thermal boundary condition, specified as a character vector or a string.

**Data Types: **`char`

| `string`

## Output Arguments

`thermalBC`

— Handle to thermal boundary condition

`ThermalBC`

object

Handle to thermal boundary condition, returned as a
`ThermalBC`

object. See ThermalBC Properties.

`thermalBC`

associates the thermal boundary condition
with the geometric region.

## More About

### Specifying Nonconstant Parameters of a Thermal Model

Use a function handle to specify these thermal parameters when they depend on space, temperature, and time:

Thermal conductivity of the material

Mass density of the material

Specific heat of the material

Internal heat source

Temperature on the boundary

Heat flux through the boundary

Convection coefficient on the boundary

Radiation emissivity coefficient on the boundary

Initial temperature (can depend on space only)

For example, use function handles to specify the thermal conductivity, internal heat source, convection coefficient, and initial temperature for this model.

thermalProperties(model,"ThermalConductivity", ... @myfunConductivity) internalHeatSource(model,"Face",2,@myfunHeatSource) thermalBC(model,"Edge",[3,4], ... "ConvectionCoefficient",@myfunBC, ... "AmbientTemperature",27) thermalIC(model,@myfunIC)

For all parameters, except the initial temperature, the function must be of the form:

`function thermalVal = myfun(location,state)`

For the initial temperature the function must be of the form:

`function thermalVal = myfun(location)`

The solver computes and populates the data in the `location`

and
`state`

structure arrays and passes this data to your function. You can
define your function so that its output depends on this data. You can use any names instead of
`location`

and `state`

, but the function must have exactly
two arguments (or one argument if the function specifies the initial temperature).

`location`

— A structure containing these fields:`location.x`

— The*x*-coordinate of the point or points`location.y`

— The*y*-coordinate of the point or points`location.z`

— For a 3-D or an axisymmetric geometry, the*z*-coordinate of the point or points`location.r`

— For an axisymmetric geometry, the*r*-coordinate of the point or points

Furthermore, for boundary conditions, the solver passes these data in the

`location`

structure:`location.nx`

—*x*-component of the normal vector at the evaluation point or points`location.ny`

—*y*-component of the normal vector at the evaluation point or points`location.nz`

— For a 3-D or an axisymmetric geometry,*z*-component of the normal vector at the evaluation point or points`location.nr`

— For an axisymmetric geometry,*r*-component of the normal vector at the evaluation point or points

`state`

— A structure containing these fields for transient or nonlinear problems:`state.u`

— Temperatures at the corresponding points of the location structure`state.ux`

— Estimates of the*x*-component of temperature gradients at the corresponding points of the location structure`state.uy`

— Estimates of the*y*-component of temperature gradients at the corresponding points of the location structure`state.uz`

— For a 3-D or an axisymmetric geometry, estimates of the*z*-component of temperature gradients at the corresponding points of the location structure`state.ur`

— For an axisymmetric geometry, estimates of the*r*-component of temperature gradients at the corresponding points of the location structure`state.time`

— Time at evaluation points

Thermal material properties (thermal conductivity, mass density, and specific heat) and internal heat source get these data from the solver:

`location.x`

,`location.y`

,`location.z`

,`location.r`

Subdomain ID

`state.u`

,`state.ux`

,`state.uy`

,`state.uz`

,`state.r`

,`state.time`

Boundary conditions (temperature on the boundary, heat flux, convection coefficient, and radiation emissivity coefficient) get these data from the solver:

`location.x`

,`location.y`

,`location.z`

,`location.r`

`location.nx`

,`location.ny`

,`location.nz`

,`location.nr`

`state.u`

,`state.time`

Initial temperature gets the following data from the solver:

`location.x`

,`location.y`

,`location.z`

,`location.r`

Subdomain ID

For all thermal parameters, except for thermal conductivity, your function must return a row
vector `thermalVal`

with the number of columns
equal to the number of evaluation points, for example, ```
M =
length(location.y)
```

.

For thermal conductivity, your function must return a matrix
`thermalVal`

with number of rows equal to 1, `Ndim`

,
`Ndim*(Ndim+1)/2`

, or `Ndim*Ndim`

, where
`Ndim`

is 2 for 2-D problems and 3 for 3-D problems. The number of columns
must equal the number of evaluation points, for example, ```
M =
length(location.y)
```

. For details about dimensions of the matrix, see c Coefficient for specifyCoefficients.

If properties depend on the time or temperature, ensure that your function returns a matrix of
`NaN`

of the correct size when `state.u`

or
`state.time`

are `NaN`

. Solvers check whether a problem is
time dependent by passing `NaN`

state values and looking for returned
`NaN`

values.

### Additional Arguments in Functions for Nonconstant Thermal Parameters

To use additional arguments in your function, wrap your function (that takes additional arguments) with an anonymous function that takes only the `location`

and `state`

arguments. For example:

thermalVal = ... @(location,state) myfunWithAdditionalArgs(location,state,arg1,arg2...) thermalBC(model,"Edge",3,"Temperature",thermalVal) thermalVal = @(location) myfunWithAdditionalArgs(location,arg1,arg2...) thermalIC(model,thermalVal)

## Version History

**Introduced in R2017a**

### R2021b: Label to extract sparse linear models for use with Control System Toolbox

Now you can add a label for thermal boundary conditions to be used by the
`linearizeInput`

function. This function lets you pass thermal
boundary conditions to the `linearize`

function that extracts sparse linear models for use with Control System Toolbox.

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)