[Swift-commit] r8130 - SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Wed Aug 13 11:23:58 CDT 2014
Author: wozniak
Date: 2014-08-13 11:23:58 -0500 (Wed, 13 Aug 2014)
New Revision: 8130
Modified:
SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c
SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c
SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h
Log:
Split out new function simulate()
Modified: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c 2014-08-13 16:23:07 UTC (rev 8129)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/main.c 2014-08-13 16:23:58 UTC (rev 8130)
@@ -86,8 +86,8 @@
int step;
int step_num;
int step_print;
- int step_print_index;
- int step_print_num=10;
+ int step_print_index = 0;
+ int step_print_num = 10;
double *vel;
timestamp ( );
@@ -239,10 +239,6 @@
FILE *ofile = fopen(outfile,"w");
fprintf (ofile, " Step Potential Kinetic RelativeErr\n" );
- step_print = 0;
- step_print_index = 0;
-
- step = 0;
printf ( " %8d %14f %14f %14e\n",
step, potential, kinetic, ( potential + kinetic - e0 ) / e0 );
fprintf ( ofile, " %8d %14f %14f %14e\n",
@@ -252,22 +248,13 @@
ctime1 = cpu_time ( );
- for ( step = 1; step <= step_num; step++ )
- {
- compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
+ simulate (step_num, step_print_num, step_print, step_print_index,
+ np, nd, pos, vel,
+ mass, force, acc,
+ potential, kinetic, e0,
+ dt,
+ ofile);
- if ( step == step_print )
- {
- printf ( " %8d %14f %14f %14e\n", step, potential, kinetic,
- ( potential + kinetic - e0 ) / e0 );
- fprintf ( ofile, " %8d %14f %14f %14e\n", step, potential, kinetic,
- ( potential + kinetic - e0 ) / e0 );
- step_print_index = step_print_index + 1;
- step_print = ( step_print_index * step_num ) / step_print_num;
- snap ( np, nd, pos, vel, force, acc, mass, dt );
- }
- update ( np, nd, pos, vel, force, acc, mass, dt );
- }
ctime2 = cpu_time ( );
ctime = ctime2 - ctime1;
Modified: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c 2014-08-13 16:23:07 UTC (rev 8129)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.c 2014-08-13 16:23:58 UTC (rev 8130)
@@ -5,22 +5,44 @@
#include "md.h"
-void compute ( int np, int nd, double pos[], double vel[],
- double mass, double f[], double *pot, double *kin );
-double cpu_time ( void );
+double scale_factor = 2.5, scale_offset = -2.0;
+char *printinfo = "0.05 1.0 0.2 0.05 50.0 0.1";
+
+
double dist ( int nd, double r1[], double r2[], double dr[] );
-void initialize ( int np, int nd, double box[], int *seed, double pos[],
- double vel[], double acc[] );
+
double r8_uniform_01 ( int *seed );
-void timestamp ( void );
-void update ( int np, int nd, double pos[], double vel[], double f[],
+void update ( int np, int nd, double pos[], double vel[], double f[],
double acc[], double mass, double dt );
-void snap ( int np, int nd, double pos[], double vel[], double f[],
+void snap ( int np, int nd, double pos[], double vel[], double f[],
double acc[], double mass, double dt );
-double scale_factor = 2.5, scale_offset = -2.0;
-char *printinfo = "0.05 1.0 0.2 0.05 50.0 0.1";
+void simulate (int step_num, int step_print_num,
+ int step_print, int step_print_index,
+ int np, int nd, double pos[], double vel[],
+ double mass, double force[], double acc[],
+ double potential, double kinetic, double e0,
+ double dt,
+ FILE* ofile)
+{
+ for (int step = 1; step <= step_num; step++ )
+ {
+ compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
+ if ( step == step_print )
+ {
+ printf ( " %8d %14f %14f %14e\n", step, potential, kinetic,
+ ( potential + kinetic - e0 ) / e0 );
+ fprintf ( ofile, " %8d %14f %14f %14e\n", step, potential, kinetic,
+ ( potential + kinetic - e0 ) / e0 );
+ step_print_index = step_print_index + 1;
+ step_print = ( step_print_index * step_num ) / step_print_num;
+ snap ( np, nd, pos, vel, force, acc, mass, dt );
+ }
+ update ( np, nd, pos, vel, force, acc, mass, dt );
+ }
+}
+
/******************************************************************************/
void compute ( int np, int nd, double pos[], double vel[],
Modified: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h 2014-08-13 16:23:07 UTC (rev 8129)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/05-md/md.h 2014-08-13 16:23:58 UTC (rev 8130)
@@ -11,4 +11,22 @@
extern double scale_factor, scale_offset;
extern char *printinfo;
+double cpu_time ( void );
+
+void timestamp ( void );
+
+void initialize ( int np, int nd, double box[], int *seed, double pos[],
+ double vel[], double acc[] );
+
+void compute ( int np, int nd, double pos[], double vel[],
+ double mass, double f[], double *pot, double *kin );
+
+void simulate (int step_num, int step_print_num,
+ int step_print, int step_print_index,
+ int np, int nd, double pos[], double vel[],
+ double mass, double force[], double acc[],
+ double potential, double kinetic, double e0,
+ double dt,
+ FILE* ofile);
+
#endif
More information about the Swift-commit
mailing list