1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
|
program main
c*********************************************************************72
c
cc MAIN is the main program for MD_OPENMP.
c
c Discussion:
c
c The program implements a simple molecular dynamics simulation.
c
c The program uses Open MP directives to allow parallel computation.
c
c The velocity Verlet time integration scheme is used.
c
c The particles interact with a central pair potential.
c
c Output of the program is saved in the TNG format, which is why this
c code is included in the TNG API release.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 8 Jan 2013
c
c Author:
c
c Original FORTRAN90 version by Bill Magro.
c FORTRAN77 version by John Burkardt.
c TNG trajectory output by Magnus Lundborg.
c
c Parameters:
c
c None
c
implicit none
include 'omp_lib.h'
integer nd
parameter ( nd = 3 )
integer np
parameter ( np = 250 )
integer step_num
parameter ( step_num = 1000 )
double precision acc(nd,np)
double precision box(nd)
double precision box_shape(9)
double precision dt
parameter ( dt = 0.0001D+00 )
double precision e0
double precision force(nd,np)
integer i
integer id
double precision kinetic
double precision mass
parameter ( mass = 1.0D+00 )
double precision pos(nd,np)
double precision potential
integer proc_num
integer seed
integer step
integer step_print
integer step_print_index
integer step_print_num
integer step_save
integer*8 sparse_save
integer thread_num
double precision vel(nd,np)
double precision wtime
c
c Cray pointers are not standard fortran 77, but must be used to allocate
c memory properly.
c
pointer (traj_p, traj)
pointer (molecule_p, molecule)
pointer (chain_p, chain)
pointer (residue_p, residue)
pointer (atom_p, atom)
byte traj
byte molecule
byte chain
byte residue
byte atom
c
c The TNG functions expect 64 bit integers
c
integer*8 n_frames_per_frame_set
integer*8 frames_saved_cnt
integer*8 tng_n_particles
c
c These constants are also defined in tng_io.h, but need to
c set in fortran as well. This can be copied to any fortran
c source code using the tng_io library.
c
integer*8 TNG_UNCOMPRESSED
parameter ( TNG_UNCOMPRESSED = 0)
integer TNG_NON_TRAJECTORY_BLOCK
parameter ( TNG_NON_TRAJECTORY_BLOCK = 0)
integer TNG_TRAJECTORY_BLOCK
parameter ( TNG_TRAJECTORY_BLOCK = 1)
integer*8 TNG_GENERAL_INFO
parameter ( TNG_GENERAL_INFO = 0 )
integer*8 TNG_MOLECULES
parameter ( TNG_MOLECULES = 1 )
integer*8 TNG_TRAJECTORY_FRAME_SET
parameter ( TNG_TRAJECTORY_FRAME_SET = 2 )
integer*8 TNG_PARTICLE_MAPPING
parameter ( TNG_PARTICLE_MAPPING = 3 )
integer*8 TNG_TRAJ_BOX_SHAPE
parameter ( TNG_TRAJ_BOX_SHAPE = 10000 )
integer*8 TNG_TRAJ_POSITIONS
parameter ( TNG_TRAJ_POSITIONS = 10001 )
integer*8 TNG_TRAJ_VELOCITIES
parameter ( TNG_TRAJ_VELOCITIES = 10002 )
integer*8 TNG_TRAJ_FORCES
parameter ( TNG_TRAJ_FORCES = 10003 )
integer TNG_SKIP_HASH
parameter ( TNG_SKIP_HASH = 0 )
integer TNG_USE_HASH
parameter ( TNG_USE_HASH = 1 )
integer TNG_CHAR_DATA
parameter ( TNG_CHAR_DATA = 0 )
integer TNG_INT_DATA
parameter ( TNG_INT_DATA = 1 )
integer TNG_FLOAT_DATA
parameter ( TNG_FLOAT_DATA = 2 )
integer TNG_DOUBLE_DATA
parameter ( TNG_DOUBLE_DATA = 3 )
call timestamp ( )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'MD_OPENMP'
write ( *, '(a)' ) ' FORTRAN77/OpenMP version'
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' A molecular dynamics program.'
write ( *, '(a)' ) ' '
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
write ( *, '(a)' ) ' '
write ( *, '(a,i8)' )
& ' The number of processors = ', omp_get_num_procs ( )
write ( *, '(a,i8)' )
& ' The number of threads = ', omp_get_max_threads ( )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Initializing trajectory storage.'
call tng_trajectory_init(traj_p)
c
c N.B. The TNG output file should be modified according to needs
c
call tng_output_file_set(traj, TNG_EXAMPLE_FILES_DIR "tng_md_out_f77.tng")
write ( *, '(a)' ) ' Creating molecules in trajectory.'
tng_n_particles = np
call tng_molecule_add(traj, "water", molecule_p)
call tng_molecule_chain_add(traj, molecule, "W", chain_p)
call tng_chain_residue_add(traj, chain, "WAT", residue_p)
call tng_residue_atom_add(traj, residue, "O", "O", atom_p)
call tng_molecule_cnt_set(traj, molecule, tng_n_particles)
c
c Set the dimensions of the box.
c
do i = 1, 9
box_shape(i) = 0.0
end do
do i = 1, nd
box(i) = 10.0D+00
box_shape(i*nd + i) = box(i)
end do
c
c Add the box shape data block
c
call tng_data_block_add(traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE",
& TNG_DOUBLE_DATA, TNG_NON_TRAJECTORY_BLOCK, int(1, 8),
& int(9, 8), int(1, 8), TNG_UNCOMPRESSED, box_shape)
c
c Write the file headers
c
call tng_file_headers_write(traj, TNG_USE_HASH)
c
c Set initial positions, velocities, and accelerations.
c
write ( *, '(a)' )
& ' Initializing positions, velocities, and accelerations.'
seed = 123456789
call initialize ( np, nd, box, seed, pos, vel, acc )
c
c Compute the forces and energies.
c
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Computing initial forces and energies.'
call compute ( np, nd, pos, vel, mass, force, potential,
& kinetic )
e0 = potential + kinetic
c
c Saving frequency
c
step_save = 5
step_print = 0
step_print_index = 0
step_print_num = 10
sparse_save = 10
frames_saved_cnt = 0
c
c This is the main time stepping loop.
c
write ( *, '(a,i4,a)' ) ' Every', step_save,
& ' steps particle positions, velocities and forces are'
write ( *, '(a)' ) ' saved to a TNG trajectory file.'
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)' ) ' '
step = 0
write ( *, '(2x,i8,2x,g14.6,2x,g14.6,2x,g14.6)' )
& step, potential, kinetic, ( potential + kinetic - e0 ) / e0
step_print_index = step_print_index + 1
step_print = ( step_print_index * step_num ) / step_print_num
c
c Create a frame set for writing data
c
call tng_num_frames_per_frame_set_get(traj,
& n_frames_per_frame_set)
call tng_frame_set_new(traj, int(0, 8), n_frames_per_frame_set)
c
c Add empty data blocks.
c
call tng_particle_data_block_add(traj, TNG_TRAJ_POSITIONS,
& "POSITIONS", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK,
& n_frames_per_frame_set, int(3, 8), int(1, 8), int(0, 8),
& tng_n_particles, TNG_UNCOMPRESSED, %VAL(int(0, 8)))
call tng_particle_data_block_add(traj, TNG_TRAJ_VELOCITIES,
& "VELOCITIES", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK,
& n_frames_per_frame_set, int(3, 8), int(1, 8), int(0, 8),
& tng_n_particles, TNG_UNCOMPRESSED, %VAL(int(0, 8)))
call tng_particle_data_block_add(traj, TNG_TRAJ_FORCES,
& "FORCES", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK,
& n_frames_per_frame_set, int(3, 8), int(1, 8), int(0, 8),
& tng_n_particles, TNG_UNCOMPRESSED, %VAL(int(0, 8)))
c
c The potential energy data block is saved sparsely.
c
call tng_data_block_add(traj, int(10101, 8),
& "POTENTIAL ENERGY", TNG_DOUBLE_DATA, TNG_TRAJECTORY_BLOCK,
& n_frames_per_frame_set, int(1, 8), sparse_save,
& TNG_UNCOMPRESSED, %VAL(int(0, 8)))
c
c Write the frame set to disk
c
call tng_frame_set_write(traj, TNG_USE_HASH)
wtime = omp_get_wtime ( )
do step = 1, step_num
call compute ( np, nd, pos, vel, mass, force, potential,
& kinetic )
if ( step .eq. step_print ) then
write ( *, '(2x,i8,2x,g14.6,2x,g14.6,2x,g14.6)' )
& step, potential, kinetic, ( potential + kinetic - e0 ) / e0
step_print_index = step_print_index + 1
step_print = ( step_print_index * step_num ) / step_print_num
end if
c
c Output to TNG file at regular intervals, specified by step_save
c
if ( step_save .EQ. 0 .OR. mod(step, step_save) .EQ. 0 ) then
call tng_frame_particle_data_write(traj, frames_saved_cnt,
& TNG_TRAJ_POSITIONS, int(0, 8), tng_n_particles, pos,
& TNG_USE_HASH)
call tng_frame_particle_data_write(traj, frames_saved_cnt,
& TNG_TRAJ_VELOCITIES, int(0, 8), tng_n_particles, vel,
& TNG_USE_HASH)
call tng_frame_particle_data_write(traj, frames_saved_cnt,
& TNG_TRAJ_FORCES, int(0, 8), tng_n_particles, force,
& TNG_USE_HASH)
frames_saved_cnt = frames_saved_cnt + 1
if (mod(step, step_save * sparse_save) .EQ. 0) then
call tng_frame_data_write(traj, frames_saved_cnt,
& int(10101, 8), potential, TNG_USE_HASH)
end if
end if
call update ( np, nd, pos, vel, force, acc, mass, dt )
end do
wtime = omp_get_wtime ( ) - wtime
write ( *, '(a)' ) ' '
write ( *, '(a)' )
& ' Elapsed time for main computation:'
write ( *, '(2x,g14.6,a)' ) wtime, ' seconds'
c
c Terminate.
c
call tng_trajectory_destroy(traj_p)
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'MD_OPENMP'
write ( *, '(a)' ) ' Normal end of execution.'
write ( *, '(a)' ) ' '
call timestamp ( )
stop
end
subroutine compute ( np, nd, pos, vel, mass, f, pot, kin )
c*********************************************************************72
c
cc COMPUTE computes the forces and energies.
c
c Discussion:
c
c The computation of forces and energies is fully parallel.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 31 July 2009
c
c Author:
c
c Original FORTRAN90 version by Bill Magro.
c FORTRAN77 version by John Burkardt.
c
c Parameters:
c
c Input, integer NP, the number of particles.
c
c Input, integer ND, the number of spatial dimensions.
c
c Input, double precision POS(ND,NP), the position of each particle.
c
c Input, double precision VEL(ND,NP), the velocity of each particle.
c
c Input, double precision MASS, the mass of each particle.
c
implicit none
integer np
integer nd
double precision d
double precision d2
double precision dv
double precision f(nd,np)
integer i
integer j
integer k
double precision kin
double precision mass
double precision PI2
parameter ( PI2 = 3.141592653589793D+00 / 2.0D+00 )
double precision pos(nd,np)
double precision pot
double precision rij(nd)
double precision v
double precision vel(nd,np)
pot = 0.0D+00
kin = 0.0D+00
c$omp parallel
c$omp& shared ( f, nd, np, pos, vel )
c$omp& private ( d, d2, i, j, k, rij )
c$omp do reduction ( + : pot, kin )
do i = 1, np
c
c Compute the potential energy and forces.
c
do k = 1, nd
f(k,i) = 0.0D+00
end do
do j = 1, np
if ( i .ne. j ) then
call dist ( nd, pos(1,i), pos(1,j), rij, d )
c
c Attribute half of the potential energy to particle J.
c
d2 = min ( d, pi2 )
pot = pot + 0.5D+00 * ( sin ( d2 ) )**2
do k = 1, nd
f(k,i) = f(k,i) - rij(k) * sin ( 2.0D+00 * d2 ) / d
end do
end if
end do
c
c Compute the kinetic energy.
c
do k = 1, nd
kin = kin + vel(k,i)**2
end do
end do
c$omp end do
c$omp end parallel
kin = kin * 0.5D+00 * mass
return
end
subroutine dist ( nd, r1, r2, dr, d )
c*********************************************************************72
c
cc DIST computes the displacement (and its norm) between two particles.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 13 November 2007
c
c Author:
c
c Original FORTRAN90 version by Bill Magro.
c FORTRAN77 version by John Burkardt.
c
c Parameters:
c
c Input, integer ND, the number of spatial dimensions.
c
c Input, double precision R1(ND), R2(ND), the positions of the particles.
c
c Output, double precision DR(ND), the displacement vector.
c
c Output, double precision D, the Euclidean norm of the displacement.
c
implicit none
integer nd
double precision d
double precision dr(nd)
integer i
double precision r1(nd)
double precision r2(nd)
do i = 1, nd
dr(i) = r1(i) - r2(i)
end do
d = 0.0D+00
do i = 1, nd
d = d + dr(i)**2
end do
d = sqrt ( d )
return
end
subroutine initialize ( np, nd, box, seed, pos, vel, acc )
c*********************************************************************72
c
cc INITIALIZE initializes the positions, velocities, and accelerations.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 13 November 2007
c
c Author:
c
c Original FORTRAN90 version by Bill Magro.
c FORTRAN77 version by John Burkardt.
c
c Parameters:
c
c Input, integer NP, the number of particles.
c
c Input, integer ND, the number of spatial dimensions.
c
c Input, double precision BOX(ND), specifies the maximum position
c of particles in each dimension.
c
c Input/output, integer SEED, a seed for the random number generator.
c
c Output, double precision POS(ND,NP), the position of each particle.
c
c Output, double precision VEL(ND,NP), the velocity of each particle.
c
c Output, double precision ACC(ND,NP), the acceleration of each particle.
c
implicit none
integer np
integer nd
double precision acc(nd,np)
double precision box(nd)
integer i
integer j
double precision pos(nd,np)
double precision r8_uniform_01
integer seed
double precision vel(nd,np)
c
c Give the particles random positions within the box.
c
do i = 1, nd
do j = 1, np
pos(i,j) = r8_uniform_01 ( seed )
end do
end do
c$omp parallel
c$omp& shared ( acc, box, nd, np, pos, vel )
c$omp& private ( i, j )
c$omp do
do j = 1, np
do i = 1, nd
pos(i,j) = box(i) * pos(i,j)
vel(i,j) = 0.0D+00
acc(i,j) = 0.0D+00
end do
end do
c$omp end do
c$omp end parallel
return
end
function r8_uniform_01 ( seed )
c*********************************************************************72
c
cc R8_UNIFORM_01 returns a unit pseudorandom R8.
c
c Discussion:
c
c This routine implements the recursion
c
c seed = 16807 * seed mod ( 2**31 - 1 )
c r8_uniform_01 = seed / ( 2**31 - 1 )
c
c The integer arithmetic never requires more than 32 bits,
c including a sign bit.
c
c If the initial seed is 12345, then the first three computations are
c
c Input Output R8_UNIFORM_01
c SEED SEED
c
c 12345 207482415 0.096616
c 207482415 1790989824 0.833995
c 1790989824 2035175616 0.947702
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 11 August 2004
c
c Author:
c
c John Burkardt
c
c Reference:
c
c Paul Bratley, Bennett Fox, Linus Schrage,
c A Guide to Simulation,
c Springer Verlag, pages 201-202, 1983.
c
c Pierre L'Ecuyer,
c Random Number Generation,
c in Handbook of Simulation,
c edited by Jerry Banks,
c Wiley Interscience, page 95, 1998.
c
c Bennett Fox,
c Algorithm 647:
c Implementation and Relative Efficiency of Quasirandom
c Sequence Generators,
c ACM Transactions on Mathematical Software,
c Volume 12, Number 4, pages 362-376, 1986.
c
c Peter Lewis, Allen Goodman, James Miller,
c A Pseudo-Random Number Generator for the System/360,
c IBM Systems Journal,
c Volume 8, pages 136-143, 1969.
c
c Parameters:
c
c Input/output, integer SEED, the "seed" value, which should NOT be 0.
c On output, SEED has been updated.
c
c Output, double precision R8_UNIFORM_01, a new pseudorandom variate,
c strictly between 0 and 1.
c
implicit none
double precision r8_uniform_01
integer k
integer seed
if ( seed .eq. 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'R8_UNIFORM_01 - Fatal error!'
write ( *, '(a)' ) ' Input value of SEED = 0.'
stop
end if
k = seed / 127773
seed = 16807 * ( seed - k * 127773 ) - k * 2836
if ( seed .lt. 0 ) then
seed = seed + 2147483647
end if
c
c Although SEED can be represented exactly as a 32 bit integer,
c it generally cannot be represented exactly as a 32 bit real number!
c
r8_uniform_01 = dble ( seed ) * 4.656612875D-10
return
end
subroutine timestamp ( )
c*********************************************************************72
c
cc TIMESTAMP prints out the current YMDHMS date as a timestamp.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 12 January 2007
c
c Author:
c
c John Burkardt
c
c Parameters:
c
c None
c
implicit none
character * ( 8 ) ampm
integer d
character * ( 8 ) date
integer h
integer m
integer mm
character * ( 9 ) month(12)
integer n
integer s
character * ( 10 ) time
integer y
save month
data month /
& 'January ', 'February ', 'March ', 'April ',
& 'May ', 'June ', 'July ', 'August ',
& 'September', 'October ', 'November ', 'December ' /
call date_and_time ( date, time )
read ( date, '(i4,i2,i2)' ) y, m, d
read ( time, '(i2,i2,i2,1x,i3)' ) h, n, s, mm
if ( h .lt. 12 ) then
ampm = 'AM'
else if ( h .eq. 12 ) then
if ( n .eq. 0 .and. s .eq. 0 ) then
ampm = 'Noon'
else
ampm = 'PM'
end if
else
h = h - 12
if ( h .lt. 12 ) then
ampm = 'PM'
else if ( h .eq. 12 ) then
if ( n .eq. 0 .and. s .eq. 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, month(m), y, h, ':', n, ':', s, '.', mm, ampm
return
end
subroutine update ( np, nd, pos, vel, f, acc, mass, dt )
c*********************************************************************72
c
cc UPDATE performs the time integration, using a velocity Verlet algorithm.
c
c Discussion:
c
c The time integration is fully parallel.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 13 November 2007
c
c Author:
c
c Original FORTRAN90 version by Bill Magro.
c FORTRAN77 version by John Burkardt.
c
c Parameters:
c
c Input, integer NP, the number of particles.
c
c Input, integer ND, the number of spatial dimensions.
c
c Input/output, double precision POS(ND,NP), the position of each particle.
c
c Input/output, double precision VEL(ND,NP), the velocity of each particle.
c
c Input, double precision MASS, the mass of each particle.
c
c Input/output, double precision ACC(ND,NP), the acceleration of each
c particle.
c
implicit none
integer np
integer nd
double precision acc(nd,np)
double precision dt
double precision f(nd,np)
integer i
integer j
double precision mass
double precision pos(nd,np)
double precision rmass
double precision vel(nd,np)
rmass = 1.0D+00 / mass
c$omp parallel
c$omp& shared ( acc, dt, f, nd, np, pos, rmass, vel )
c$omp& private ( i, j )
c$omp do
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
c$omp end do
c$omp end parallel
return
end
|