Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP: program is not working. don't know why

Status
Not open for further replies.

FortranPirate

Programmer
Apr 24, 2005
3
US
I keep getting this error when i try to excute the program.

Linking...
ex.obj : error LNK2001: unresolved external symbol _P@8
ex.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
ex.exe - 2 error(s), 0 warning(s)

I have no clue why, except that its due to the subroutine.

the subroutine code was given to me by the professor, i believe its written in fortran 77. but my code is in 90.

Please help,
the code I am trying to run is..

PROGRAM Project2

IMPLICIT NONE

REAL F, G, Q, Po, Uo, Vo, Qo, U, V, P, Re, dx, dy, dt, t, f1,f2,f3,f4,g1,g2,g3,g4,nts, erroru, errorv, nstop, time

INTEGER imax, jmax, i, j

PARAMETER (imax=100,jmax=100)

DIMENSION F(imax,jmax), G(imax,jmax), Q(imax,jmax), Uo(imax,jmax), Vo(imax,jmax), Po(imax,jmax), Qo(imax,jmax), U(imax,jmax), V(imax,jmax)

OPEN (unit=2, file='testoutput', status = 'new')

Re = 1000.0
dx = 1.0/float(imax-2)
dy = dx
dt=0.25*Re*dx*dx*0.1
nts = 0.0
erroru = 0.0
errorv = 0.0
nstop = 1

!initial conditions
DO i=1, imax
Do j=1, jmax

Uo(i,j) = 0.0
Vo(i,j) = 0.0
Po(i,j) = 0.0

END DO
END DO



DO i=1, imax
DO j=1, jmax

!boundary conditions
nts = nts +1
time = time + dt



Vo(i,1) = 0
Vo(i,2) = 0
Vo(i,jmax+1) = 0
Vo(i,jmax-1) = 0
Uo(1,j) = 0
Uo(2,j) = 0
Uo(imax-1,j) = 0
Uo(imax+1,j) = 0


Uo(i+1,1) = -2 - Uo(i+1,2)
Uo(i-1,1) = -2 - Uo(i-1,2)
Uo(i+1,jmax) = 2 - Uo(i+1,jmax - 1)
Uo(i-1,jmax) = 2 - Uo(i-1,jmax - 1)
Vo(1,j+1) = -Vo(2,j+1)
Vo(1,j-1) = -Vo(2,j-1)
Vo(imax,j+1) = -Vo(imax-1,j+1)
Vo(imax,j-1) = -Vo(imax-1,j-1)


!Fn calculation
f1 = (Uo(i+2,j) - 2*Uo(i,j) + Uo(i-1,j))/(Re*dx**2)
f2 = (Uo(i,j-1) - 2*Uo(i,j) + Uo(i,j+1))/(Re*dy**2)
f3 = (((Uo(i+1,j) + Uo(i,j))/2)**2 - ((Uo(i,j) + Uo(i-1,j))/2)**2)/(dx)
f4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i,j)+Uo(i,j-1))*(Vo(i+1,j-1)+Vo(i,j-1)))/(dy)))

F(i,j) = Uo(i,j) + dt*(f1 + f2 - f3 - f4)


!Gn calculation
g1 = (Vo(i+1,j) - 2*Vo(i,j+1) + Vo(i-1,j+1))/(Re*(dx)**2)
g2 = (Vo(i,j+1) - 2*Vo(i,j) + Vo(i,j-1))/(Re*(dy)**2)
g3 = (((Vo(i,j+1) + Vo(i,j))/2)**2 - ((Vo(i,j) + Vo(i,j-1))/2)**2)/(dy)
g4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i-1,j)+Uo(i-1,j+1))*(Vo(i-1,j)+Vo(i,j)))/(dy)))

G(i,j) = Vo(i,j+1) + dt*(g1 + g2 - g3 - g4)

!Qn calculation
Q(i,j) = (1/dt)*((F(i+1,j) - F(i-1,j))/dx + (G(i,j+1) - G(i,j-1))/dy)

END DO !j
END DO !i

CALL poisson

!calculation of Un+1 and Vn+1
Do i=2,imax-1
Do j=2,jmax-1

U(i,j) = F(i,j) - dt/dx*((P(i,j)+P(i+1,j))/2 - (P(i,j)+P(i-1,j))/2)
V(i,j) = G(i,j) - dt/dy*((P(i,j)+P(i,j+1))/2 - (P(i,j)+P(i,j-1))/2)


