program main !*****************************************************************************80 ! !! MAIN is the main program for MD. ! ! Discussion: ! ! MD implements a simple molecular dynamics simulation. ! ! The velocity Verlet time integration scheme is used. ! ! The particles interact with a central pair potential. ! ! Based on a FORTRAN90 program by Bill Magro. ! ! Usage: ! ! md nd np step_num dt ! ! where ! ! * nd is the spatial dimension (2 or 3); ! * np is the number of particles (500, for instance); ! * step_num is the number of time steps (500, for instance). ! * dt is the time step (0.1 for instance ) ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 26 December 2014 ! ! Author: ! ! John Burkardt ! implicit none real ( kind = 8 ), allocatable :: acc(:,:) integer ( kind = 4 ) arg_num real ( kind = 8 ) ctime real ( kind = 8 ) ctime1 real ( kind = 8 ) ctime2 real ( kind = 8 ) dt real ( kind = 8 ) e0 real ( kind = 8 ), allocatable :: force(:,:) integer ( kind = 4 ) iarg integer ( kind = 4 ) id integer ( kind = 4 ) ierror real ( kind = 8 ) kinetic integer ( kind = 4 ) last real ( kind = 8 ), parameter :: mass = 1.0D+00 integer ( kind = 4 ) nd integer ( kind = 4 ) np real ( kind = 8 ), allocatable :: pos(:,:) real ( kind = 8 ) potential real ( kind = 8 ) rel integer ( kind = 4 ) step integer ( kind = 4 ) step_num integer ( kind = 4 ) step_print integer ( kind = 4 ) step_print_index integer ( kind = 4 ) step_print_num character ( len = 255 ) string real ( kind = 8 ), allocatable :: vel(:,:) real ( kind = 8 ) wtime call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'MD' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' A molecular dynamics program.' ! ! Get the number of command line arguments. ! arg_num = iargc ( ) ! ! Get ND, the number of spatial dimensions. ! if ( 1 <= arg_num ) then iarg = 1 call getarg ( iarg, string ) call s_to_i4 ( string, nd, ierror, last ) else write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Enter ND, the spatial dimension (2 or 3 ):' read ( *, * ) nd end if ! ! Get NP, the number of particles. ! if ( 2 <= arg_num ) then iarg = 2 call getarg ( iarg, string ) call s_to_i4 ( string, np, ierror, last ) else write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' Enter NP, the number of particles (500, for instance):' read ( *, * ) np end if ! ! Get STEP_NUM, the number of time steps. ! if ( 3 <= arg_num ) then iarg = 3 call getarg ( iarg, string ) call s_to_i4 ( string, step_num, ierror, last ) else write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' Enter STEP_NUM, the number of time steps (500, for instance):' read ( *, * ) step_num end if ! ! Get DT, the time step. ! if ( 4 <= arg_num ) then iarg = 4 call getarg ( iarg, string ) call s_to_r8 ( string, dt ) else write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' Enter DT, the time step size (0.1, for instance):' read ( *, * ) dt end if ! ! Report. ! write ( *, '(a)' ) ' ' write ( *, '(a,i8)' ) ' ND, the spatial dimension, is ', nd write ( *, '(a,i8)' ) & ' NP, the number of particles in the simulation is ', np write ( *, '(a,i8)' ) ' STEP_NUM, the number of time steps, is ', step_num write ( *, '(a,g14.6)' ) ' DT, the size of each time step, is ', dt ! ! Allocate memory. ! allocate ( acc(nd,np) ) allocate ( force(nd,np) ) allocate ( pos(nd,np) ) allocate ( vel(nd,np) ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' At each step, we report the potential and kinetic energies.' write ( *, '(a)' ) ' The sum of these energies should be a constant.' write ( *, '(a)' ) ' As an accuracy check, we also print the relative error' write ( *, '(a)' ) ' in the total energy.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' Step Potential Kinetic (P+K-E0)/E0' write ( *, '(a)' ) & ' Energy P Energy K Relative Energy Error' write ( *, '(a)' ) ' ' ! ! This is the main time stepping loop: ! Initialize or update positions, velocities, accelerations. ! Compute forces and energies, ! step_print = 0 step_print_index = 0 step_print_num = 10 call cpu_time ( ctime1 ) do step = 0, step_num if ( step == 0 ) then call initialize ( np, nd, pos, vel, acc ) else call update ( np, nd, pos, vel, force, acc, mass, dt ) end if call compute ( np, nd, pos, vel, mass, force, potential, kinetic ) if ( step == 0 ) then e0 = potential + kinetic end if if ( step == step_print ) then rel = ( potential + kinetic - e0 ) / e0 write ( *, '(2x,i8,2x,g14.6,2x,g14.6,2x,g14.6)' ) & step, potential, kinetic, rel step_print_index = step_print_index + 1 step_print = ( step_print_index * step_num ) / step_print_num end if end do ! ! Report time. ! call cpu_time ( ctime2 ) ctime = ctime2 - ctime1 write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Elapsed cpu time for main computation:' write ( *, '(2x,g14.6,a)' ) ctime, ' seconds' ! ! Free memory. ! deallocate ( acc ) deallocate ( force ) deallocate ( pos ) deallocate ( vel ) ! ! Terminate. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'MD:' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end subroutine compute ( np, nd, pos, vel, mass, f, pot, kin ) !*****************************************************************************80 ! !! COMPUTE computes the forces and energies. ! ! Discussion: ! ! The computation of forces and energies is fully parallel. ! ! The potential function V(X) is a harmonic well which smoothly ! saturates to a maximum value at PI/2: ! ! v(x) = ( sin ( min ( x, PI/2 ) ) )^2 ! ! The derivative of the potential is: ! ! dv(x) = 2.0D+00 * sin ( min ( x, PI/2 ) ) * cos ( min ( x, PI/2 ) ) ! = sin ( 2.0 * min ( x, PI/2 ) ) ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 15 July 2008 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer ( kind = 4 ) NP, the number of particles. ! ! Input, integer ( kind = 4 ) ND, the number of spatial dimensions. ! ! Input, real ( kind = 8 ) POS(ND,NP), the positions. ! ! Input, real ( kind = 8 ) VEL(ND,NP), the velocities. ! ! Input, real ( kind = 8 ) MASS, the mass. ! ! Output, real ( kind = 8 ) F(ND,NP), the forces. ! ! Output, real ( kind = 8 ) POT, the total potential energy. ! ! Output, real ( kind = 8 ) KIN, the total kinetic energy. ! implicit none integer ( kind = 4 ) np integer ( kind = 4 ) nd real ( kind = 8 ) d real ( kind = 8 ) d2 real ( kind = 8 ) f(nd,np) integer ( kind = 4 ) i integer ( kind = 4 ) j real ( kind = 8 ) kin real ( kind = 8 ) mass real ( kind = 8 ), parameter :: PI2 = 3.141592653589793D+00 / 2.0D+00 real ( kind = 8 ) pos(nd,np) real ( kind = 8 ) pot real ( kind = 8 ) rij(nd) real ( kind = 8 ) vel(nd,np) pot = 0.0D+00 do i = 1, np ! ! Compute the potential energy and forces. ! f(1:nd,i) = 0.0D+00 do j = 1, np if ( i /= j ) then rij(1:nd) = pos(1:nd,i) - pos(1:nd,j) d = sqrt ( sum ( rij(1:nd)**2 ) ) ! ! Truncate the distance. ! d2 = min ( d, PI2 ) ! ! Attribute half of the total potential energy to particle J. ! pot = pot + 0.5D+00 * sin ( d2 ) * sin ( d2 ) ! ! Add particle J's contribution to the force on particle I. ! f(1:nd,i) = f(1:nd,i) - rij(1:nd) * sin ( 2.0D+00 * d2 ) / d end if end do end do ! ! Compute the total kinetic energy. ! kin = 0.5D+00 * mass * sum ( vel(1:nd,1:np)**2 ) return end subroutine initialize ( np, nd, pos, vel, acc ) !*****************************************************************************80 ! !! INITIALIZE initializes the positions, velocities, and accelerations. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 26 December 2014 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer ( kind = 4 ) NP, the number of particles. ! ! Input, integer ( kind = 4 ) ND, the number of spatial dimensions. ! ! Output, real ( kind = 8 ) POS(ND,NP), the positions. ! ! Output, real ( kind = 8 ) VEL(ND,NP), the velocities. ! ! Output, real ( kind = 8 ) ACC(ND,NP), the accelerations. ! implicit none integer ( kind = 4 ) np integer ( kind = 4 ) nd real ( kind = 8 ) acc(nd,np) real ( kind = 8 ) pos(nd,np) integer ( kind = 4 ) seed real ( kind = 8 ) vel(nd,np) ! ! Set the positions. ! seed = 123456789 call r8mat_uniform_ab ( nd, np, 0.0D+00, 10.0D+00, seed, pos ) ! ! Set the velocities. ! vel(1:nd,1:np) = 0.0D+00 ! ! Set the accelerations. ! acc(1:nd,1:np) = 0.0D+00 return end subroutine r8mat_uniform_ab ( m, n, a, b, seed, r ) !*****************************************************************************80 ! !! R8MAT_UNIFORM_AB returns a scaled pseudorandom R8MAT. ! ! Discussion: ! ! A <= R(I,J) <= B. ! ! An R8MAT is an array of R8's. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 31 May 2007 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! Paul Bratley, Bennett Fox, Linus Schrage, ! A Guide to Simulation, ! Second Edition, ! Springer, 1987, ! ISBN: 0387964673, ! LC: QA76.9.C65.B73. ! ! Bennett Fox, ! Algorithm 647: ! Implementation and Relative Efficiency of Quasirandom ! Sequence Generators, ! ACM Transactions on Mathematical Software, ! Volume 12, Number 4, December 1986, pages 362-376. ! ! Pierre L'Ecuyer, ! Random Number Generation, ! in Handbook of Simulation, ! edited by Jerry Banks, ! Wiley, 1998, ! ISBN: 0471134031, ! LC: T57.62.H37. ! ! Peter Lewis, Allen Goodman, James Miller, ! A Pseudo-Random Number Generator for the System/360, ! IBM Systems Journal, ! Volume 8, Number 2, 1969, pages 136-143. ! ! Parameters: ! ! Input, integer ( kind = 4 ) M, N, the number of rows and columns ! in the array. ! ! Input, real ( kind = 8 ) A, B, the lower and upper limits. ! ! Input/output, integer ( kind = 4 ) SEED, the "seed" value, which ! should NOT be 0. On output, SEED has been updated. ! ! Output, real ( kind = 8 ) R(M,N), the array of pseudorandom values. ! implicit none integer ( kind = 4 ) m integer ( kind = 4 ) n real ( kind = 8 ) a real ( kind = 8 ) b integer ( kind = 4 ) i integer ( kind = 4 ), parameter :: i4_huge = 2147483647 integer ( kind = 4 ) j integer ( kind = 4 ) k integer ( kind = 4 ) seed real ( kind = 8 ) r(m,n) if ( seed == 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'R8MAT_UNIFORM_AB - Fatal error!' write ( *, '(a)' ) ' Input value of SEED = 0.' stop 1 end if do j = 1, n do i = 1, m k = seed / 127773 seed = 16807 * ( seed - k * 127773 ) - k * 2836 if ( seed < 0 ) then seed = seed + i4_huge end if r(i,j) = a + ( b - a ) * real ( seed, kind = 8 ) * 4.656612875D-10 end do end do return end subroutine s_to_i4 ( s, value, ierror, length ) !*****************************************************************************80 ! !! S_TO_I4 reads an integer value from a string. ! ! Discussion: ! ! Instead of ICHAR, we now use the IACHAR function, which ! guarantees the ASCII collating sequence. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 12 January 2009 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S, a string to be examined. ! ! Output, integer ( kind = 4 ) VALUE, the integer value read from the string. ! If the string is blank, then VALUE will be returned 0. ! ! Output, integer ( kind = 4 ) IERROR, an error flag. ! 0, no error. ! 1, an error occurred. ! ! Output, integer ( kind = 4 ) LENGTH, the number of characters ! of S used to make the integer. ! implicit none character c integer ( kind = 4 ) i integer ( kind = 4 ) ierror integer ( kind = 4 ) isgn integer ( kind = 4 ) length character ( len = * ) s integer ( kind = 4 ) state character :: TAB = achar ( 9 ) integer ( kind = 4 ) value value = 0 ierror = 0 length = 0 state = 0 isgn = 1 do i = 1, len_trim ( s ) c = s(i:i) ! ! STATE = 0, haven't read anything. ! if ( state == 0 ) then if ( c == ' ' .or. c == TAB ) then else if ( c == '-' ) then state = 1 isgn = -1 else if ( c == '+' ) then state = 1 isgn = +1 else if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then state = 2 value = iachar ( c ) - iachar ( '0' ) else ierror = 1 return end if ! ! STATE = 1, have read the sign, expecting digits or spaces. ! else if ( state == 1 ) then if ( c == ' ' .or. c == TAB ) then else if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then state = 2 value = iachar ( c ) - iachar ( '0' ) else ierror = 1 return end if ! ! STATE = 2, have read at least one digit, expecting more. ! else if ( state == 2 ) then if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then value = 10 * value + iachar ( c ) - iachar ( '0' ) else value = isgn * value ierror = 0 length = i - 1 return end if end if end do ! ! If we read all the characters in the string, see if we're OK. ! if ( state == 2 ) then value = isgn * value ierror = 0 length = len_trim ( s ) else value = 0 ierror = 1 length = 0 end if return end subroutine s_to_r8 ( s, r8 ) !*****************************************************************************80 ! !! S_TO_R8 reads an R8 value from a string. ! ! Discussion: ! ! An "R8" value is simply a real number to be stored as a ! variable of type "real ( kind = 8 )". ! ! The routine will read as many characters as possible until it reaches ! the end of the string, or encounters a character which cannot be ! part of the number. ! ! Legal input is: ! ! 1 blanks, ! 2 '+' or '-' sign, ! 2.5 blanks ! 3 integer part, ! 4 decimal point, ! 5 fraction part, ! 6 'E' or 'e' or 'D' or 'd', exponent marker, ! 7 exponent sign, ! 8 exponent integer part, ! 9 exponent decimal point, ! 10 exponent fraction part, ! 11 blanks, ! 12 final comma or semicolon, ! ! with most quantities optional. ! ! Example: ! ! S R8 ! ! '1' 1.0 ! ' 1 ' 1.0 ! '1A' 1.0 ! '12,34,56' 12.0 ! ' 34 7' 34.0 ! '-1E2ABCD' -100.0 ! '-1X2ABCD' -1.0 ! ' 2E-1' 0.2 ! '23.45' 23.45 ! '-4.2E+2' -420.0 ! '17d2' 1700.0 ! '-14e-2' -0.14 ! 'e2' 100.0 ! '-12.73e-9.23' -12.73 * 10.0^(-9.23) ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 06 January 2013 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S, the string containing the ! data to be read. Reading will begin at position 1 and ! terminate at the end of the string, or when no more ! characters can be read to form a legal real. Blanks, ! commas, or other nonnumeric data will, in particular, ! cause the conversion to halt. ! ! Output, real ( kind = 8 ) R8, the value read from the string. ! implicit none character c integer ( kind = 4 ) ierror integer ( kind = 4 ) ihave integer ( kind = 4 ) isgn integer ( kind = 4 ) iterm integer ( kind = 4 ) jbot integer ( kind = 4 ) jsgn integer ( kind = 4 ) jtop integer ( kind = 4 ) length integer ( kind = 4 ) ndig real ( kind = 8 ) r8 real ( kind = 8 ) rbot real ( kind = 8 ) rexp real ( kind = 8 ) rtop character ( len = * ) s integer ( kind = 4 ) s_length character :: TAB = achar ( 9 ) s_length = len_trim ( s ) ierror = 0 r8 = 0.0D+00 length = -1 isgn = 1 rtop = 0 rbot = 1 jsgn = 1 jtop = 0 jbot = 1 ihave = 1 iterm = 0 do length = length + 1 if ( s_length < length + 1 ) then exit end if c = s(length+1:length+1) ! ! Blank character. ! if ( c == ' ' .or. c == TAB ) then if ( ihave == 2 ) then else if ( ihave == 6 .or. ihave == 7 ) then iterm = 1 else if ( 1 < ihave ) then ihave = 11 end if ! ! Comma. ! else if ( c == ',' .or. c == ';' ) then if ( ihave /= 1 ) then iterm = 1 ihave = 12 length = length + 1 end if ! ! Minus sign. ! else if ( c == '-' ) then if ( ihave == 1 ) then ihave = 2 isgn = -1 else if ( ihave == 6 ) then ihave = 7 jsgn = -1 else iterm = 1 end if ! ! Plus sign. ! else if ( c == '+' ) then if ( ihave == 1 ) then ihave = 2 else if ( ihave == 6 ) then ihave = 7 else iterm = 1 end if ! ! Decimal point. ! else if ( c == '.' ) then if ( ihave < 4 ) then ihave = 4 else if ( 6 <= ihave .and. ihave <= 8 ) then ihave = 9 else iterm = 1 end if ! ! Scientific notation exponent marker. ! else if ( c == 'E' .or. c == 'e' .or. c == 'D' .or. c == 'd' ) then if ( ihave < 6 ) then ihave = 6 else iterm = 1 end if ! ! Digit. ! else if ( ihave < 11 .and. lle ( '0', c ) .and. lle ( c, '9' ) ) then if ( ihave <= 2 ) then ihave = 3 else if ( ihave == 4 ) then ihave = 5 else if ( ihave == 6 .or. ihave == 7 ) then ihave = 8 else if ( ihave == 9 ) then ihave = 10 end if ndig = iachar ( c ) - 48 if ( ihave == 3 ) then rtop = 10.0D+00 * rtop + real ( ndig, kind = 8 ) else if ( ihave == 5 ) then rtop = 10.0D+00 * rtop + real ( ndig, kind = 8 ) rbot = 10.0D+00 * rbot else if ( ihave == 8 ) then jtop = 10 * jtop + ndig else if ( ihave == 10 ) then jtop = 10 * jtop + ndig jbot = 10 * jbot end if ! ! Anything else is regarded as a terminator. ! else iterm = 1 end if ! ! If we haven't seen a terminator, and we haven't examined the ! entire string, go get the next character. ! if ( iterm == 1 ) then exit end if end do ! ! If we haven't seen a terminator, and we have examined the ! entire string, then we're done, and LENGTH is equal to S_LENGTH. ! if ( iterm /= 1 .and. length + 1 == s_length ) then length = s_length end if ! ! Number seems to have terminated. Have we got a legal number? ! Not if we terminated in states 1, 2, 6 or 7! ! if ( ihave == 1 .or. ihave == 2 .or. ihave == 6 .or. ihave == 7 ) then ierror = ihave write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'S_TO_R8 - Serious error!' write ( *, '(a)' ) ' Illegal or nonnumeric input:' write ( *, '(a)' ) ' "' // trim ( s ) // '"' stop 1 end if ! ! Number seems OK. Form it. ! if ( jtop == 0 ) then rexp = 1.0D+00 else if ( jbot == 1 ) then rexp = 10.0D+00 ** ( jsgn * jtop ) else rexp = 10.0D+00 ** ( real ( jsgn * jtop, kind = 8 ) & / real ( jbot, kind = 8 ) ) end if end if r8 = real ( isgn, kind = 8 ) * rexp * rtop / rbot return end subroutine timestamp ( ) !*****************************************************************************80 ! !! TIMESTAMP prints the current YMDHMS date as a time stamp. ! ! Example: ! ! 31 May 2001 9:45:54.872 AM ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 18 May 2013 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! None ! implicit none character ( len = 8 ) ampm integer ( kind = 4 ) d integer ( kind = 4 ) h integer ( kind = 4 ) m integer ( kind = 4 ) mm character ( len = 9 ), parameter, dimension(12) :: month = (/ & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' /) integer ( kind = 4 ) n integer ( kind = 4 ) s integer ( kind = 4 ) values(8) integer ( kind = 4 ) y call date_and_time ( values = values ) y = values(1) m = values(2) d = values(3) h = values(5) n = values(6) s = values(7) mm = values(8) if ( h < 12 ) then ampm = 'AM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h < 12 ) then ampm = 'PM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm ) return end subroutine update ( np, nd, pos, vel, f, acc, mass, dt ) !*****************************************************************************80 ! !! UPDATE updates positions, velocities and accelerations. ! ! Discussion: ! ! The time integration is fully parallel. ! ! A velocity Verlet algorithm is used for the updating. ! ! x(t+dt) = x(t) + v(t) * dt + 0.5 * a(t) * dt * dt ! v(t+dt) = v(t) + 0.5 * ( a(t) + a(t+dt) ) * dt ! a(t+dt) = f(t) / m ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 21 November 2007 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer ( kind = 4 ) NP, the number of particles. ! ! Input, integer ( kind = 4 ) ND, the number of spatial dimensions. ! ! Input/output, real ( kind = 8 ) POS(ND,NP), the positions. ! ! Input/output, real ( kind = 8 ) VEL(ND,NP), the velocities. ! ! Input, real ( kind = 8 ) F(ND,NP), the forces. ! ! Input/output, real ( kind = 8 ) ACC(ND,NP), the accelerations. ! ! Input, real ( kind = 8 ) MASS, the mass of each particle. ! ! Input, real ( kind = 8 ) DT, the time step. ! implicit none integer ( kind = 4 ) np integer ( kind = 4 ) nd real ( kind = 8 ) acc(nd,np) real ( kind = 8 ) dt real ( kind = 8 ) f(nd,np) integer ( kind = 4 ) i integer ( kind = 4 ) j real ( kind = 8 ) mass real ( kind = 8 ) pos(nd,np) real ( kind = 8 ) rmass real ( kind = 8 ) vel(nd,np) rmass = 1.0D+00 / mass do j = 1, np do i = 1, nd pos(i,j) = pos(i,j) + vel(i,j) * dt + 0.5D+00 * acc(i,j) * dt * dt vel(i,j) = vel(i,j) + 0.5D+00 * dt * ( f(i,j) * rmass + acc(i,j) ) acc(i,j) = f(i,j) * rmass end do end do return end