Fortran Need help with Jacobi relaxation method for Dirichlet boundary conditions

AI Thread Summary
The discussion focuses on a Fortran program implementing the Jacobi method for solving partial differential equations. Key points include the initialization of variables, grid allocation, boundary conditions, and the Jacobi iteration process. The program sets up a computational grid defined by dimensions Lx and Ly, with nx and ny points. Boundary conditions are applied to the phi array, which represents the solution at each grid point. The Jacobi iteration is performed to update the phi values based on finite difference approximations for spatial derivatives. An error is highlighted in line 94, indicating a missing multiplication operator, which could lead to compilation issues. Additionally, suggestions are made to improve code readability by adding spaces and breaking long lines into multiple statements.
Nikolas_Ex_Aguirre
Messages
1
Reaction score
0
TL;DR Summary
I have a problem with this code that i made. every time that i run it, this shows an error (is the same in the image), and i don't know how to fix this. It's a jacobi relaxation method for a dirichlet boundary conditions.
Code:
program r_jacobi

  implicit none

!!!!Variables!!!

  real*8 V, V_1, V_2, Lx, Ly
  integer n ,i , j, k, nx, ny
  real*8, allocatable :: arrx(:), arry(:), phi(:,:,:)
  real*8 x, xi, xf, y, yi, yf, dx, dy

  real*8 d, q, bx, by

  V=1
  V_1=V
  V_2=-V

  Lx = 2
  Ly = 1
  nx = 200
  ny = nx/2

  n = 200
  k = 200
  allocate(arrx(nx))
  allocate(arry(ny))
  allocate(phi(n,nx,ny))!!!GRID!!!

  xi = 0
  xf = Lx
  dx = (xf-xi)/(nx-1)
  yi = 0
  yf = Ly
  dy = (yf-yi)/(ny-1)

  d = 2*(dx**(-1)+dy**(-1))  do j = 1,ny
     do i = 1,nx
        x = xi+(i-1)*dx
        arrx(i) = x
        y = yi+(j-1)*dy
        arry(j)=y
     end do
  end do

!!!BC!!!

  do j = 1,ny
     do i = 1,nx
        phi(1,i,j) = (V_1+V_2)/2
     end do
  end do
 
  do i = 1, nx/2
     phi(1,i,1) = V_1
     phi(1,i,ny) = V_1
  end do

  do i = nx/2 +1, nx
     phi(1,i,1) = V_2
     phi(1,i,ny) = V_2
  end do

  do j = 1, ny
     phi(1,1,j) = V_1
     phi(1,nx,j) = V_2
  end do
!!!jacobi!!! 
!delta_2^x = u^n_j+1_k - 2 u^n_j_k + u^n_j-1_k
!delta_2^y = u^n_j_k+1 - 2 u^n_j_k + u^n_j_k-1

!alpha^0_jk = -2(1/dx^2 + 1/dy^2)
!alpha^1_jk = alpha^2_jk = -1/dx^2
!alpha^3_jk = alpha^4_jk = -1/dy^2  do k = 1, n
     do j = 2, ny-1
        do i = 2, nx-1
           bx = phi(k,i+1,j) - 2*phi(k,i,j) + phi(k,i-1,j)
           by = phi(k,i,j+1) - 2*phi(k,i,j) + phi(k,i,j-1)
           q = -dx**(-2)*(phi(k,i,j))*bx - dy**(-2)*phi(k,i,j)*by
           phi(k+1,i,j)=d**(-1)(q+dx**(-1)*(phi(k,i+1,j)+phi(k,i-1,j))+dy**(-1)*(phi(k,i,j+1)&
                +phi(k,i,j-1)))
        end do
     end do
  end do 
end program r_jacobi
error.png
 
Last edited by a moderator:
Technology news on Phys.org
Nikolas_Ex_Aguirre said:
Fortran:
phi(k+1,i,j)=d**(-1)(q+dx**(-1)*(phi(k,i+1,j)+phi(k,i-1,j))+dy**(-1)*(phi(k,i,j+1)& +phi(k,i,j-1)))
The error message says there is a problem with line 94, which I've copied above. It looks to me like you are missing '*" to the right of the assignment operator, and between d**(-1) and the stuff following it. In other words,
phi(k+1, i, j) = d**(-1) * (a + dx**(-1) * ...
There might be other errors as well.

Do yourself and anyone else who has to read your code by inserting some spaces. If this makes the line too long, break up the line into multiple assignment statements.
 
  • Like
Likes dlgoff and berkeman
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
6
Views
7K
Replies
12
Views
3K
Replies
7
Views
3K
Replies
3
Views
2K
Replies
9
Views
9K
Replies
4
Views
2K
Replies
1
Views
3K
Back
Top