Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Neumann boundary with finite differences

  1. Apr 12, 2006 #1
    I tried to solve laplace equation for the steady state temperature over a rectangle with both neumann and dirichlet boundary conditions.
    For the part of the rectangle with neumann boundary condition(normal derivative = 0) i used

    U(k,p)=(2*U(k+1,p)+U(k,p+1)+U(k,p-1))/4

    Is this correct?
    The result i get is different from when i use Matlab PDE toolbox...and i think im doing something wrong with the neumann boundary condition.
     
  2. jcsd
  3. Apr 13, 2006 #2

    J77

    User Avatar

    Assuming you used discretisation:

    [tex]\frac{1}{h^2}(u_{i+1}-2u_i+u_{i-1})[/tex]

    Say your b.c. is at X=0 (T for temp. etc.):

    [tex]\frac{\partial T(0,t)}{\partial X}=0[/tex]

    For the discretisation, you don't know [tex]u_{i-1}[/tex] but you can rewrite the discretisation as:

    [tex]\frac{1}{h}\left(\frac{u_{i+1}-u_i}{h}-\frac{u_i-u_{i-1}}{h}\right)[/tex]

    Where the [tex]\frac{u_i-u_{i-1}}{h}[/tex] bit is given by the b.c.
     
  4. Apr 14, 2006 #3
    I did it like this

    if given homogenous neumann boundary condition for the points (0,j)

    Laplace equation gives

    4*T(0,j)=T(1,j)+T(-1,j)+T(0,j+1)+T(0,j-1) (*)

    then

    dT/dx=0 for those boundary points and i used

    dT/dx=[T(1,j)-T(-1,j)]/2*h

    and (-1,j) is outside the domain so i use

    T(-1,j)=T(1,j)-2*h*dT/dx

    and substituting this into (*) gives

    4*T(0,j)=T(1,j)+T(1,j)-2*h*dT/dx+T(0,j+1)+T(0,j-1)

    but dT/dx=0 which gives

    4*T(0,j)=2*T(1,j)+T(0,j+1)+T(0,j-1)

    ______________________________________
    in the code i have T=U and (i,j)=(k,p). The neumann boundary is for k=1 or Nx and 12<p<20 and otherwise dirichlet boundary conditions.

    Nmax=500; eps=10^(-3); n=0; delta=1; % parametrar
    while abs(delta)>eps & n<Nmax
    n=n+1
    for k=2:Nx-1
    for p=2:Ny-1

    if (k==1) & (12<p<20)
    dU(k,p)=(2*U(k+1,p)+U(k,p+1)+U(k,p-1))/4 ...
    -U(k,p);
    U(k,p)=U(k,p)+om*dU(k,p);

    elseif k==Nx & 12<p<20
    dU(k,p)=(2*U(k-1,p)+U(k,p+1)+U(k,p-1))/4 ...
    -U(k,p);
    U(k,p)=U(k,p)+om*dU(k,p);

    elseif (k~=1) | (k~=Nx)

    dU(k,p)=(U(k+1,p)+U(k-1,p)+U(k,p+1)+U(k,p-1))/4 ...
    -U(k,p);
    U(k,p)=U(k,p)+om*dU(k,p);

    else
    U(k,p)=U(k,p)
    end
    end
    end
    delta=max(max(dU)); disp(delta);
    end
     
  5. Apr 15, 2006 #4

    Clausius2

    User Avatar
    Science Advisor
    Gold Member

    I would rather leave interior domain points to Laplace discretization, and in the Neumman boundary I would chose either a 2nd order central derivative approx centered just on the boundary point and applying an image point at -1, or a one-sided 2nd order derivative in which you obtain the boundary point value as a function only of the inner points.
     
  6. Apr 16, 2006 #5
    Isnt that what im doing? (if you by image point mean phantom point?)

    Or is it something wrong with my approach?

    In the code its of course is
    for
    k=1:Nx

    First i calculate for the points on the boundary which have a neumann boundary condition:

    if (k==1) & (12<p<20)
    dU(k,p)=(2*U(k+1,p)+U(k,p+1)+U(k,p-1))/4 ...
    -U(k,p);
    U(k,p)=U(k,p)+om*dU(k,p);

    elseif k==Nx & (12<p<20)
    dU(k,p)=(2*U(k-1,p)+U(k,p+1)+U(k,p-1))/4 ...
    -U(k,p);
    U(k,p)=U(k,p)+om*dU(k,p);

    where om is a relaxation factor to speed up the calculations.

    Then i calculate for the interior points

    elseif (k~=1) | (k~=Nx)

    dU(k,p)=(U(k+1,p)+U(k-1,p)+U(k,p+1)+U(k,p-1))/4 ...
    -U(k,p);
    U(k,p)=U(k,p)+om*dU(k,p);

    and finally

    else
    U(k,p)=U(k,p)

    for those boundary points with dirichlet boundary conditions
    Nx = 36; Ny = 32;

    U=zeros(Nx,Ny);
    U(1:Nx,Ny)=100;
    U(1:Nx,1)=20;
    U(1,20:32)=100;
    U(Nx,20:32)=100
    U(1,1:12)=20;
    U(Nx,1:12)=20;
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook