Newer
Older
/*----------------------------------------------------------------------
SerialReax - Reax Force Field Simulator
Copyright (2010) Purdue University
Hasan Metin Aktulga, haktulga@cs.purdue.edu
Joseph Fogarty, jcfogart@mail.usf.edu
Sagar Pandit, pandit@usf.edu
Ananth Y Grama, ayg@cs.purdue.edu
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
See the GNU General Public License for more details:
<http://www.gnu.org/licenses/>.
----------------------------------------------------------------------*/
#include "mytypes.h"
Kurt A. O'Hearn
committed
#include "control.h"
#include "ffield.h"
#include "forces.h"
#include "init_md.h"
#include "neighbors.h"
Kurt A. O'Hearn
committed
#include "geo_tools.h"
#include "print_utils.h"
#include "reset_utils.h"
#include "restart.h"
#include "system_props.h"
#include "tool_box.h"
Kurt A. O'Hearn
committed
static static_storage workspace;
static reax_list *lists;
static output_controls out_control;
static void Post_Evolve( reax_system * const system, control_params * const control,
simulation_data * const data, static_storage * const workspace,
Kurt A. O'Hearn
committed
reax_list ** const lists, output_controls * const out_control )
int i;
rvec diff, cross;
/* if velocity dependent force then
{
Generate_Neighbor_Lists( &system, &control, &lists );
Kurt A. O'Hearn
committed
Compute_Charges(system, control, workspace, lists[FAR_NBRS]);
Introduce compute_force here if we are using velocity dependent forces
Compute_Forces(system,control,data,workspace,lists);
} */
/* compute kinetic energy of the system */
Compute_Kinetic_Energy( system, data );
/* remove rotational and translational velocity of the center of mass */
if ( control->ensemble != NVE &&
control->remove_CoM_vel &&
data->step && data->step % control->remove_CoM_vel == 0 )
{
/* compute velocity of the center of mass */
Compute_Center_of_Mass( system, data, out_control->prs );
for ( i = 0; i < system->N; i++ )
{
// remove translational
rvec_ScaledAdd( system->atoms[i].v, -1., data->vcm );
// remove rotational
rvec_ScaledSum( diff, 1., system->atoms[i].x, -1., data->xcm );
rvec_Cross( cross, data->avcm, diff );
rvec_ScaledAdd( system->atoms[i].v, -1., cross );
}
Kurt A. O'Hearn
committed
void static Read_System( char * const geo_file,
char * const ffield_file,
char * const control_file,
reax_system * const system,
control_params * const control,
simulation_data * const data,
static_storage * const workspace,
output_controls * const out_control )
Kurt A. O'Hearn
committed
if ( (ffield = fopen( ffield_file, "r" )) == NULL )
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] Error opening the ffield file!\n" );
fprintf( stderr, " [INFO] (%s)\n", ffield_file );
Kurt A. O'Hearn
committed
exit( FILE_NOT_FOUND );
Kurt A. O'Hearn
committed
if ( (ctrl = fopen( control_file, "r" )) == NULL )
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] Error opening the ffield file!\n" );
fprintf( stderr, " [INFO] (%s)\n", control_file );
Kurt A. O'Hearn
committed
exit( FILE_NOT_FOUND );
}
/* ffield file */
Read_Force_Field( ffield, &(system->reaxprm) );
/* control file */
Read_Control_File( ctrl, system, control, out_control );
/* geo file */
Kurt A. O'Hearn
committed
if ( control->geo_format == CUSTOM )
Kurt A. O'Hearn
committed
Read_Geo( geo_file, system, control, data, workspace );
Kurt A. O'Hearn
committed
{
Read_PDB( geo_file, system, control, data, workspace );
}
Kurt A. O'Hearn
committed
{
Read_BGF( geo_file, system, control, data, workspace );
}
Kurt A. O'Hearn
committed
Read_ASCII_Restart( geo_file, system, control, data, workspace );
control->restart = 1;
}
else if ( control->geo_format == BINARY_RESTART )
{
Kurt A. O'Hearn
committed
Read_Binary_Restart( geo_file, system, control, data, workspace );
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] unknown geo file format. terminating!\n" );
Kurt A. O'Hearn
committed
exit( INVALID_GEO );
Kurt A. O'Hearn
committed
fclose( ffield );
fclose( ctrl );
Kurt A. O'Hearn
committed
Print_Box( &(system->box), stderr );
Kurt A. O'Hearn
committed
int Setup( char ** args, reax_system * const system, control_params * const control,
simulation_data * const data )
lists = (reax_list*) smalloc( sizeof(reax_list) * LIST_N,
"Setup::lists" );
Kurt A. O'Hearn
committed
Read_System( args[0], args[1], args[2], system, control,
data, &workspace, &out_control );
return SUCCESS;
Kurt A. O'Hearn
committed
int Run( reax_system * const system, control_params * const control, simulation_data * const data,
const int output_enabled )
Kurt A. O'Hearn
committed
evolve_function Evolve;
Kurt A. O'Hearn
committed
Initialize( system, control, data, &workspace, &lists,
&out_control, &Evolve, output_enabled );
Kurt A. O'Hearn
committed
Reset( system, control, data, &workspace, &lists );
Generate_Neighbor_Lists( system, control, data, &workspace,
Kurt A. O'Hearn
committed
&lists, &out_control );
//fprintf( stderr, "total: %.2f secs\n", data.timing.nbrs);
Kurt A. O'Hearn
committed
Compute_Forces( system, control, data, &workspace, &lists, &out_control );
Compute_Kinetic_Energy( system, data );
if ( output_enabled == TRUE )
{
Output_Results( system, control, data, &workspace, &lists, &out_control );
}
++data->step;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
for ( ; data->step <= control->nsteps; data->step++ )
Kurt A. O'Hearn
committed
if ( control->T_mode )
{
Temperature_Control( control, data, &out_control );
}
Evolve( system, control, data, &workspace, &lists, &out_control );
Post_Evolve( system, control, data, &workspace, &lists, &out_control );
if ( output_enabled == TRUE )
{
Kurt A. O'Hearn
committed
Output_Results( system, control, data, &workspace, &lists, &out_control );
Analysis( system, control, data, &workspace, &lists, &out_control );
}
Kurt A. O'Hearn
committed
steps = data->step - data->prev_steps;
Kurt A. O'Hearn
committed
steps % out_control.restart_freq == 0 &&
output_enabled == TRUE )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
Write_Restart( system, control, data, &workspace, &out_control );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
if ( out_control.write_steps > 0 && output_enabled == TRUE )
Kurt A. O'Hearn
committed
Write_PDB( system, &(lists[BONDS]), data, control, &workspace, &out_control );
Kurt A. O'Hearn
committed
data->timing.end = Get_Time( );
data->timing.elapsed = Get_Timing_Info( data->timing.start );
if ( output_enabled == TRUE )
{
fprintf( out_control.log, "total: %.2f secs\n", data->timing.elapsed );
}
return SUCCESS;
}
Kurt A. O'Hearn
committed
int Cleanup( reax_system * const system, control_params * const control,
simulation_data * const data, const int output_enabled )
{
Finalize( system, control, data, &workspace, &lists, &out_control,
output_enabled );
Kurt A. O'Hearn
committed
sfree( lists, "main::lists" );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
return SUCCESS;