Crank-Nicholson method and Robin boundary conditions

In summary, we discussed the use of the Crank-Nicholson method to solve a PDE with boundary conditions and how to properly discretize the boundary conditions. We also discussed two different methods of solution and how they should theoretically give the same answer.
  • #1
hunt_mat
Homework Helper
1,782
32
TL;DR Summary
How does one implement the Robin condition for Crank-Nicholson?
I have the following PDE I wish to solve:
[tex]
\frac{\partial u}{\partial t}=D\frac{\partial^{2}u}{\partial x^{2}}
[/tex]

With the following boundary conditions:

[tex]
\frac{\partial u}{\partial x}(t,1)+u(t,1)=f(t),\quad u(t,0)=0
[/tex]

Now, I wish to do this via the Crank-Nicholson method and I would naively apply the method in the following way:
[tex]
\frac{u_{i,N}-u_{i,N-1}}{\delta r}+u_{i,N}=f(t_{i})\equiv f_{i}
[/tex]

Now the stencil for the CN method is:
[tex]
su_{i+1,j+1}-(2s+1)u_{i+1,j}+su_{i+1,j-1}=-(su_{i,j+1}-(2s+1)u_{i,j}+su_{i,j-1})
[/tex]

On the boundary this becomes:

[tex]
su_{i+1,N}-(2s+1)u_{i+1,N-1}+su_{i+1,N-2}=-(su_{i,N}-(2s+1)u_{i,N-1}+su_{i,N-2})
[/tex]

I can write the boundary term as:

[tex]
(1+\delta r)u_{i+1,N}=u_{i+1,N-1}+f_{i}\delta r
[/tex]

So I can then write:

[tex]
\left(\frac{s}{1+\delta r}-(2s+1)\right)u_{i+1,N-1}+su_{i+1,N-2}=-(su_{i,N}-(2s+1)u_{i,N-1}+su_{i,N-2})-\frac{s\delta r}{1+\delta r}f_{i+1}
[/tex]

The system of equations is then:
[tex]
A\mathbf{u}^{i+1}=-B\mathbf{u}^{i}=-\mathbf{b}
[/tex]

I've seen this done with a symmetric version of the first derivative, is that the right thing to do or is what I'm suggesting correct? I've got this coded up and it doesn't look the right sort of thing.
 
  • Like
Likes Delta2
Physics news on Phys.org
  • #2
I would have used a central difference on the boundary condition, and combined it with the global difference equation at N to eliminate the value at N+1.
 
  • Like
Likes hunt_mat
  • #3
Yes, I realize why that is done, the method I initially proposed doesn't yield the derivative on the actual boundary. My code still doesn't seem to work as intended though.
 
  • #4
You didn't supply the boundary condition at x=0, so I assume it is a constant. Incidentally, this looks like a Cartesian system given the PDE and x as a variable, but you have r in the boundary condition discretization so... I will assume the PDE is right.

If we use a central difference on the boundary then we end up with (I use superscripts for the time):

##\frac{u_{N+1}^{k} - u_{N-1}^{k}}{2\Delta x} + u_{N}^{k} = f_i##

This can be solved for the fake node at N+1 and put into the general formulation for the internal nodes. For 3 nodes, this gives the below system. Note for more nodes the second row is simply repeated with corresponding node adjustments in the u vector to form a tri-diagonal system.

##M =
\begin{matrix}
1 & 0 & 0\\
-A & 2(1+A) & -A \\
0&-2A & 2(1+AB)
\end{matrix} ##

## u^k =
\begin{matrix}
u_0^k \\
Au_0^k + 2(1-A)u_1^k + Au_2^k \\
2Au_1^k + 2(1-AB)u_2^k+4A\Delta x f_2
\end{matrix} ##

Where ## A = \frac{D\Delta t}{(\Delta x)^2}## and ##B = 1 + \Delta x##. The updated values of u are given as solutions of ##Mu^{k+1} = u^k##.
 
Last edited:
  • #5
I thought I supplied the boundary condition at [itex]x=0[/itex], it was [itex]u(t,0)=0[/itex].
 
Last edited:
  • #6
Yes, I see it now. I'm not sure how I missed it. At least it's a constant as I assumed. :cool:
 
  • #7
I was hoping that my two methods of solution would a) work and b) give the same answer as one another.
 
  • #8
with solution A1(r,ϵ)A1(r,ϵ). In particular, for ϵ=0ϵ=0 you get the solution A1(r,0)A1(r,0) which is a solution for ddrA=F(A,r)ddrA=F(A,r), so you should get the same solutions (if they agree at a point and the differential equation behaves nicely enough to get a unique solution).Tutuapp 9apps ShowBox
 
  • #9
This has now been solved and is a dead thread.
 

1. What is the Crank-Nicholson method?

The Crank-Nicholson method is a numerical method used to solve partial differential equations (PDEs). It is a combination of the forward Euler method and the backward Euler method, resulting in a second-order accurate method that is unconditionally stable.

2. How does the Crank-Nicholson method work?

The Crank-Nicholson method works by taking a time step and dividing it into two sub-steps. In the first sub-step, the PDE is evaluated using the forward Euler method, and in the second sub-step, it is evaluated using the backward Euler method. The average of these two sub-steps gives the solution for the time step.

3. What are Robin boundary conditions?

Robin boundary conditions are a type of boundary condition used in PDEs that involve a combination of both Dirichlet and Neumann boundary conditions. In other words, they specify a relationship between the solution and its derivative at the boundary.

4. How are Robin boundary conditions incorporated into the Crank-Nicholson method?

In the Crank-Nicholson method, Robin boundary conditions are incorporated by using a weighted average of the Dirichlet and Neumann boundary conditions in the first sub-step, and then using the Neumann boundary condition in the second sub-step.

5. What are some advantages of using the Crank-Nicholson method with Robin boundary conditions?

The Crank-Nicholson method with Robin boundary conditions has several advantages, including its second-order accuracy, unconditional stability, and ability to handle a wide range of boundary conditions. It is also more accurate and efficient than other methods, such as the forward Euler method or the backward Euler method, in solving PDEs with Robin boundary conditions.

Similar threads

Replies
1
Views
1K
  • Differential Equations
Replies
3
Views
1K
Replies
1
Views
1K
  • Differential Equations
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
Replies
1
Views
1K
Replies
1
Views
1K
  • Differential Equations
Replies
7
Views
392
  • Differential Equations
Replies
6
Views
2K
Back
Top