## 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 thermal model for transient analysis.

`model = createpde("thermal","transient");`

Create a 2-D geometry from the decomposed geometry matrix and assign the geometry to the thermal model.

`g = geometryFromEdges(model,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);`

Assign the modified geometry to the thermal model and plot the geometry.

```model.Geometry = g; figure pdegplot(g)``` ### Perform Thermal Analysis

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

```thermalProperties(model,"ThermalConductivity",400, ... "MassDensity",8960, ... "SpecificHeat",386);```

Specify the Stefan-Boltzmann constant.

`model.StefanBoltzmannConstant = 5.670367e-8;`

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

`thermalBC(model,"Face",1:13,"Temperature",1000);`

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

```thermalBC(model,"Face",14:g.NumFaces, ... "ConvectionCoefficient",5, ... "AmbientTemperature",300, ... "Emissivity",0.8);```

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

`thermalIC(model,300);`

Generate a mesh.

`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(model,"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 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.

1. In the Select results section of the task, select `results` from the drop-down list.

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