How to Apply Leap-Frog Scheme for Estuary System Dynamics in Fortran 95?

In summary, there are two ways to approach solving these equations using an explicit leap-frog scheme. One way is to use separate sets of do loops for each equation, while the other is to use a temporary array to store the values at each time step. Both methods can help with the issue you are facing with the do loops.
  • #1
edge333
16
0

Homework Statement



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 systemContinuity 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 * (n2)/(R(4/3)) * |u|

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

Homework Equations



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

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 don't 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
 
Last edited:
Physics news on Phys.org
  • #2
for how to properly write these do loops. Any help would be greatly appreciated.Thank you for sharing your attempt at solving these governing equations using an explicit leap-frog scheme. It seems like you have a good understanding of the equations and the finite difference approximation. However, as you mentioned, the issue lies in the do loops and the way you are trying to calculate the values of h and u.

One way to approach this problem is to use a separate set of do loops for each equation. For the continuity equation, you can start with the initial condition and use the calculated values of u to update the values of h at the next time step, and so on. Similarly, for the momentum equation, you can use the values of h to update the values of u at the next time step. This way, you will have two sets of do loops that are independent of each other.

Another approach could be to use a temporary array to store the values of h and u at each time step and then update the actual arrays after each time step. In this case, you would only need one set of do loops where you calculate the values of h and u for each time step, store them in the temporary array, and then update the actual arrays using the values from the temporary array.

I hope this helps. If you have any further questions or need clarification, please don't hesitate to ask. Good luck with your calculations!
 

FAQ: How to Apply Leap-Frog Scheme for Estuary System Dynamics in Fortran 95?

What is a "Do Loop" in Fortran 95?

A "Do Loop" is a control structure in Fortran 95 that allows for the repeated execution of a block of code. It is similar to a "For Loop" in other programming languages.

How do I write a "Do Loop" in Fortran 95?

To write a "Do Loop" in Fortran 95, you first need to specify the number of times you want the loop to run using the "Do" statement. Then, you can include the code you want to repeat within the loop between the "Do" and "End Do" statements.

Can I use a variable as the number of iterations in a "Do Loop"?

Yes, you can use a variable as the number of iterations in a "Do Loop" in Fortran 95. This allows for more flexibility in the loop and allows the number of iterations to change during the execution of the program.

How do I control the flow of a "Do Loop" in Fortran 95?

You can control the flow of a "Do Loop" in Fortran 95 by using the "Exit" and "Cycle" statements. The "Exit" statement will immediately exit the loop, while the "Cycle" statement will skip to the next iteration of the loop.

Can I nest "Do Loops" in Fortran 95?

Yes, you can nest "Do Loops" in Fortran 95 by including one loop within another loop. This allows for more complex logic and repetition in your code.

Similar threads

Replies
6
Views
6K
Replies
4
Views
5K
Replies
6
Views
1K
Replies
3
Views
2K
Replies
4
Views
1K
Replies
7
Views
2K
Replies
2
Views
2K
Back
Top