Uo(i,j) = U(i,j)
Vo(i,j) = V(i,j)
Po(i,j) = P(i,j)
Qo(i,j) = Q(i,j)


erroru = (U(i,j) - Uo(i,j))
errorv = (V(i,j) - Vo(i,j))

IF (erroru.lt.0.01 .and. errorv.lt.0.01) then

print*, erroru, errorv
END IF

END DO !j
END DO !i

END DO !dt

!!!!!!!!!!!!!!!!!!!!!!!!!!!!! writing u,v,p to file
i=x
j=y

DO i=1, imax
DO j=1, jmax

UU(i,j) = (U(i,j) + U(i+1,j))/2
VV(i,j) = (V(i,j) + V(i+1,j))/2

END DO !j
END DO !i

WRITE (2,70) 'x','y','U','V'
70 FORMAT (1x,A8,T12,A8,T22,A8,T32,A9/1x, 40("="))
WRITE (2,80) x,y,UU,VV
80 FORMAT (1x, I6, 2I10, 2x, F10.4)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END PROGRAM


!Poisson calculation
subroutine poisson
implicit real*8(a-h,o-z)
parameter (imax=42,jmax=42)

dimension u(imax,jmax),v(imax,jmax),p(imax,jmax),q(imax,jmax)
common /Po/U,V,P,Q,Re,time,nts,dx

rf=1.6
eps=0.01
itmax=5000
iter=0

10 iter=iter+1
change=0.0
do 20 i=2,i-1
do 20 j=2,j-1
pold=p(i,j)
p(i,j)=0.25*(p(i-1,j)+p(i,j-1)+p(i+1,j)+p(i,j+1)-q(i,j)*dx**2)
p(i,j)=pold+rf*(p(i,j)-pold)
if (pold .ne. 0.0) ch=dabs((p(i,j)-pold)/pold)
if (ch .gt. change) then
change=ch
im=i
jm=j
Po=pold
endif
20 continue

do 40 k=1,imax
p(k,1)=p(k,2)-2.*v(k,2)/Re/dx
p(k,j)=p(k,j-1)+2.*v(k,j-2)/Re/dx
p(1,k)=p(2,k)-2.*u(2,k)/Re/dx
40 p(i,k)=p(i-1,k)+2.*u(i-2,k)/Re/dx

if (iter .ge. itmax) then
write(2,*) '**** NO CONVERGENCE FOR "P" at Time= ',time
goto 50
endif
if (change .gt. eps) goto 10
50 continue

return
end subroutine
 
wait, i just noticed that there were some errors,

here is the code with no errors, but couple of warnings (x and y used but not set)



PROGRAM Project2

IMPLICIT NONE

REAL F, G, Q, Po, Uo, Vo, Qo, U, V, P, Re, dx, dy, dt, f1,f2,f3,f4,g1,g2,g3,g4,nts, erroru, errorv, nstop, time,x,y,UU,VV

INTEGER imax, jmax, i, j

PARAMETER (imax=100,jmax=100)

DIMENSION F(imax,jmax), G(imax,jmax), Q(imax,jmax), Uo(imax,jmax), Vo(imax,jmax), Po(imax,jmax), Qo(imax,jmax), U(imax,jmax), V(imax,jmax),UU(imax,jmax), VV(imax,jmax)

OPEN (unit=2, file='testoutput', status = 'new')

Re = 1000.0
dx = 1.0/float(imax-2)
dy = dx
dt=0.25*Re*dx*dx*0.1
nts = 0.0
erroru = 0.0
errorv = 0.0
nstop = 1

!initial conditions
DO i=1, imax
Do j=1, jmax

Uo(i,j) = 0.0
Vo(i,j) = 0.0
Po(i,j) = 0.0

END DO
END DO



DO i=1, imax
DO j=1, jmax

!boundary conditions
nts = nts +1
time = time + dt



Vo(i,1) = 0
Vo(i,2) = 0
Vo(i,jmax+1) = 0
Vo(i,jmax-1) = 0
Uo(1,j) = 0
Uo(2,j) = 0
Uo(imax-1,j) = 0
Uo(imax+1,j) = 0


