forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Do-loop alternating

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
curoi



Joined: 04 Mar 2012
Posts: 6

PostPosted: Mon Mar 05, 2012 12:19 am    Post subject: Do-loop alternating Reply with quote

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 * 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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group