Main Content

internalHeatSource

Specify internal heat source 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.

Description

internalHeatSource(thermalmodel,heatSourceValue) specifies an internal heat source for the thermal model. This syntax declares that the entire geometry is a heat source.

Note

Use internalHeatSource for specifying internal heat generators, that is, for specifying heat sources that belong to the geometry of the model. To specify a heat influx from an external source, use the thermalBC function with the HeatFlux parameter.

example

internalHeatSource(thermalmodel,heatSourceValue,RegionType,RegionID) specifies geometry regions of type RegionType with ID numbers in RegionID as heat sources. Always specify heatSourceValue first, then specify RegionType and RegionID.

example

internalHeatSource(___,"Label",labeltext) adds a label for the internal heat source to be used by the linearizeInput function. This function lets you pass internal heat sources to the linearize function that extracts sparse linear models for use with Control System Toolbox™.

heatSource = internalHeatSource(___) returns the heat source object.

Examples

collapse all

Create a transient thermal model.

thermalmodel = createpde("thermal","transient");

Import the geometry.

gm = importGeometry(thermalmodel,"SquareBeam.stl");

Set thermal conductivity to 0.2, mass density to 2700e-9, and specific heat to 920.

thermalProperties(thermalmodel,"ThermalConductivity",0.2, ...
                               "MassDensity",2700e-9, ...
                               "SpecificHeat",920)
ans = 
  ThermalMaterialAssignment with properties:

             RegionType: 'cell'
               RegionID: 1
    ThermalConductivity: 0.2000
            MassDensity: 2.7000e-06
           SpecificHeat: 920

Specify that the entire geometry generates heat at the rate 2e-4.

internalHeatSource(thermalmodel,2e-4)
ans = 
  HeatSourceAssignment with properties:

    RegionType: 'cell'
      RegionID: 1
    HeatSource: 2.0000e-04
         Label: []

Create a steady-state thermal model.

thermalModel = createpde("thermal","transient");

Create the geometry.

SQ1 = [3; 4; 0; 3; 3; 0; 0; 0; 3; 3];
D1 = [2; 4; 0.5; 1.5; 2.5; 1.5; 1.5; 0.5; 1.5; 2.5];
gd = [SQ1 D1];
sf = 'SQ1+D1';
ns = char('SQ1','D1');
ns = ns';
dl = decsg(gd,sf,ns);

geometryFromEdges(thermalModel,dl);

Set thermal conductivity to 50, mass density to 2500, and specific heat to 600.

thermalProperties(thermalModel,"ThermalConductivity",50, ...
                               "MassDensity",2500, ...
                               "SpecificHeat",600);

Specify that face 1 generates heat at 25.

internalHeatSource(thermalModel,25,"Face",1)
ans = 
  HeatSourceAssignment with properties:

    RegionType: 'face'
      RegionID: 1
    HeatSource: 25
         Label: []

Use a function handle to specify an internal heat source that depends 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 x-dimension extends from the axis of symmetry to the outer surface, and whose y-dimension extends over the actual length of the rod.

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

Figure contains an axes object. The axes object contains an object of type line.

The heat is generated within the rod due to the radioactive decay. Therefore, the entire geometry is an internal nonlinear heat source and can be represented by a function of the x-coordinate, for example, q=2000x.

q = @(location,state)2000*location.x;

Specify the internal heat source for the transient model.

internalHeatSource(thermalmodel,q)
ans = 
  HeatSourceAssignment with properties:

    RegionType: 'face'
      RegionID: 1
    HeatSource: @(location,state)2000*location.x
         Label: []

Use a function handle to specify an internal heat source that depends on time.

Create a thermal model for transient analysis and include the geometry. The geometry is a rectangular strip.

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

Specify the thermal properties of the rod.

thermalProperties(thermalmodel,"ThermalConductivity",40,...
                               "MassDensity",7800,...
                               "SpecificHeat",500);

Specify the boundary conditions and initial temperature.

thermalBC(thermalmodel,"Edge",2,"Temperature",100);
thermalBC(thermalmodel,"Edge",3,...
                       "ConvectionCoefficient",50,...
                       "AmbientTemperature",100);
thermalIC(thermalmodel,0);

Specify that the entire geometry generates heat at the rate 20000t during the first 500 seconds, and then the heat source turns off. For details, see Time-Dependent Heat Source Function.

internalHeatSource(thermalmodel,@heatSource);

Generate the mesh, solve the model using the solution times from 0 to 50000 seconds, and plot the results.

generateMesh(thermalmodel);

tfinal = 50000;
tlist = 0:100:tfinal;
result = solve(thermalmodel,tlist);
T = result.Temperature;

figure 
subplot(2,1,1)
pdeplot(thermalmodel,"XYData",T(:,6),"Contour","on")
axis equal
title(sprintf("Temperature at %g s",tlist(6)))
subplot(2,1,2)
pdeplot(thermalmodel,"XYData",T(:,end),"Contour","on")
axis equal
title(sprintf("Temperature at %g s",tfinal))

Figure contains 2 axes objects. Axes object 1 with title Temperature at 500 s contains 12 objects of type patch, line. Axes object 2 with title Temperature at 50000 s contains 12 objects of type patch, line.

Always ensure that your function returns a matrix of NaN of the correct size when state.time is NaN. The solver properly recognizes a time-dependent problem by passing NaN state values and looking for returned NaN values. Without this condition, the solver might fail or return incorrect results.

internalHeatSource(thermalmodel,@heatSourceInvalid);

result = solve(thermalmodel,tlist);
T = result.Temperature;

figure 
subplot(2,1,1)
pdeplot(thermalmodel,"XYData",T(:,6),"Contour","on")
axis equal
title(sprintf("Temperature at %g s",tlist(6)))
subplot(2,1,2)
pdeplot(thermalmodel,"XYData",T(:,end),"Contour","on")
axis equal
title(sprintf("Temperature at %g s",tfinal))

Figure contains 2 axes objects. Axes object 1 with title Temperature at 500 s contains 12 objects of type patch, line. Axes object 2 with title Temperature at 50000 s contains 12 objects of type patch, line.

Time-Dependent Heat Source Function

function Q = heatSource(location,state)
  Q = zeros(1,numel(location.x));
if(isnan(state.time))
% Returning a NaN when time=NaN tells
% the solver that the heat source is a function of time.
  Q(1,:) = NaN;
  return
end
if state.time < 500
  Q(1,:) = 20000*state.time;
end
end

function Q = heatSourceInvalid(location,state) % No checks for NaN
  Q = zeros(1,numel(location.x));
if state.time < 500
  Q(1,:) = 20000*state.time;
end
end

Input Arguments

collapse all

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")

Geometric region type, specified as "Face" for a 2-D model or "Cell" for a 3-D model.

Example: internalHeatSource(thermalmodel,25,"Cell",1)

Data Types: char | string

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

Example: internalHeatSource(thermalmodel,25,"Cell",1:3)

Data Types: double

Heat source value, specified as a number or a function handle. Use a function handle to specify the internal heat source that depends on space, time, or temperature. For details, see More About.

Example: internalHeatSource(thermalmodel,25)

Data Types: double | function_handle

Label for the internal heat source, specified as a character vector or a string.

Data Types: char | string

Output Arguments

collapse all

Handle to heat source, returned as a HeatSourceAssignment object. See HeatSourceAssignment Properties.

heatSourceValue associates the heat source value with the geometric region.

More About

collapse all

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.nxx-component of the normal vector at the evaluation point or points

    • location.nyy-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

expand all