Uo(i+1,1) = -2 - Uo(i+1,2)
Uo(i-1,1) = -2 - Uo(i-1,2)
Uo(i+1,jmax) = 2 - Uo(i+1,jmax - 1)
Uo(i-1,jmax) = 2 - Uo(i-1,jmax - 1)
Vo(1,j+1) = -Vo(2,j+1)
Vo(1,j-1) = -Vo(2,j-1)
Vo(imax,j+1) = -Vo(imax-1,j+1)
Vo(imax,j-1) = -Vo(imax-1,j-1)


!Fn calculation
f1 = (Uo(i+2,j) - 2*Uo(i,j) + Uo(i-1,j))/(Re*dx**2)
f2 = (Uo(i,j-1) - 2*Uo(i,j) + Uo(i,j+1))/(Re*dy**2)
f3 = (((Uo(i+1,j) + Uo(i,j))/2)**2 - ((Uo(i,j) + Uo(i-1,j))/2)**2)/(dx)
f4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i,j)+Uo(i,j-1))*(Vo(i+1,j-1)+Vo(i,j-1)))/(dy)))

F(i,j) = Uo(i,j) + dt*(f1 + f2 - f3 - f4)


!Gn calculation
g1 = (Vo(i+1,j) - 2*Vo(i,j+1) + Vo(i-1,j+1))/(Re*(dx)**2)
g2 = (Vo(i,j+1) - 2*Vo(i,j) + Vo(i,j-1))/(Re*(dy)**2)
g3 = (((Vo(i,j+1) + Vo(i,j))/2)**2 - ((Vo(i,j) + Vo(i,j-1))/2)**2)/(dy)
g4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i-1,j)+Uo(i-1,j+1))*(Vo(i-1,j)+Vo(i,j)))/(dy)))

G(i,j) = Vo(i,j+1) + dt*(g1 + g2 - g3 - g4)

!Qn calculation
Q(i,j) = (1/dt)*((F(i+1,j) - F(i-1,j))/dx + (G(i,j+1) - G(i,j-1))/dy)

END DO !j
END DO !i

CALL poisson

!calculation of Un+1 and Vn+1
Do i=2,imax-1
Do j=2,jmax-1

U(i,j) = F(i,j) - dt/dx*((P(i,j)+P(i+1,j))/2 - (P(i,j)+P(i-1,j))/2)
V(i,j) = G(i,j) - dt/dy*((P(i,j)+P(i,j+1))/2 - (P(i,j)+P(i,j-1))/2)


Uo(i,j) = U(i,j)
Vo(i,j) = V(i,j)
Po(i,j) = P(i,j)
Qo(i,j) = Q(i,j)


erroru = (U(i,j) - Uo(i,j))
errorv = (V(i,j) - Vo(i,j))

IF (erroru.lt.0.01 .and. errorv.lt.0.01) then

print*, erroru, errorv
END IF

END DO !j
END DO !i


!!!!!!!!!!!!!!!!!!!!!!!!!!!!! writing u,v,p to file
i=x
j=y

DO i=1, imax
DO j=1, jmax

UU(i,j) = (U(i,j) + U(i+1,j))/2
VV(i,j) = (V(i,j) + V(i+1,j))/2

END DO !j
END DO !i

WRITE (2,70) 'x','y','U','V'
70 FORMAT (1x,A8,T12,A8,T22,A8,T32,A9/1x, 40("="))
WRITE (2,80) x,y,UU,VV
80 FORMAT (1x, I6, 2I10, 2x, F10.4)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END PROGRAM


!Poisson calculation
subroutine poisson
implicit real*8(a-h,o-z)
parameter (imax=42,jmax=42)

dimension u(imax,jmax),v(imax,jmax),p(imax,jmax),q(imax,jmax)
common /Po/U,V,P,Q,Re,time,nts,dx

rf=1.6
eps=0.01
itmax=5000
iter=0

10 iter=iter+1
change=0.0
do 20 i=2,i-1
do 20 j=2,j-1
pold=p(i,j)
p(i,j)=0.25*(p(i-1,j)+p(i,j-1)+p(i+1,j)+p(i,j+1)-q(i,j)*dx**2)
p(i,j)=pold+rf*(p(i,j)-pold)
if (pold .ne. 0.0) ch=dabs((p(i,j)-pold)/pold)
if (ch .gt. change) then
change=ch
im=i
jm=j
Po=pold
endif
20 continue

