Silverfrost Forums

Welcome to our forums

Do-loop alternating

4 Mar 2012 11:19 #9752

I'm trying to solve two partial differential equations using finite difference approximations. The way I went about trying to solve this explicit scheme in Fortran 95 included two sets of do loops that were meant to alternate between the h values at some time step n for all i, the u values at the subsequent time step n + 1 for all i, and then the h values at the next time step n + 2 at all i, etc. The problem is that some u values depend on h and some h values depend on u but I dont know how to write the do loops for the internal cells (excluding the boundary conditions, initial condition, and initial FTCS h equation) without Fortran trying to calculate ALL the h values and then ALL the u values or vice versa.

Here is a part of the code:

! Internal centered-time, centered-space finite difference approximations for the momentum equation do i = 3, ndx - 1, 2

do n = 3, nts - 1, 2

u( i, n ) = ( u( i, n - 2 ) - g * ( dt / dx ) * ( h( i + 1, n - 1 ) - h( i - 1, n - 1 ) ) &

  • dt * g * mff2 / hr( i )( 4 / 3 ) * abs( u( i, n - 2 ) ) * u( i, n - 2 ) ) & / ( 1 + dt * g * mff2 / hr( i )( 4 / 3 ) * abs( u( i, n - 2 ) ) )

end do

end do ! Internal centered-time, centered-space finite difference approximations for the continuity equation do i = 2, ndx - 2, 2 ! ndx - 2 to account for the last spatial step i = 51 and the fact that i = 50 ends on a u, not h value

do n = 4, nts - 2, 2

h( i, n ) = h( i, n - 2 ) - ( dt / dx ) * dep( i ) * ( u( i + 1, n - 1 ) - u( i - 1, n - 1 ) )

end do

end do

What I would like to have it do is calculate u values for n = 3 for all i, then h values for n = 4 for all i, then u values again for n = 5 for all i, etc. I've read up on the CYCLE function for Fortran 95 but I'm still at a loss.

Please login to reply.