Clear Filters
Clear Filters

I need to know how to put the s variable of pdefun (from pdepe solver) as a function of x and time

4 views (last 30 days)
Hi, I need help to solve a proble I'm in for a long ago. The thing is that I can't find any doc explaining how to set the variables [c,f,s] of pdefun (in particular the 's') as a function of the point of the 'xmesh'. It is to solve the heat transfer and difussion equation that is rho*cp*du/dt-k*d/dx(du/dx)=g.
from mathworks blogs and answers, I know that c=rho*cp (which is constant with time and x) f=k (also constant), but g is power generation, and that is not constant with time neither with x, the power is generated the first time values and just in a given set of points of xmesh.
Here I paste a part of the code where I state the pdefun:
function[c,f,s] = pdef(x, u, t, DuDx)
c = rho*cp;
f = k*DuDx;
i=1;
while(i<=length(x))
if(x(i)<=percent*radi)
s = (1/(h*pi*radi)^2)).*interp1(t40,Pot40,t,'linear','extrap');
else
s = 0;
end
i=i+1;
end
end
Please, if anyone could tell me if this is well developed. The s variable I mean.
  8 Comments
JOAN PERE PONSETI
JOAN PERE PONSETI on 11 Jan 2017
Hi again, I implemented this code to see if now it works but it gives me this error message back.
Not enough input arguments.
Error in CLDissipation1D/pdef (line 375) if(x==xmesh(1))
Error in pdepe (line 246) [c,f,s] = feval(pde,xi(1),t(1),U,Ux,varargin{:});
Error in CLDissipation1D (line 340) sol = pdepe(m, @pdef, @pdeic, @pdebc, xmesh, t40);
function[c,f,s] = pdef(x,t,DuDx,S,xmesh,tspan)
c=rho*cp;
f=k*DuDx;
% find out the volume we need the previous point too
i=1;
encontrado=0;
while(encontrado==0)
if(x==xmesh(1))
vol=inf;
encontrado=1;
elseif(x==xmesh(i))
vol=(pi*(x^2-xmesh(i-1)^2)*h);
encontrado=1;
end
i=i+1;
end
% repeat the same loop to find the power at time t
i=1;
encontrado=0;
while(encontrado==0)
if(t==tspan(i))
pot=Pot40(i);
end
i=i+1;
end
% Finally we define the variable s as the ratio of power/volum
s=pot/(vol*pin);
% ========================================================================= % defines the Initial Conditions
end
Thanks a lot again!

Sign in to comment.

Accepted Answer

Torsten
Torsten on 11 Jan 2017
1. pdepe calls pdef for arbitrary times, not only those specified in tspan.
2. sol = pdepe(m, @(x,t,DuDx)pdef(x,t,DuDx,S,xmesh,tspan), @pdeic, @pdebc);
3. Comparisons for equality like if x==xmesh(1) probably won't work because of rounding errors.
Best wishes
Torsten.
  9 Comments
JOAN PERE PONSETI
JOAN PERE PONSETI on 24 Feb 2017
Another thing, when I write the next code % Specify Coefficients
f = @(region,state) interp1(t40,Pot40,state.time,'linear','extrap');
specifyCoefficients(pdem,'m',0,'d',rho*cp,'c',k,'a',0,'f', f);
and I set a breakpoint at f, it always says that state structure is 0 at all its elements but it doesn't return any error until the fifth or sixth step... don't know why...
thanks!
JClarcq
JClarcq on 19 Feb 2018
Hi Joan,
I have the same problem than you where my heatsource is a term temperature dependent via an interp1 of a material properties.
Have you been able to solve this inputs argument issue? Thanks,

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!