0
$\begingroup$

This is a follow up to my previous post here

I'm solving the following 1D transport equation .

$$\frac{\partial C}{\partial t} = D\frac{\partial ^2 C}{\partial x^2}-v\frac{\partial C}{\partial x}$$

At the inlet (left boundary), Dirichlet boundary condition is applied $C(1) = C_L$ . (1 is the inlet node number)

At the outlet (right boundary), diffusive flux is ignored. $-D \frac{dC}{dx} = 0$

I'm comparing the absolute errors computed from the following implementations,

  1. Discretizing the convection term using backward difference and diffusion using central difference approximation.

  2. Discretizing the convection term using central difference and diffusion using central difference approximation.

After discretization in the spatial direction, the pde translates to a set of odes. The odes are solved using a stiff equation solver.

The results from the above 2 implementations are compared against the solution obtained from MATLAB's pdepe solver and absolute errors are computed.

The absolute error for the first implementation is illustrated in the following image (using a spatial discretization step of 0.25). The complete code can be found in the solution posted here

enter image description here The absolute error for the second implementation is of the order 10^-13.

From what I understand, the truncation error of the backward difference is $O( \Delta x)$ and that of centered difference is $O(\Delta x^2)$ from Taylor series approximations of the first derivative. The errors obtained from the numerical scheme is of the order 0.04 for backward + central difference and 1e-13 for central alone. I am not able to clearly understand what leads to this drastic difference and how to check the errors computed to the truncation orders from the Taylor series.

I'd like to request for explanations on why this drastic difference occurs in absolute errors.

$\endgroup$
  • 1
    $\begingroup$ You're plotting what appear to be the error as a function of time, when the level of error is dependent on the mesh size. Also, how are you measuring the absolute error? $\endgroup$ – EMP Feb 11 at 17:38
  • $\begingroup$ @EMP Yes, I'm plotting error as a function of time. The errors are compared for the two implementations using the same mesh size. This is how the absolute error is computed : solutionDifference=abs(sol-C), where C contains the transient values of C obtained at every node from my implementation of backward + central/ central + central difference scheme ; sol contains the results from MATLAB's pdepe solver. $\endgroup$ – Natasha Feb 12 at 3:15
2
$\begingroup$

As I wrote in my comment, you have plotted your errors as a function of time, and asked how that relates to the spatial error of the different finite difference methods you've used, that is not the proper way to measure this. The proper way would be comparing your two methods error to the closed form result for all times and seeing how refining the mesh effects the error.

This brings me to my second point, your error measure is not an error measure; you are in factmeasuring how your implementation compares to pdepe. This means that if you write the same solver as pdepe your error criterion would return a machine zero value, even though that would clearly not be the case. It looks to me that you achieved the goal of writing a central difference scheme (which I assume is what pdepe uses) and as a result got a criterion that returns machine zero error. The other solver you wrote is different from pdepe, so your error is non zero. You would be better served by comparing to a closed form known result as I stated above, then both your schemes would return a nontrivial error estimate. You should ask yourself what are you in fact measuring when you calculate an error estimate.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks a lot for the response. Sure, I understand the error has to be compared -- numerical scheme vs. analytical solution at different spatial positions. I'll definitely do this. Here, I am trying to understand why results from the backward difference scheme is much different from the central difference. $\endgroup$ – Natasha Feb 12 at 3:59
  • 2
    $\begingroup$ They are different because your central difference is the same as the pdepe solver, I assume. So while they won't be that different from the analytic solution, but when compared to pdepe, one is the same as it and the other isn't. Which is what I wrote in my answer. $\endgroup$ – EMP Feb 12 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.