## Temperature Distribution in Heat Sink

This example shows how to create a simple 3-D heat sink geometry and analyze heat transfer on the heat sink. The process has three steps.

### Create 2-D Geometry in PDE Modeler App

Create a geometry in the PDE Modeler app. First, open the PDE Modeler app with a geometry consisting of a rectangle and 12 circles.

pderect([0 0.01 0 0.008]) for i = 0.002:0.002:0.008 for j = 0.002:0.002:0.006 pdecirc(i,j,0.0005) end end

Adjust the axes limits by selecting **Options** > **Axes Limits**. Select **Auto** to use automatic scaling for both
axes.

Export the geometry description matrix, set formula, and name-space matrix into the
MATLAB^{®} workspace by selecting **Draw** > **Export Geometry Description, Set Formula, Labels**. This data lets you reconstruct the geometry in the workspace.

### Extrude 2-D Geometry into 3-D Geometry of Heat Sink

In the MATLAB Command Window, use the `decsg`

function to decompose
the exported geometry into minimal regions. Plot the result.

```
g = decsg(gd,sf,ns);
pdegplot(g,FaceLabels="on")
```

Create a 2-D geometry from the decomposed geometry matrix.

g = fegeometry(g);

Extrude the 2-D geometry along the *z*-axis by 0.0005 units.

g = extrude(g,0.0005);

Plot the extruded geometry so that you can see the face labels on the top.

```
figure
pdegplot(g,FaceLabels="on")
view([0 90])
```

Extrude the circular faces (faces with IDs from 15 to 26) along the
*z*-axis by 0.005 more units. These faces form the fins of the heat
sink.

g = extrude(g,[15:26],0.005);

Plot the geometry.

figure pdegplot(g)

### Perform Thermal Analysis

Create an `femodel`

object for transient thermal analysis and include
the geometry.

model = femodel(AnalysisType="thermalTransient", ... Geometry = g);

Assuming that the heat sink is made of copper, specify the thermal conductivity, mass density, and specific heat.

model.MaterialProperties = ... materialProperties(ThermalConductivity=400, ... MassDensity=8960, ... SpecificHeat=386);

Specify the Stefan-Boltzmann constant.

model.StefanBoltzmann = 5.670367e-8;

Apply the temperature boundary condition on the bottom surface of the heat sink, which consists of 13 faces.

model.FaceBC(1:13) = faceBC(Temperature=1000);

Specify the convection and radiation parameters on all other surfaces of the heat sink.

model.FaceLoad(14:g.NumFaces) = ... faceLoad(ConvectionCoefficient=5, ... AmbientTemperature=300, ... Emissivity=0.8);

Set the initial temperature of all the surfaces to the ambient temperature.

model.CellIC = cellIC(Temperature=300);

Generate a mesh.

model = generateMesh(model);

Solve the transient thermal problem for times between 0 and 0.0075 s with a time step of 0.0025 s.

results = solve(model,0:0.0025:0.0075);

Plot the temperature distribution for each time step.

for i = 1:length(results.SolutionTimes) figure pdeplot3D(results.Mesh,ColorMapData=results.Temperature(:,i)) title({['Time = ' num2str(results.SolutionTimes(i)) 's']}) end

You also can plot the same results by using the **Visualize PDE
Results** Live Editor task. First, create a new live script by clicking the
**New Live Script** button in the **File**
section on the **Home** tab.

On the **Live Editor** tab, select **Task** > **Visualize PDE Results**. This action inserts the task into your script.

To plot the temperature distribution for each time step, follow these steps.

In the

**Select results**section of the task, select`results`

from the drop-down list.In the

**Specify data parameters**section of the task, set**Type**to*Temperature*, and set the time steps to 1, 2, 3, and 4. These time steps correspond to the four time values that you used to solve the problem. You also can animate the solution by selecting**Animate**.