The Stack Overflow podcast is back! Listen to an interview with our new CEO.
2 additions according to remarks
source | link

If you consider only the pure advective part and let, say, $v>0$, then you can obtain "no flux condition" at the right point only by setting (redefining) $v=0$ there. Of course, the solution can then develop a "boundary layer" there and it can become discontinuous at the right point as the solution will preserve there the value given by initial condition, i.e. $u_{jmax}^{n+1} = u^0_{jmax}$.

A natural boundary condition for constant speed $v>0$ is that you let the solution "flow out" through the right point of interval that can be viewed as outflow boundary. It can be obtained by applying your leapfrog method for $u_{jmax}^{n+1}$ with the auxiliary value $u_{jmax+1}^n= u_{jmax}^n$ (a constant extrapolation) or $u_{jmax+1}^n= 2 u_{jmax}^n - u_{jmax-1}^n$ (a linear extrapolation). One can see such treatment as "do nothing boundary conditions" that is appropriate herefor outflow boundary and pure advection. For instanceIt is like you are solving the pure advection (the differential equation) also at the right point.

Just a remark - if you use a proper upwind method instead of leapfrog method, you even need no auxiliary values outside of your domain to compute $u_{jmax}^{n+1}$.

For the inflow boundary, i.e. the left point ofin the case $v>0$, you must prescribe the values $u_0^{n+1}$ directly by "Dirichlet boundary conditions" and not solving the differential equation.

For the case of advection-diffusion equation you can in theory define the no-flux boundary conditions as you write with $D \neq 0$, but it means for $v>0$ that you prescribe an "inward diffusion", consequently a corresponding gradient, that will cancel the advection flux, so the total flux will be zero. Such situation is hard to find in practice. More typical is to prescribe something only for the diffusion flux and to use the previous ``do nothing'' approach (or an extrapolation) for the advective flux.

If you consider only the pure advective part and let, say, $v>0$, then you can obtain "no flux condition" at the right point only by setting (redefining) $v=0$ there. Of course, the solution can then develop a "boundary layer" there.

A natural boundary condition for constant speed $v>0$ is that you let the solution "flow out" through the right point of interval that can be viewed as outflow boundary. It can be obtained by applying your leapfrog method for $u_{jmax}^{n+1}$ with the auxiliary value $u_{jmax+1}^n= u_{jmax}^n$ (a constant extrapolation) or $u_{jmax+1}^n= 2 u_{jmax}^n - u_{jmax-1}^n$ (a linear extrapolation). One can see such treatment as "do nothing boundary conditions" that is appropriate here. For instance if you use a proper upwind method instead of leapfrog method, you even need no auxiliary values to compute $u_{jmax}^{n+1}$.

For the inflow boundary, i.e. the left point of $v>0$, you must prescribe the values $u_0^{n+1}$ directly by "Dirichlet boundary conditions".

For the case of advection-diffusion equation you can in theory define the no-flux boundary conditions as you write with $D \neq 0$, but it means for $v>0$ that you prescribe an "inward diffusion", consequently a corresponding gradient, that will cancel the advection flux, so the total flux will be zero. Such situation is hard to find in practice. More typical is to prescribe something only for the diffusion flux and to use the previous ``do nothing'' approach (or an extrapolation) for the advective flux.

If you consider only the pure advective part and let, say, $v>0$, then you can obtain "no flux condition" at the right point only by setting (redefining) $v=0$ there. Of course, the solution can then develop a "boundary layer" there and it can become discontinuous at the right point as the solution will preserve there the value given by initial condition, i.e. $u_{jmax}^{n+1} = u^0_{jmax}$.

A natural boundary condition for constant speed $v>0$ is that you let the solution "flow out" through the right point of interval that can be viewed as outflow boundary. It can be obtained by applying your leapfrog method for $u_{jmax}^{n+1}$ with the auxiliary value $u_{jmax+1}^n= u_{jmax}^n$ (a constant extrapolation) or $u_{jmax+1}^n= 2 u_{jmax}^n - u_{jmax-1}^n$ (a linear extrapolation). One can see such treatment as "do nothing boundary conditions" that is appropriate for outflow boundary and pure advection. It is like you are solving the pure advection (the differential equation) also at the right point.

Just a remark - if you use a proper upwind method instead of leapfrog method, you even need no auxiliary values outside of your domain to compute $u_{jmax}^{n+1}$.

For the inflow boundary, i.e. the left point in the case $v>0$, you must prescribe the values $u_0^{n+1}$ directly by "Dirichlet boundary conditions" and not solving the differential equation.

For the case of advection-diffusion equation you can in theory define the no-flux boundary conditions as you write with $D \neq 0$, but it means for $v>0$ that you prescribe an "inward diffusion", consequently a corresponding gradient, that will cancel the advection flux, so the total flux will be zero. Such situation is hard to find in practice. More typical is to prescribe something only for the diffusion flux and to use the previous ``do nothing'' approach (or an extrapolation) for the advective flux.

1
source | link

If you consider only the pure advective part and let, say, $v>0$, then you can obtain "no flux condition" at the right point only by setting (redefining) $v=0$ there. Of course, the solution can then develop a "boundary layer" there.

A natural boundary condition for constant speed $v>0$ is that you let the solution "flow out" through the right point of interval that can be viewed as outflow boundary. It can be obtained by applying your leapfrog method for $u_{jmax}^{n+1}$ with the auxiliary value $u_{jmax+1}^n= u_{jmax}^n$ (a constant extrapolation) or $u_{jmax+1}^n= 2 u_{jmax}^n - u_{jmax-1}^n$ (a linear extrapolation). One can see such treatment as "do nothing boundary conditions" that is appropriate here. For instance if you use a proper upwind method instead of leapfrog method, you even need no auxiliary values to compute $u_{jmax}^{n+1}$.

For the inflow boundary, i.e. the left point of $v>0$, you must prescribe the values $u_0^{n+1}$ directly by "Dirichlet boundary conditions".

For the case of advection-diffusion equation you can in theory define the no-flux boundary conditions as you write with $D \neq 0$, but it means for $v>0$ that you prescribe an "inward diffusion", consequently a corresponding gradient, that will cancel the advection flux, so the total flux will be zero. Such situation is hard to find in practice. More typical is to prescribe something only for the diffusion flux and to use the previous ``do nothing'' approach (or an extrapolation) for the advective flux.