Empirical source terms with PDEPE

3 views (last 30 days)
Matthew Hunt
Matthew Hunt on 7 May 2020
Commented: Bjorn Gustavsson on 11 May 2020
Suppose I'm solving an equation:
With initial condition and boundary conditions and
Now I want to import the source term, as data, so I will have a Nx2 array [t Q] with data. Can I just treat that as I would a constant?
The code I have is:
function sol=temp_pde(t,R,X,source)
m=1; %Sets the geometry to cylindrical
global theta kappa h Q;
theta=X(1); kappa=X(2); h=X(3);
r=linspace(0,R,800);
t=source(:,1);
Q=source(:,2);
sol=pdepe(m,pdefun,icfun,bcfun,r,t);
end
function [c,f,s] = pdefun(r,t,u,dudx)
global Q theta kappa;
c = theta;
f = kappa*dudx;
s = Q;
end
function u0 = icfun(r)
u0 = 0;
end
function [pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t)
global h kappa;
pl = 0;
ql = 1;
pr = h*ur;
qr = kappa;
end
Where I obtain my t parameter from my data in source. Would this work?
  2 Comments
Matthew Hunt
Matthew Hunt on 7 May 2020
\dot{Q} is purely a function of time, so is homogeneous.

Sign in to comment.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 7 May 2020
To the best of my understanding you should be able to define your pde-function something like this:
function [c,f,s] = pde_interpS(x,t,u,dudx,tQ,Q,theta,kappa)
c = theta;
f = kappa*dudx;
s = interp1(tQ,Q,t,'pchip');
end
Then you can convert that function to a function of t, x, u and dudx with the standard @()-trick. My preference is to avoid globals as much as possible, but you can use that too.
HTH
  6 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 11 May 2020
Seems like your pde-function that should return your c, f and s either doesn't return all three of those variables, or some of them are not set to column vectors - either one or more of them are empty or of the wrong size - perhaps one of them becomes a row-vector. If you set a debug-stop in the pde-function you can check the sizes of the outputs there.
HTH

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!