Solving a diffusion-reaction equation using method of lines
Show older comments
Hi all, I am trying to solve a diffusion-reaction equation (under cylindrical co-ordinate) using method of lines (MOL). The partial differential equation, initial and boundary conditions, and the corresponding derivations can be seen in the attachment. The corresponding code has also been uploaded. I also simulated the PDE using the pde solver in Matlab, and found that my MOL code cannot obtain the right results. Moreover, what weird is that the results of MOL depend on the number of spatial grids (the variable n in my code). I have checked my code many times and did not find any errors. Can anyone help me with this? Thanks in advance.
19 Comments
J. Alex Lee
on 9 Oct 2020
i don't think your BC is implemented correctly...wouldn't you just want [1,0,0...] in your top row of A so that the equation just forces C1=BC? And same for last row?
Dadi Bi
on 9 Oct 2020
J. Alex Lee
on 9 Oct 2020
so you actually have n+2 nodes, and are only solving the "middle" n of them. I guess this makes more sense in your case for BC at left because you have an asserted time dependent function.
But then still confused why build your BC into the equation for the 1-th node? it should naturally be taken care of without "asserting" any BCs on your internal node FDEs, i.e., not sure you need the b vector at all?
Dadi Bi
on 9 Oct 2020
J. Alex Lee
on 11 Oct 2020
Your explanation in the comment is clear, now that I understand the BCs are flux conditions, based on your equations it is
The method of not solving for the end nodes seems clever, and your equations do look ok to me. The only comment I would make is that your flux condition is asserted using a 2 point FDE (first order accurate) whereas your other FDE's are 2nd order accurate. This might result in subtly different answers. How are you generating your "reference" solution (pdepe?) and in what way is your answer different from it?
By teh way, you can also re-institute the much better way of constructing A in the example
B = [ (s - s./(2*(1:n)')) , (-2*s-kd)*ones(n,1) , ( s + s./(2*(-1:n-2)')) ];
A = spdiags(B,-1:1,n,n);
Dadi Bi
on 11 Oct 2020
J. Alex Lee
on 11 Oct 2020
In your pdepe example, you are asserting your flux condition at some finite value of r rather than at r=0. If you change your boundary location to r=0, the pdepe solver seems to fail. If you change your boundary to match that of your original formulation (for larger n, you get smaller r0), you'd see a dependence on the boundary location similarly to what you see.
In hindsight, the BC at r=0 violates radial symmetry, which seems to be problematic.
Dadi Bi
on 12 Oct 2020
J. Alex Lee
on 13 Oct 2020
In the documentation it is stated that for pdepe that when m=1 then any boundary condition at r=0 is ignored and the symmetry condition is assumed.
The nuclear waste has a symmetry condition at r=0, so it should be ok.
Again, when you say results are very different, are you remembering to compare only the internal nodes of the pdepe solution? Remember because you have very high gradients near r=0, that extra node is going to shoot up to a high value.
Dadi Bi
on 13 Oct 2020
J. Alex Lee
on 13 Oct 2020
Edited: J. Alex Lee
on 13 Oct 2020
where is your code for generating these plots? You should be comparing
sol = pdepe()
u = sol(:,:,1);
figure;
mesh (t,x(2:end-1),u(:,2:end-1)')
to within a transpose of whatever is in u.
That's assuming you can control the number of nodes in pdepe, and you should compare n=101 for pdepe to n=99 for your MOL, and n=301 for pdepe to n=299 for your MOL
Dadi Bi
on 13 Oct 2020
J. Alex Lee
on 13 Oct 2020
Are you sure your xmesh is consistent across your solution methods? Your MOL needs to be define from x1+dr to a-dr, and the term in your denominator (2*i) needs to correspond to the elements in xmesh correctly. At first glance, i think you need to add an offset of 0.05 (or whatever x1 is) in that denominator.
Also, when setting x1 = 0.05 in a MOL, i'm seeing a dramatic difference between using first order vs second order difference equations at the boundaries. Likely the pdepe is internally using consistent order of discretization, so you'd want to use second order difference eqs at the ends if you want to compare apples to apples.
Dadi Bi
on 20 Oct 2020
J. Alex Lee
on 21 Oct 2020
Edited: J. Alex Lee
on 21 Oct 2020
the LHS of your last equation is the finite difference equation estimating the left-handed first order accurate first derivative. You can replace that with any FDE you want, in particular for a left-handed second order accurate first derivative estimate:
But I still have doubts about the non-zero flux at the center-line; maybe pdepe SHOULD fail when you try to assert anything but a symmetry condition there. If you are modeling a physical system, it seems reasonable that any type of line-source/sink is anyway an idealization of a "thin embedded wire"-like source so that your strategy of nudging the left boundary a bit is actually the more sensible one.
For your mesh dependence study, what are you comparing? I would compare the value of
at some specific time. If you are comparing
values, are you compensating for your mesh size change by changing the location of your left boundary to
?
?
Dadi Bi
on 22 Oct 2020
J. Alex Lee
on 23 Oct 2020
once you change r_0, you are solving different problems, so of course you expect different answers.
still not clear if you doing the right comparison...if you are assessing mesh dependence of MOL, then you must remember that every time you change your mesh, your value of C1 (which is largest) is NOT at r_0, but at r_0+dr, and dr is always changing.
Dadi Bi
on 24 Oct 2020
J. Alex Lee
on 24 Oct 2020
If you are comparing C1 values to C1 values (the first value in your mesh), instead of C0 values to C0 values, your answers WILL depend on your mesh because of the way you are defining the mesh.
Answers (0)
Categories
Find more on Eigenvalue Problems 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!

