do 40 k=1,imax
p(k,1)=p(k,2)-2.*v(k,2)/Re/dx
p(k,j)=p(k,j-1)+2.*v(k,j-2)/Re/dx
p(1,k)=p(2,k)-2.*u(2,k)/Re/dx
40 p(i,k)=p(i-1,k)+2.*u(i-2,k)/Re/dx

if (iter .ge. itmax) then
write(2,*) '**** NO CONVERGENCE FOR "P" at Time= ',time
goto 50
endif
if (change .gt. eps) goto 10
50 continue

return
end subroutine
 
It's a very suspicious common/Po/ declared only in the Poisson subroutine. In the PROGRAM Po var declared as an array...
Use CODE tags to represent your snippets (see Process TGML link on the post form).
 
Thanks, yeah I know that commom/Po/ is evil. so I went and deleted the subroutine and placed the contents into the main program. After more coding, I finally had it running, but it now gives me overflow errors after running 10 cycles, unless I change itmax=5000 to itmax=.01 (located in poissen), where it'll run for 33 seconds. After some initial checking, the problem is again the Poissen calculation or it could be the errorU/errorV calculation.

Again here is my code, hopefully the TGML thingy will work. Maybe someone can try running the code on their machine.

PROGRAM Project2

IMPLICIT NONE

REAL F, G, Q, Po, Uo, Vo, Qo, U, V, P, Re, dx, dy, dt, f1,f2,f3,f4,g1,g2,g3,g4,nts, erroru, errorv, nstop, time,x,y,UU,VV,rf, eps, itmax, iter,change, POLD,ch,im,jm,k,errumax,errvmax,Vm

INTEGER imax, jmax, i, j

PARAMETER (imax=42,jmax=42)

DIMENSION F(imax,jmax), G(imax,jmax), Q(imax,jmax), Uo(imax,jmax), Vo(imax,jmax), Po(imax,jmax), Qo(imax,jmax), U(imax,jmax), V(imax,jmax),UU(imax,jmax), VV(imax,jmax),P(imax,jmax),Vm(50,jmax)

OPEN (unit=2, file='testoutput.dat', status = 'replace')
OPEN (unit=3, file='v at midplane.dat', status = 'replace')
OPEN (unit=4, file='streamlines.dat', status = 'replace')


Re = 400.0
dx = 1.0/float(imax-2)
dy = dx
dt=0.25*Re*dx*dx*0.1
nts = 0.0
erroru = 0.0
errorv = 0.0
nstop = 1

!initial conditions
DO i=1, imax
Do j=1, jmax

Uo(i,j) = 0.0
Vo(i,j) = 0.0
Po(i,j) = 0.0

END DO
END DO

nts = nts +1
time = time + dt

DO time=1,2000

DO i=1, imax
DO j=1, jmax

!boundary conditions

Vo(i,1) = 0
Vo(i,2) = 0
Vo(i,jmax+1) = 0
Vo(i,jmax-1) = 0
Uo(1,j) = 0
Uo(2,j) = 0
Uo(imax-1,j) = 0
Uo(imax+1,j) = 0


Uo(i+1,1) = -2 - Uo(i+1,2)
Uo(i-1,1) = -2 - Uo(i-1,2)
Uo(i+1,jmax) = 2 - Uo(i+1,jmax - 1)
Uo(i-1,jmax) = 2 - Uo(i-1,jmax - 1)
Vo(1,j+1) = -Vo(2,j+1)
Vo(1,j-1) = -Vo(2,j-1)
Vo(imax,j+1) = -Vo(imax-1,j+1)
Vo(imax,j-1) = -Vo(imax-1,j-1)


!Fn calculation
f1 = (Uo(i+2,j) - 2*Uo(i,j) + Uo(i-1,j))/(Re*dx**2)
f2 = (Uo(i,j-1) - 2*Uo(i,j) + Uo(i,j+1))/(Re*dy**2)
f3 = (((Uo(i+1,j) + Uo(i,j))/2)**2 - ((Uo(i,j) + Uo(i-1,j))/2)**2)/(dx)
f4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i,j)+Uo(i,j-1))*(Vo(i+1,j-1)+Vo(i,j-1)))/(dy)))

F(i,j) = Uo(i,j) + dt*(f1 + f2 - f3 - f4)


