(adsbygoogle = window.adsbygoogle || []).push({}); 1. The problem statement, all variables and given/known data

Use an explicit leap-frog scheme for the following two governing equations describing head and velocity in a estuary system (time and x-direction) due to tidal forces and river flow.

The length of the system, L, is 100 km. Both the depth, a, and the width, B, vary linearly over the length of the system

Continuity Equation:

dh/dt + a * du/dx = 0

Momentum Equation:

du/dt + g * dh/dx - r * u

where u is velocity of the water, h is the head (m), a is the depth of the river system, g is the acceleration due to gravity (9.81 m/s), and r is a term described as

r = g * (n^{2})/(R^{(4/3)}) * |u|

R is the hydraulic radius defined as cross-sectional area of the river system divided by the wetted perimeter.

2. Relevant equations

Solving these equations requires using a finite difference approximation for each that is centered-time and centered space (CTCS).

3. The attempt at a solution

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 * mff**2 / hr( i )**( 4 / 3 ) * abs( u( i, n - 2 ) ) * u( i, n - 2 ) ) &

/ ( 1 + dt * g * mff**2 / 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

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Do Loops in Fortran 95

Can you offer guidance or do you also need help?

**Physics Forums | Science Articles, Homework Help, Discussion**