Defining mass matrix for solving transport equation
Show older comments
I want to solve the following 1-D pde which is discretized in spacial direction to solve using ode15s.
Dc/Dt = D*D^c/Dx^2 - v*Dc/Dx.
With initial condition,
c(x,0) = Co
Boundary conditions ,
Dirichlet boundary condition at left boundary,
c(0,t) = cl;
Neumann boundary condition at right boundary,
dc/dx = 0;
I'm not very clear about defining the mass matrix for the input options in the call to ode15s
options = odeset('Mass',M,'RelTol',1e-4,'AbsTol',[1e-6 1e-10 1e-6]);
[t,y] = ode15s(@fun,tspan,y0,options);
I'm trying to solve the above system as a index-1 DAE. The first row and second row of the mass matrix will contain one's in the diagonal entries.
I am not sure how the left boundary condition has to be specified in the mass matrix.
Could someone explain?
13 Comments
Torsten
on 7 Jan 2019
Why don't you use "pdepe" ?
Deepa Maheshvare
on 7 Jan 2019
Torsten
on 7 Jan 2019
For your PDE from above, the mass matrix will be the identity matrix and your system will be a pure system of ODEs. Why do you expect something different ?
Deepa Maheshvare
on 7 Jan 2019
At the right boundary (x=x_n)
D^2c/dx^2 ~
(dc_n/dx - dc_(n-1/2)/dx) /(x_n-x_(n-1/2)) ~
(dc_n/dx - (c_n-c_(n-1))/(x_n-x_(n-1)))/(x_n-x_(n-1/2))
Thus with your boundary condition dc_n/dx = 0 you get the ODE
dc_n/dt = D*(- (c_n-c_(n-1))/(x_n-x_(n-1)))/(x_n-x_(n-1/2))
with x_(n-1/2) = (x_n+x_(n-1))/2
Deepa Maheshvare
on 7 Jan 2019
Edited: Deepa Maheshvare
on 8 Jan 2019
Deepa Maheshvare
on 8 Jan 2019
Torsten
on 8 Jan 2019
As I already wrote: A mass matrix does not need to be defined. At the left boundary, you can solve dc(1)/dt = 0 since c=cI for all times. At the right boundary, I provided an ODE for dc(n)/dt.
Before you care about providing a Jacobian pattern (which might be helpful to accelarate computation), you should try to make your code work in dense mode.
Best wishes
Torsten.
Deepa Maheshvare
on 8 Jan 2019
Torsten
on 8 Jan 2019
Sorry, I have not yet worked with the option of "Jacobian Pattern". Thus I had to start at the same knowledge level as you do.
Deepa Maheshvare
on 8 Jan 2019
Torsten
on 8 Jan 2019
function S = Jacpat(N)
% Define the sparsity structure of the Jacobian by indicating which
% variables appear in which equations. This is done by inspection of
% the function 'f' above for evaluating the equations.
S = sparse(N,N);
for i = 2:(N-1)
S(i,i-1) = 1; % c(i-1)
S(i,i) = 1; % c(i)
S(i,i+1) = 1; % c(i+1)
end
S(N,N-1) = 1; % c(N-1)
S(N,N) = 1; % c(N)
Deepa Maheshvare
on 23 Sep 2019
Answers (0)
Categories
Find more on Programming 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!