## Create time dependent internal heat source for heat transfer problem

### Anthony Carreon (view profile)

on 10 Oct 2019
Latest activity Answered by Alan Weiss

on 10 Oct 2019

### Alan Weiss (view profile)

Hello,
I am writing a heat source function that is supposed to be time dependent, but it is not produccing the right results. I wrote a internal heat source function "HeatSourceFunc" that will be used as follows:
internalHeatSource(model,@HeatSourceFunc);
I have written two different heat source functions that basically do the same thing, except that the first case is not time-dependent, and the second case is time-dependent and is supposed to start at time t = 5 seconds.
Here is case 1 (not time dependent):
function Q = HeatSourceFunc(location,~) % case 1
xx = location.x;
yy = location.y;
Q = zeros(size(xx));
idx = (xx-0.006).^2 + (yy-0.004).^2 <= 0.002^2; % circular heat source
Q(idx) = 50;
end
Here is case 2 (time dependent):
function Q = HeatSourceFunc(location,state) % case 2
xx = location.x;
yy = location.y;
tt = state.time;
Q = zeros(size(xx));
if tt < 5 % no heat sources before t = 5 seconds
return;
else % circular heat source starting at t = 5 seconds
idx = (xx-0.006).^2 + (yy-0.004).^2 <= 0.002^2;
Q(idx) = 20 - tt;
end
end
I ran the simulation from t = 0 seconds to t = 100 seconds as follows:
time = 0:100; % times at which to sample solution
sol = solve(model,time); % solve problem
Then I obtained the following graphs. Why am I not getting a similar picture in case 2 as in case 1? 100 seconds is plenty of time for a temperature change to occur. Any help would be appreciated, thank you.  ### Alan Weiss (view profile)

on 10 Oct 2019
The solution (if I am correct) is to solve two problems. Solve one for times . Then take the solution at time 5 as the initial condition for the problem for . This workaround should enable you to obtain correct answers.