Neumann boundary with finite differences

Click For Summary
The discussion revolves around solving the Laplace equation for steady-state temperature using finite differences with Neumann and Dirichlet boundary conditions. The user implemented a specific formula for the Neumann boundary condition but noticed discrepancies in results compared to MATLAB's PDE toolbox. They explored different discretization approaches, including central and one-sided derivatives, to accurately represent the Neumann condition. The code provided demonstrates how boundary conditions are applied, particularly for points with Neumann conditions, using relaxation methods for convergence. The user seeks clarification on whether their approach is correct or if adjustments are needed for accurate results.
JohanL
Messages
154
Reaction score
0
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 I am doing something wrong with the neumann boundary condition.
 
Physics news on Phys.org
Assuming you used discretisation:

\frac{1}{h^2}(u_{i+1}-2u_i+u_{i-1})

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

\frac{\partial T(0,t)}{\partial X}=0

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

\frac{1}{h}\left(\frac{u_{i+1}-u_i}{h}-\frac{u_i-u_{i-1}}{h}\right)

Where the \frac{u_i-u_{i-1}}{h} bit is given by the b.c.
 
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
 
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.
 
Clausius2 said:
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.

Isnt that what I am 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;
 
Question: A clock's minute hand has length 4 and its hour hand has length 3. What is the distance between the tips at the moment when it is increasing most rapidly?(Putnam Exam Question) Answer: Making assumption that both the hands moves at constant angular velocities, the answer is ## \sqrt{7} .## But don't you think this assumption is somewhat doubtful and wrong?

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K