summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMagnus Lundborg <lundborg.magnus@gmail.com>2013-05-24 12:27:02 (GMT)
committerMagnus Lundborg <lundborg.magnus@gmail.com>2013-05-24 12:27:02 (GMT)
commit6380d1a869ee1c29d9b1ab2aa2ff403f3fbed14b (patch)
treef7501191b9ee3725bcfbfd19c4ce7f438a1540cf /src/tests
parentf043e57811aed313b0de3fd3aa4f6df734156191 (diff)
Improved utility functions. Bug fixes.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/md_openmp.c38
-rw-r--r--src/tests/md_openmp_util.c67
-rw-r--r--src/tests/tng_io_read_pos_util.c9
3 files changed, 93 insertions, 21 deletions
diff --git a/src/tests/md_openmp.c b/src/tests/md_openmp.c
index 108beb6..2314e6f 100644
--- a/src/tests/md_openmp.c
+++ b/src/tests/md_openmp.c
@@ -240,7 +240,7 @@ int main ( int argc, char *argv[] )
TNG_TRAJECTORY_BLOCK,
n_frames_per_frame_set, 3,
1, 0, np,
- TNG_TNG_COMPRESSION,
+ TNG_UNCOMPRESSED,
0) != TNG_SUCCESS)
{
printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
@@ -252,7 +252,7 @@ int main ( int argc, char *argv[] )
TNG_TRAJECTORY_BLOCK,
n_frames_per_frame_set, 3,
1, 0, np,
- TNG_TNG_COMPRESSION,
+ TNG_UNCOMPRESSED,
0) != TNG_SUCCESS)
{
printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
@@ -294,7 +294,39 @@ int main ( int argc, char *argv[] )
wtime = omp_get_wtime ( );
- for ( step = 1; step <= step_num; step++ )
+ if(tng_frame_particle_data_write(traj, frames_saved_cnt,
+ TNG_TRAJ_POSITIONS, 0, np,
+ pos, TNG_USE_HASH) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
+ if(tng_frame_particle_data_write(traj, frames_saved_cnt,
+ TNG_TRAJ_VELOCITIES, 0, np,
+ vel, TNG_USE_HASH) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
+ if(tng_frame_particle_data_write(traj, frames_saved_cnt,
+ TNG_TRAJ_FORCES, 0, np,
+ force, TNG_USE_HASH) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
+ if(step % (step_save * sparse_save) == 0)
+ {
+ if(tng_frame_data_write(traj, frames_saved_cnt, 10101, &potential,
+ TNG_USE_HASH) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
+ }
+ frames_saved_cnt++;
+
+ for ( step = 1; step < step_num; step++ )
{
compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
diff --git a/src/tests/md_openmp_util.c b/src/tests/md_openmp_util.c
index 6a2f377..99ab60e 100644
--- a/src/tests/md_openmp_util.c
+++ b/src/tests/md_openmp_util.c
@@ -155,17 +155,17 @@ int main ( int argc, char *argv[] )
/* Add the box shape data block and write the file headers */
- if(tng_data_block_add(traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", TNG_DOUBLE_DATA,
- TNG_NON_TRAJECTORY_BLOCK, 1, 9, 1, TNG_UNCOMPRESSED,
- box_shape) == TNG_CRITICAL ||
- tng_file_headers_write(traj, TNG_USE_HASH) == TNG_CRITICAL)
- {
- free(box_shape);
- tng_util_trajectory_close(&traj);
- printf(" Cannot write trajectory headers and box shape.\n");
- exit(1);
- }
- free(box_shape);
+// if(tng_data_block_add(traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", TNG_DOUBLE_DATA,
+// TNG_NON_TRAJECTORY_BLOCK, 1, 9, 1, TNG_UNCOMPRESSED,
+// box_shape) == TNG_CRITICAL ||
+// tng_file_headers_write(traj, TNG_USE_HASH) == TNG_CRITICAL)
+// {
+// free(box_shape);
+// tng_util_trajectory_close(&traj);
+// printf(" Cannot write trajectory headers and box shape.\n");
+// exit(1);
+// }
+// free(box_shape);
printf ( "\n" );
printf ( " Initializing positions, velocities, and accelerations.\n" );
@@ -184,11 +184,11 @@ int main ( int argc, char *argv[] )
e0 = potential + kinetic;
/* Saving frequency */
- step_save = 100;
+ step_save = 400;
step_print = 0;
step_print_index = 0;
- step_print_num = 10;
+ step_print_num = 100;
/*
This is the main time stepping loop:
@@ -214,15 +214,44 @@ int main ( int argc, char *argv[] )
step_print_index++;
step_print = ( step_print_index * step_num ) / step_print_num;
+ if(tng_util_pos_write_frequency_set(traj, step_save) != TNG_SUCCESS)
+ {
+ printf("Error setting writing frequency data. %s: %d\n",
+ __FILE__, __LINE__);
+ exit(1);
+ }
+ if(tng_util_vel_write_frequency_set(traj, step_save) != TNG_SUCCESS)
+ {
+ printf("Error setting writing frequency data. %s: %d\n",
+ __FILE__, __LINE__);
+ exit(1);
+ }
+ if(tng_util_force_write_frequency_set(traj, step_save) != TNG_SUCCESS)
+ {
+ printf("Error setting writing frequency data. %s: %d\n",
+ __FILE__, __LINE__);
+ exit(1);
+ }
+
if(tng_util_pos_write(traj, 0, pos) != TNG_SUCCESS)
{
printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
exit(1);
}
+ if(tng_util_vel_write(traj, 0, vel) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
+ if(tng_util_force_write(traj, 0, force) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
wtime = omp_get_wtime ( );
- for ( step = 1; step <= step_num; step++ )
+ for ( step = 1; step < step_num; step++ )
{
compute ( np, nd, pos, vel, mass, force, &potential, &kinetic );
@@ -240,6 +269,16 @@ int main ( int argc, char *argv[] )
printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
exit(1);
}
+ if(tng_util_vel_write(traj, step, vel) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
+ if(tng_util_force_write(traj, step, force) != TNG_SUCCESS)
+ {
+ printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
+ exit(1);
+ }
}
update ( np, nd, pos, vel, force, acc, mass, dt );
}
diff --git a/src/tests/tng_io_read_pos_util.c b/src/tests/tng_io_read_pos_util.c
index 12bf2ed..322f4a4 100644
--- a/src/tests/tng_io_read_pos_util.c
+++ b/src/tests/tng_io_read_pos_util.c
@@ -22,8 +22,9 @@
int main(int argc, char **argv)
{
tng_trajectory_t traj;
- float *positions = 0; // A 1-dimensional array
- // to be populated
+ /* Assume that the data is stored as floats. The data is placed in 1-D
+ * arrays */
+ float *positions = 0, *velocities = 0, *forces = 0;
int64_t n_particles, n_frames, tot_n_frames, stride_length, i, j;
// Set a default frame range
int64_t first_frame = 0, last_frame = 5000;
@@ -41,7 +42,7 @@ int main(int argc, char **argv)
// A reference must be passed to allocate memory
tng_util_trajectory_open(argv[1], 'r', &traj);
-
+
if(argc >= 3)
{
first_frame = strtoll(argv[2], 0, 10);
@@ -64,7 +65,7 @@ int main(int argc, char **argv)
tng_util_trajectory_close(&traj);
exit(1);
}
-
+
printf("%"PRId64" frames in file\n", tot_n_frames);
if(last_frame > tot_n_frames - 1)
contact: Jan Huwald // Impressum