!Gn calculation
g1 = (Vo(i+1,j) - 2*Vo(i,j+1) + Vo(i-1,j+1))/(Re*(dx)**2)
g2 = (Vo(i,j+1) - 2*Vo(i,j) + Vo(i,j-1))/(Re*(dy)**2)
g3 = (((Vo(i,j+1) + Vo(i,j))/2)**2 - ((Vo(i,j) + Vo(i,j-1))/2)**2)/(dy)
g4 = ((0.25*(Uo(i,j)+Uo(i,j+1))*(Vo(i+1,j)+Vo(i,j)) - (0.25*(Uo(i-1,j)+Uo(i-1,j+1))*(Vo(i-1,j)+Vo(i,j)))/(dy)))

G(i,j) = Vo(i,j+1) + dt*(g1 + g2 - g3 - g4)

!Qn calculation
Q(i,j) = (1/dt)*((F(i+1,j) - F(i-1,j))/dx + (G(i,j+1) - G(i,j-1))/dy)

END DO !j
END DO !i

!POISSON Calculation


rf=1.6
eps=0.01
itmax=5000
iter=0

10 iter=iter+1
change=0.0
do 20 i=2,imax-1
do 20 j=2,jmax-1
pold=p(i,j)
p(i,j)=0.25*(p(i-1,j)+p(i,j-1)+p(i+1,j)+p(i,j+1)-q(i,j)*dx**2)
p(i,j)=pold+rf*(p(i,j)-pold)
if (pold .ne. 0.0) ch = abs((p(i,j)-pold)/pold)
if (ch .gt. change) then
change=ch
im=i
jm=j
Po=pold
endif
20 continue

do 40 k=1,imax
p(k,1)=p(k,2)-2.*v(k,2)/Re/dx
p(k,j)=p(k,j-1)+2.*v(k,j-2)/Re/dx
p(1,k)=p(2,k)-2.*u(2,k)/Re/dx
40 p(i,k)=p(i-1,k)+2.*u(i-2,k)/Re/dx

if (iter .ge. itmax) then
WRITE(*,*) '**** NO CONVERGENCE FOR "P" at Time= ',time
goto 50
endif
if (change .gt. eps) goto 10
50 continue

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

!calculation of Un+1 and Vn+1
Do i=2,imax-2
Do j=2,jmax-1

U(i,j) = F(i,j) - (dt/dx)*((P(i,j)+P(i+1,j))/2 - (P(i,j)+P(i-1,j))/2)

Uo(i,j) = U(i,j)

Po(i,j) = P(i,j)
Qo(i,j) = Q(i,j)

END DO
END DO

Do i=2,imax-1
Do j=2,jmax-2

V(i,j) = G(i,j) - (dt/dy)*((P(i,j)+P(i,j+1))/2 - (P(i,j)+P(i,j-1))/2)

Vo(i,j) = V(i,j)

Po(i,j) = P(i,j)
Qo(i,j) = Q(i,j)

END DO
END DO






errumax=0.0
errvmax=0.0

do 140 i=2, jmax-1
do 140 j=2, jmax-1

erroru = abs(U(i,j) - Uo(i,j))
errorv = abs(V(i,j) - Vo(i,j))
IF (errumax.lt.erroru) errumax=erroru
IF (errvmax.lt.errorv) errvmax=errorv
140 continue

IF (errumax.lt.eps .and. errvmax.lt.eps) then

print*, 'erroru=',erroru, 'errorv=',errorv
END IF



END DO !time

!!!!!!!!!!!!!!!!!!!!!!!!!!!!! writing u,v,p to file
x=i
y=j

DO i=1, imax
DO j=1, jmax

UU(i,j) = (U(i,j) + U(i+1,j))/2
VV(i,j) = (V(i,j) + V(i+1,j))/2

END DO !j
END DO !i

Do j=1,jmax

Vm=V(50,j)

END DO !j

PRINT*, UU,VV

WRITE (2,70) 'x','y','U','V','p'
70 FORMAT (1x,A8,T12,A8,T22,A8,T32,A9/1x, 40("="))

WRITE (4,71) x,y,UU,VV,P
71 FORMAT (1x,I6,2I10,2x,F10.4)

WRITE (3,72) Vm
72 FORMAT (1x,I6,2I10,2x,F10.4)


!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END PROGRAM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top