Computing temperature of a fluid inside a cylinder using PDEPE
Show older comments
I am trying to solve the following problem:
- there is a fluid inside a cylinder with an initial temperature;
- this fluid starts cooling down while cylinder is cooled by the water surrounding it;
- my goal is to plot "time vs. fluid temperature".
I started modeling the problem using "pdepe" funcion. What I did first was trying to model just the region between R0=4in and R1=6in and trying to apply the boundary conditions to the inner and outer faces. I had no problems with the outer face, because water outside cylinder has a fixed temperature and convection coefficient is also a constant.
However, I didn't manage to model the inner boundary condition. For the purposes of what I need, all the fluid inside the cylinder can be consider to have the same temperature at a given time. Therefore, it can be considered that
, where T is the the fluid temperature inside the cylinder and
is the temperature of the inner wall of the cylinder (it is a funcion of the time and will be computed by PDEPE).
I did not manage to write this BC as it is required by PDEPE function,
.
Anyone can help?
3 Comments
Bill Greene
on 11 Aug 2022
I find this question very confusing. My impression is that you have some fluid in a cylinder, from r=0 up to r=R0, that is surrounded by a solid wall from r=R0 to r=R1. This solid wall is surrounded by a large volume of water that can be assumed to have a fixed temperature. But it appears you are assuming that the fluid inside ( r=0 up to r=R0) is being cooled by the containing solid cylinder but for some reason still has a uniform temperature throughout? How can this be?
Torsten
on 11 Aug 2022
If R0 is small and maybe the fluid inside is stirred, temperature assimilates quite fast.
But by the way: isn't your pdepe code capable to solve this problem (one coupled ODE at the left boundary point) ?
Bill Greene
on 11 Aug 2022
Yes,I was thinking of trying pde1dm on this problem (using one ODE as you suggest) if I could understand the physics. ;-)
Accepted Answer
More Answers (3)
Torsten
on 10 Aug 2022
Therefore, it can be considered that , Tdot = -2*h*(T-Tw)/(rho*cp*R0) where T is the the fluid temperature inside the cylinder and Tw is the temperature of the inner wall of the cylinder (it is a funcion of the time and will be computed by PDEPE).
And how do you get T ? Or is this your question ?
If you have T available, the equation for pdepe at r = r0 would be
lambda*dTw/dr = alpha*(Tw-T)
This can be set in bcfun as
pl = -alpha*(ul-T);
ql = 1.0;
if you have set
f = lambda*dudx
in pdefun.
9 Comments
Rodrigo Resende
on 10 Aug 2022
You could define small time steps in tspan for pdepe and call an OutputFcn function in which you update T according to the wall temperature Tw from pdepe (e.g. with simple Euler forward). Then for the next time step, you could use this T to define the boundary condition at the inner wall for pdepe.
But I think a simple discretization of the cylindrical wall and a solution of the usual
rho_w*cp_w*dT_w/dt = 1/r d/dr(r*lambda_w*dT_w/dr)
using the method-of-lines (without pdepe) should be more flexible and simple.
And here it is easy to include an additional ODE for T.
Rodrigo Resende
on 10 Aug 2022
Rodrigo Resende
on 10 Aug 2022
Edited: Rodrigo Resende
on 10 Aug 2022
Torsten
on 10 Aug 2022
I also have no experience with OutputFcn. The only thing I can answer is
If I want to compute T, then I would need to do: T_n+1=T_n + (dT/dt)_n x dt. But how can I get dt and T_n
dt is given by your prescribed array "tspan" for the times when the solution should be provided. Defining
tspan = tstart:dt:tend
in the program from which you call "pdepe", you will have to use this value for dt in OutputFcn, too. Also in OutputFcn, you could store T(n) as a persistent variable and use it in the next call to compute T(n+1) from your above formula.
Rodrigo Resende
on 11 Aug 2022
Edited: Rodrigo Resende
on 11 Aug 2022
If it works, ok. But keep in mind that "heatbc" - in contrast to "OutputFcn" - is not (only) called at times where the solutions ul and ur are already established, but also for "test" times and values for ul and ur in between. Despite your if-statement (if dt> 0), I have my doubts about the reliability of the results.
Further keep in mind that usually in pdepe's problem function,
f = k*DuDr
is set.
If this is the case also in your code, don't multiply ql and qr again with k as you do it in "heatbc". Otherwise, your boundary condition will look something like
k^2*du/dr = ...
Rodrigo Resende
on 11 Aug 2022
I think you can get a reliable solution if you call "pdepe" in a loop from t0 to t1, from t1 to t2 and so on. During the time intervals t_i <= t <= t_i+1, you can keep T constant at the value you received with your Euler forward at time t_i.
Or try Bill Greene's extended version of pdepe (pde1dm):
I think the code can handle additional ODEs.
Note that the additional x under the operator
1/x * d/dx (x*du/dx)
is not specified when you define the boundary condition for pdepe.
Thus your pl,ql,pr,qr in "heatbc" are wrong.
For comparison:
R0 = .1;
R1 = .15; % radii in meters
t0 = 0;
t1 = 1e4; % time limits
wallConductivity = 150;
wallDensity = 2800;
wallSpecHeat = 800;
rhoWater = 997;
cpWater = 4182;
hWater = 100; % convection coeff between tank and containing water
hTank = 200; % convection coeff between tank and inner reservoir
tempTank = 50; % initial temperature of fluid in the inner reservoir
tempWater = 20; % temperature of containing water
nr = 10;
r = linspace(R0,R1,nr); %spatial discretization
r = r.';
rm = 0.5*(r(1:nr-1)+r(2:nr)); %cell centers
nt = 50;
t = linspace(t0,t1,nt); %output times
initialtempWall = tempWater; %initial temperatures
initialtempTank = tempTank;
y0 = [initialtempWall*ones(nr,1);initialtempTank];
[T,Y] = ode15s(@(t,y)odefun(t,y,nr,r,rm,wallConductivity,wallDensity,wallSpecHeat,...
rhoWater,cpWater,hWater,hTank,tempWater),t,y0); % solver call
%Plot temperature profile in the wall for certain output times
figure(1)
plot(r,[Y(1,1:nr);Y(2,1:nr);Y(5,1:nr);Y(10,1:nr);Y(11,1:nr)])
%Plot temperature profiles in certain wall points over time
figure(2)
plot(t,[Y(:,1),Y(:,5),Y(:,10)])
%Plot temperature of water in inner cylinder
figure(3)
plot(t,Y(:,nr+1))
function dTemp = odefun(t,y,nr,r,rm,wallConductivity,wallDensity,wallSpecHeat,...
rhoWater,cpWater,hWater,hTank,tempWater)
tempWall = y(1:nr);
tempTank = y(nr+1);
dtempWalldt = zeros(nr,1);
% Wall Temperatures
% left boundary
dtempWalldt(1) = 1/r(1)*(rm(1)*wallConductivity*(tempWall(2)-tempWall(1))/(r(2)-r(1))-...
r(1)*hTank*(tempWall(1)-tempTank))/(rm(1)-r(1))/...
(wallDensity*wallSpecHeat);
% inner points
dtempWalldt(2:nr-1) = 1./r(2:nr-1).*(rm(2:nr-1).*wallConductivity.*(tempWall(3:nr)-tempWall(2:nr-1))./(r(3:nr)-r(2:nr-1)) -...
rm(1:nr-2).*wallConductivity.*(tempWall(2:nr-1)-tempWall(1:nr-2))./(r(2:nr-1)-r(1:nr-2)))./(rm(2:nr-1)-rm(1:nr-2))./...
(wallDensity*wallSpecHeat);
% right boundary
dtempWalldt(nr) = 1/r(nr)*(r(nr)*hWater*(tempWater-tempWall(nr))-rm(nr-1)*wallConductivity*...
(tempWall(nr)-tempWall(nr-1))/(r(nr)-r(nr-1)))/(r(nr)-rm(nr-1))/...
(wallDensity*wallSpecHeat);
% Tank Temperature
dtempTankdt = 2/r(1) * hTank* (tempWall(1) - tempTank)/(rhoWater*cpWater);
% Return temporal derivatives
dTemp = [dtempWalldt;dtempTankdt];
end
2 Comments
Rodrigo Resende
on 15 Aug 2022
Edited: Rodrigo Resende
on 15 Aug 2022
0 votes
1 Comment
Bill Greene
on 15 Aug 2022
Glad to hear that pde1dm worked for you!
>The only change I was in doubt was if I could replace "jac" by "jac(1)".
Apparently the semantics of the ./ operator were enhanced sometime after the 2010b version.
The change you made is OK as long as all the elements in your mesh (the entries in the xmesh array)
are uniformly spaced. But, for a non-uniform mesh, it will fail because the values
in the jac array vary.
A change that should work in general, possibly at the cost of being slower, is to
add this line:
dNdx=zeros(nen, length(jac));
after this line:
jac=(x(i2)-x(i1))/2;
and replace
dNdx = dN(:,i)./jac;
with
for j=1:nen
dNdx(j,:) = dN(j,i)./jac;
end
Categories
Find more on Structural Mechanics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

