Question

I want to apply heat transfer ( heat conduction and convection) for a hemisphere. It is a transient homogeneous heat transfer in spherical coordinates. There is no heat generation. Boundary conditions of hemisphere is in the beginning at Tinitial= 20 degree room temperature. External-enviromental temperature is -30 degree. You can imagine that hemisphere is a solid material. Also, it is a non-linear model, because thermal conductivity is changing after material is frozen, and this going to change the temperature profile.

I want to find the temperature profile of this solid during a certain time until center temperature reach to -30degree.

In this case, Temperature depends on 3 parameters : T(r,theta,t). radius, angle, and time.

1/α(∂T(r,θ,t))/∂t =1/r^2*∂/∂r(r^2(∂T(r,θ,t))/∂r)+ 1/(r^2*sinθ )∂/∂θ(sinθ(∂T(r,θ,t))/∂θ)

I applied finite difference method using matlab, however program does not calculate anything for inner nodes of the hemisphere, and just giving me initial temperatures values (Which is Told in here) . You can see some scripts which i used for inner nodes.

% initial conditions
Tair    =   -30.0;               % Temperature of air
Tin     =    21; 

% setting initial values for grid
for i=1:(nodes)
    for j=1:(nodes)
Told(i,j)     =   Tin;
Tnew(i,j)     =   Tin;
frozen(i)   =   0;                      
latent(i)   =   Qs*mass(i)*Water/dt;    
k(i)        =   0.5;                    
cp(i)       =   cw;                     
W(i)        =   Water;                  
l(i)        =   0;                      
S(i)        =   1-Water;                
     end
end


%Simulation conditions
J       =    9;              % No. of space steps   
nodes   =   J+1;             % Number of nodes along radius or theta direction
dt      =0.1;


t       =   0;               % time index on start
tmax    =   7000;            % Time simmulation is supposed to run


R       =  d/2;

dr      =  (d/2)/J;         %  space steps in r direction

 y   =        pi/2;        % (theta) for hemisphere
dy      =  (pi/2)/J;       % space steps in Theta direction

    % Top surface condition for hemisphere
      i=nodes; 
        for j=1:1:(nodes-1) 

       Qcd_ot(i,j) = ((k(i)+ k(i-1))/2)*A(i-1)*(( Told(i,j)-Told(i-1,j))/(dr)); % heat conduction out of nod 

        Qcv(i,j) = h*(Tair-Told(i,j))*A(i); % heat transfer through convectioin on surface 

        Tnew(i,j) = ((Qcv(i,j)-Qcd_ot(i,j))/(mass(i)*cp(i))/2)*dt + Told(i,j); 
          end             %end of for loop 

  % Temperature profile for inner nodes

  for i=2:1:(nodes-1)     
    for j=2:1:(nodes-1)  

Qcd_in(i,j)=   ((k(i)+ k(i+1))/2)*A(i) *((2/R)*(( Told(i+1,j)-Told(i,j))/(2*dr)) + ((Told(i+1,j)-2*Told(i,j)+Told(i-1,j))/(dr^2)) + ((cot(y)/(R^2))*((Told(i,j+1)-Told(i,j))/(2*dy))) + (1/(R^2))*(Told(i,j+1)-2*Told(i,j)+ Told(i,j-1))/(dy^2));
Qcd_out(i,j)=  ((k(i)+ k(i-1))/2)*A(i-1)*((2/R)*(( Told(i,j)-Told(i-1,j))/(2*dr)) +((Told(i+1,j)-2*Told(i,j)+Told(i-1,j))/(dr^2)) + ((cot(y)/(R^2))*((Told(i,j)-Told(i,j-1))/(2*dy))) + (1/(R^2))*(Told(i,j+1)-2*Told(i,j)+ Told(i,j-1))/(dy^2));

Tnew(i,j)     =   (Qcd_in(i,j)-Qcd_out(i,j))/(mass(i)*cp(i)))*dt + Told(i,j);
    end           
end               

   %bottom of the hemisphere solid
  Tnew(:,nodes)=-30;



 Told=Tnew;
 t=t+dt;

EDIT *Thanks, now the scripts are working and calculating. And i can see temperature profile for model system.

However, i want to plot in a 2D or 3D plot for this hemisphere temperature profile. Also if it is possible i would like to run animation for temperature change during certain time. The codes what i am using for simulation and to write a file is

     t=0;

    tmax=7000;
    ...................
    .....................
    ss=0;   % index for printouts

     %start simulation
     while t<tmax
   ss=ss+1;
  .............
  .................
   ................
    if ss==2000
    dlmwrite('d:\Results_for_model.txt',Tnew,'-append');
    ss=0;
    end


    end   % end of while loop

Do you have any suggestion for it ? Because in text file, for Tnew(i,j) values, after every 10 rows, model calculates for next dt value. Therefore, results data looks like a mess, after every 10 rows, it gives for next time values results.

Is there any way to coordinate to write this results according to specific rows and columns ( because otherwise huge amount of data are needed to be organized again and again) ?

and i want to plot in 3d plot for this temperature profile which is hemisphere in this case, i have Tnew(r,theta,t), but i am confused to how to represent this temperature profile to show in a hemisphere graph. I would like to hear your suggestions about it. Thanks in advance !!

Was it helpful?

Solution

To be precise, the proper syntax as defined by MATLAB for the for loop construct is

for index = values
    program statements
    ...
end

where values has one of the following forms:

initval:endval

initval:step:endval

valArray

your code is parsed to initval:endval = 9:2, which means the loop runs 0 times, resulting in no calculations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top