Documentation

## Heat Transfer in Block with Cavity

This example shows how to solve for the heat distribution in a block with cavity.

Consider a block containing a rectangular crack or cavity. The left side of the block is heated to 100 degrees centigrade. At the right side of the block, heat flows from the block to the surrounding air at a constant rate, for example $-10W/{m}^{2}$. All the other boundaries are insulated. The temperature in the block at the starting time ${t}_{0}=0$ is 0 degrees. The goal is to model the heat distribution during the first five seconds.

The `crackg.m` file describes the geometry of the block.

```thermalmodel = createpde('thermal','transient'); geometryFromEdges(thermalmodel,@crackg);```

Plot the geometry with edge labels.

```pdegplot(thermalmodel,'EdgeLabels','on'); ylim([-1,1]) axis equal```

Assume that the block has these thermal properties.

```thermalProperties(thermalmodel,'ThermalConductivity',1,... 'MassDensity',1,... 'SpecificHeat',1);```

Set the boundary conditions to have the solution `u` equal to `20` on the left edge (edge 6), and `g` equal to `-10` on the right edge (edge 1). The boundary condition on edge 1 corresponds to constant heat flow to the exterior. The toolbox uses the default insulating boundary condition for all other boundaries.

```thermalBC(thermalmodel,'Edge',6,'Temperature',20); thermalBC(thermalmodel,'Edge',1,'HeatFlux',-10);```

Set an initial value of `0` for the temperature.

`thermalIC(thermalmodel,0);`

Set solution times to be 0 to 5 in steps of 1/2.

`tlist = 0:0.5:5;`

Create a mesh and solve the problem.

```generateMesh(thermalmodel); thermalresults = solve(thermalmodel,tlist); T = thermalresults.Temperature;```

Compute the heat flux density. Plot the solution at t = 5.0 seconds with isothermal lines using a contour plot, and plot the heat flux vector field using arrows.

```[qx,qy] = evaluateHeatFlux(thermalresults); pdeplot(thermalmodel,'XYData',T(:,end),'Contour','on',... 'FlowData',[qx(:,end),qy(:,end)],'ColorMap','hot')```