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 "forces.h"
#include "charges.h"
#include "four_body_interactions.h"
#include "list.h"
#include "system_props.h"
#include "single_body_interactions.h"
#include "three_body_interactions.h"
#include "tool_box.h"
#include "two_body_interactions.h"
Kurt A. O'Hearn
committed
typedef enum
{
DIAGONAL = 0,
OFF_DIAGONAL = 1,
} MATRIX_ENTRY_POSITION;
Kurt A. O'Hearn
committed
static void Dummy_Interaction( reax_system *system, control_params *control,
Kurt A. O'Hearn
committed
simulation_data *data, static_storage *workspace,
Kurt A. O'Hearn
committed
reax_list **lists, output_controls *out_control )
Kurt A. O'Hearn
committed
void Init_Bonded_Force_Functions( control_params *control,
interaction_function *interaction_functions )
Kurt A. O'Hearn
committed
interaction_functions[0] = Calculate_Bond_Orders;
interaction_functions[1] = Bond_Energy; //*/Dummy_Interaction;
interaction_functions[2] = LonePair_OverUnder_Coordination_Energy;
Kurt A. O'Hearn
committed
interaction_functions[3] = Three_Body_Interactions; //*/Dummy_Interaction;
interaction_functions[4] = Four_Body_Interactions; //*/Dummy_Interaction;
Kurt A. O'Hearn
committed
if ( control->hb_cut > 0.0 )
{
Kurt A. O'Hearn
committed
interaction_functions[5] = Hydrogen_Bonds; //*/Dummy_Interaction;
Kurt A. O'Hearn
committed
}
else
{
Kurt A. O'Hearn
committed
interaction_functions[5] = Dummy_Interaction;
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
interaction_functions[6] = Dummy_Interaction; //empty
interaction_functions[7] = Dummy_Interaction; //empty
interaction_functions[8] = Dummy_Interaction; //empty
interaction_functions[9] = Dummy_Interaction; //empty
Kurt A. O'Hearn
committed
static void Compute_Bonded_Forces( reax_system *system, control_params *control,
Kurt A. O'Hearn
committed
simulation_data *data, static_storage *workspace, reax_list **lists,
output_controls *out_control, interaction_function *interaction_functions )
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
/* Mark beginning of a new timestep in each energy file */
fprintf( out_control->ebond, "step: %d\n%6s%6s%12s%12s%12s\n",
data->step, "atom1", "atom2", "bo", "ebond", "total" );
fprintf( out_control->elp, "step: %d\n%6s%12s%12s%12s\n",
data->step, "atom", "nlp", "elp", "total" );
fprintf( out_control->eov, "step: %d\n%6s%12s%12s\n",
data->step, "atom", "eov", "total" );
fprintf( out_control->eun, "step: %d\n%6s%12s%12s\n",
data->step, "atom", "eun", "total" );
fprintf( out_control->eval, "step: %d\n%6s%6s%6s%12s%12s%12s%12s%12s%12s\n",
data->step, "atom1", "atom2", "atom3",
"angle", "bo(12)", "bo(23)", "eval", "epen", "total" );
fprintf( out_control->epen, "step: %d\n%6s%6s%6s%12s%12s%12s%12s%12s\n",
data->step, "atom1", "atom2", "atom3",
"angle", "bo(12)", "bo(23)", "epen", "total" );
fprintf( out_control->ecoa, "step: %d\n%6s%6s%6s%12s%12s%12s%12s%12s\n",
data->step, "atom1", "atom2", "atom3",
"angle", "bo(12)", "bo(23)", "ecoa", "total" );
fprintf( out_control->ehb, "step: %d\n%6s%6s%6s%12s%12s%12s%12s%12s\n",
data->step, "atom1", "atom2", "atom3",
"r(23)", "angle", "bo(12)", "ehb", "total" );
fprintf( out_control->etor, "step: %d\n%6s%6s%6s%6s%12s%12s%12s%12s\n",
data->step, "atom1", "atom2", "atom3", "atom4",
"phi", "bo(23)", "etor", "total" );
fprintf( out_control->econ, "step:%d\n%6s%6s%6s%6s%12s%12s%12s%12s%12s%12s\n",
data->step, "atom1", "atom2", "atom3", "atom4",
"phi", "bo(12)", "bo(23)", "bo(34)", "econ", "total" );
#endif
/* Implement all the function calls as function pointers */
for ( i = 0; i < NO_OF_INTERACTIONS; i++ )
{
Kurt A. O'Hearn
committed
(interaction_functions[i])( system, control, data, workspace,
Kurt A. O'Hearn
committed
lists, out_control );
(Print_Interactions[i])(system, control, data, workspace,
lists, out_control);
Kurt A. O'Hearn
committed
static void Compute_NonBonded_Forces( reax_system *system, control_params *control,
Kurt A. O'Hearn
committed
simulation_data *data, static_storage *workspace,
Kurt A. O'Hearn
committed
reax_list** lists, output_controls *out_control )
Kurt A. O'Hearn
committed
fprintf( out_control->evdw, "step: %d\n%6s%6s%12s%12s%12s\n",
data->step, "atom1", "atom2", "r12", "evdw", "total" );
fprintf( out_control->ecou, "step: %d\n%6s%6s%12s%12s%12s%12s%12s\n",
data->step, "atom1", "atom2", "r12", "q1", "q2", "ecou", "total" );
Compute_Charges( system, control, data, workspace, out_control );
Kurt A. O'Hearn
committed
data->timing.cm += t_elapsed;
Kurt A. O'Hearn
committed
if ( control->tabulate <= 0 )
{
vdW_Coulomb_Energy( system, control, data, workspace, lists, out_control );
}
{
Tabulated_vdW_Coulomb_Energy( system, control, data, workspace,
Kurt A. O'Hearn
committed
lists, out_control );
}
Print_vdW_Coulomb_Forces( system, control, data, workspace,
Kurt A. O'Hearn
committed
lists, out_control );
/* This version of Compute_Total_Force computes forces from coefficients
accumulated by all interaction functions. Saves enormous time & space! */
Kurt A. O'Hearn
committed
static void Compute_Total_Force( reax_system *system, control_params *control,
Kurt A. O'Hearn
committed
simulation_data *data, static_storage *workspace, reax_list **lists )
Kurt A. O'Hearn
committed
int i;
Kurt A. O'Hearn
committed
reax_list *bonds;
Kurt A. O'Hearn
committed
bonds = &(*lists)[BONDS];
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#ifdef _OPENMP
Kurt A. O'Hearn
committed
#pragma omp parallel default(shared)
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
{
int pj;
#ifdef _OPENMP
int j;
#endif
Kurt A. O'Hearn
committed
#ifdef _OPENMP
Kurt A. O'Hearn
committed
#pragma omp for schedule(static)
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
for ( i = 0; i < system->N; ++i )
{
for ( pj = Start_Index(i, bonds); pj < End_Index(i, bonds); ++pj )
Kurt A. O'Hearn
committed
if ( i < bonds->select.bond_list[pj].nbr )
{
if ( control->ensemble == NVE || control->ensemble == nhNVT
|| control->ensemble == bNVT )
Kurt A. O'Hearn
committed
{
Add_dBond_to_Forces( i, pj, system, data, workspace, lists );
}
else
{
Add_dBond_to_Forces_NPT( i, pj, system, data, workspace, lists );
}
}
Kurt A. O'Hearn
committed
}
#ifdef _OPENMP
#pragma omp for schedule(static)
for ( i = 0; i < system->N; ++i )
{
for ( j = 0; j < control->num_threads; ++j )
{
rvec_Add( system->atoms[i].f, workspace->f_local[j * system->N + i] );
}
}
#endif
}
Kurt A. O'Hearn
committed
static void Validate_Lists( static_storage *workspace, reax_list **lists, int step, int n,
Kurt A. O'Hearn
committed
int Hmax, int Htop, int num_bonds, int num_hbonds )
Kurt A. O'Hearn
committed
reax_list *bonds, *hbonds;
Kurt A. O'Hearn
committed
bonds = &(*lists)[BONDS];
hbonds = &(*lists)[HBONDS];
/* far neighbors */
if ( Htop > Hmax * DANGER_ZONE )
{
workspace->realloc.Htop = Htop;
if ( Htop > Hmax )
{
fprintf( stderr,
Kurt A. O'Hearn
committed
"[ERROR] step%d - ran out of space on H matrix: Htop=%d, max = %d",
Kurt A. O'Hearn
committed
exit( INSUFFICIENT_MEMORY );
workspace->realloc.num_bonds = num_bonds;
for ( i = 0; i < n - 1; ++i )
Kurt A. O'Hearn
committed
{
if ( End_Index(i, bonds) >= Start_Index(i + 1, bonds) - 2 )
{
workspace->realloc.bonds = 1;
if ( End_Index(i, bonds) > Start_Index(i + 1, bonds) )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] step%d-bondchk failed: i=%d end(i)=%d str(i+1)=%d\n",
step, flag, End_Index(flag, bonds), Start_Index(flag + 1, bonds) );
Kurt A. O'Hearn
committed
exit( INSUFFICIENT_MEMORY );
if ( End_Index(i, bonds) >= bonds->total_intrs - 2 )
if ( End_Index(i, bonds) > bonds->total_intrs )
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] step%d-bondchk failed: i=%d end(i)=%d bond_end=%d\n",
step, flag, End_Index(i, bonds), bonds->total_intrs );
Kurt A. O'Hearn
committed
exit( INSUFFICIENT_MEMORY );
/* hbonds list */
if ( workspace->num_H > 0 )
{
flag = -1;
workspace->realloc.num_hbonds = num_hbonds;
for ( i = 0; i < workspace->num_H - 1; ++i )
Kurt A. O'Hearn
committed
{
if ( Num_Entries(i, hbonds) >=
(Start_Index(i + 1, hbonds) - Start_Index(i, hbonds)) * DANGER_ZONE )
{
workspace->realloc.hbonds = 1;
if ( End_Index(i, hbonds) > Start_Index(i + 1, hbonds) )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] step%d-hbondchk failed: i=%d end(i)=%d str(i+1)=%d\n",
step, flag, End_Index(flag, hbonds), Start_Index(flag + 1, hbonds) );
Kurt A. O'Hearn
committed
exit( INSUFFICIENT_MEMORY );
(hbonds->total_intrs - Start_Index(i, hbonds)) * DANGER_ZONE )
if ( End_Index(i, hbonds) > hbonds->total_intrs )
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] step%d-hbondchk failed: i=%d end(i)=%d hbondend=%d\n",
step, flag, End_Index(i, hbonds), hbonds->total_intrs );
Kurt A. O'Hearn
committed
exit( INSUFFICIENT_MEMORY );
Kurt A. O'Hearn
committed
static inline real Init_Charge_Matrix_Entry_Tab( reax_system *system,
Kurt A. O'Hearn
committed
control_params *control, LR_lookup_table **LR, int i, int j,
Kurt A. O'Hearn
committed
real r_ij, MATRIX_ENTRY_POSITION pos )
{
int r;
real base, dif, val, ret = 0.0;
LR_lookup_table *t;
switch ( control->charge_method )
{
case QEQ_CM:
//TODO: tabulate other portions of matrices for EE, ACKS2?
case EE_CM:
case ACKS2_CM:
Kurt A. O'Hearn
committed
switch ( pos )
{
case OFF_DIAGONAL:
t = &( LR
[MIN( system->atoms[i].type, system->atoms[j].type )]
[MAX( system->atoms[i].type, system->atoms[j].type )] );
/* cubic spline interpolation */
r = (int)(r_ij * t->inv_dx);
if ( r == 0 )
{
++r;
}
Kurt A. O'Hearn
committed
base = (real)(r + 1) * t->dx;
dif = r_ij - base;
val = ((t->ele[r].d * dif + t->ele[r].c) * dif + t->ele[r].b) * dif +
t->ele[r].a;
Kurt A. O'Hearn
committed
val *= EV_to_KCALpMOL / C_ele;
ret = ((i == j) ? 0.5 : 1.0) * val;
break;
case DIAGONAL:
ret = system->reaxprm.sbp[system->atoms[i].type].eta;
Kurt A. O'Hearn
committed
break;
default:
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] Invalid matrix position. Terminating...\n" );
Kurt A. O'Hearn
committed
exit( INVALID_INPUT );
break;
}
break;
default:
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] Invalid charge method. Terminating...\n" );
Kurt A. O'Hearn
committed
exit( INVALID_INPUT );
break;
}
return ret;
}
static inline real Init_Charge_Matrix_Entry( reax_system *system,
control_params *control, int i, int j,
real r_ij, MATRIX_ENTRY_POSITION pos )
{
Kurt A. O'Hearn
committed
real Tap, dr3gamij_1, dr3gamij_3, ret;
Kurt A. O'Hearn
committed
ret = 0.0;
Kurt A. O'Hearn
committed
switch ( control->charge_method )
{
case QEQ_CM:
case EE_CM:
case ACKS2_CM:
Kurt A. O'Hearn
committed
switch ( pos )
{
case OFF_DIAGONAL:
Tap = control->Tap7 * r_ij + control->Tap6;
Tap = Tap * r_ij + control->Tap5;
Tap = Tap * r_ij + control->Tap4;
Tap = Tap * r_ij + control->Tap3;
Tap = Tap * r_ij + control->Tap2;
Tap = Tap * r_ij + control->Tap1;
Tap = Tap * r_ij + control->Tap0;
Kurt A. O'Hearn
committed
/* shielding */
Kurt A. O'Hearn
committed
dr3gamij_1 = ( r_ij * r_ij * r_ij +
system->reaxprm.tbp[system->atoms[i].type][system->atoms[j].type].gamma );
Kurt A. O'Hearn
committed
dr3gamij_3 = POW( dr3gamij_1 , 1.0 / 3.0 );
Kurt A. O'Hearn
committed
ret = ((i == j) ? 0.5 : 1.0) * Tap * EV_to_KCALpMOL / dr3gamij_3;
break;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
case DIAGONAL:
ret = system->reaxprm.sbp[system->atoms[i].type].eta;
break;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
default:
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] Invalid matrix position. Terminating...\n" );
Kurt A. O'Hearn
committed
exit( INVALID_INPUT );
break;
}
break;
default:
Kurt A. O'Hearn
committed
fprintf( stderr, "[ERROR] Invalid charge method. Terminating...\n" );
Kurt A. O'Hearn
committed
exit( INVALID_INPUT );
break;
}
return ret;
}
Kurt A. O'Hearn
committed
static void Init_Charge_Matrix_Remaining_Entries( reax_system *system,
Kurt A. O'Hearn
committed
control_params *control, reax_list *far_nbrs,
Kurt A. O'Hearn
committed
sparse_matrix * H, sparse_matrix * H_sp,
Kurt A. O'Hearn
committed
int * Htop, int * H_sp_top )
{
Kurt A. O'Hearn
committed
int i, j, pj;
real d, xcut, bond_softness, * X_diag;
Kurt A. O'Hearn
committed
switch ( control->charge_method )
{
case QEQ_CM:
break;
Kurt A. O'Hearn
committed
H->start[system->N_cm - 1] = *Htop;
H_sp->start[system->N_cm - 1] = *H_sp_top;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
for ( i = 0; i < system->N_cm - 1; ++i )
Kurt A. O'Hearn
committed
{
H->j[*Htop] = i;
H->val[*Htop] = 1.0;
Kurt A. O'Hearn
committed
*Htop = *Htop + 1;
Kurt A. O'Hearn
committed
H_sp->j[*H_sp_top] = i;
H_sp->val[*H_sp_top] = 1.0;
Kurt A. O'Hearn
committed
*H_sp_top = *H_sp_top + 1;
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
H->j[*Htop] = system->N_cm - 1;
H->val[*Htop] = 0.0;
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = system->N_cm - 1;
H_sp->val[*H_sp_top] = 0.0;
*H_sp_top = *H_sp_top + 1;
Kurt A. O'Hearn
committed
break;
case ACKS2_CM:
X_diag = (real*) scalloc( system->N, sizeof(real),
"Init_Charge_Matrix_Remaining_Entries::X_diag" );
Kurt A. O'Hearn
committed
H->start[system->N] = *Htop;
H_sp->start[system->N] = *H_sp_top;
for ( i = 0; i < system->N; ++i )
{
H->j[*Htop] = i;
Kurt A. O'Hearn
committed
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = i;
Kurt A. O'Hearn
committed
*H_sp_top = *H_sp_top + 1;
}
H->j[*Htop] = system->N;
H->val[*Htop] = 0.0;
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = system->N;
H_sp->val[*H_sp_top] = 0.0;
*H_sp_top = *H_sp_top + 1;
for ( i = 0; i < system->N; ++i )
{
H->start[system->N + i + 1] = *Htop;
H_sp->start[system->N + i + 1] = *H_sp_top;
H->j[*Htop] = i;
Kurt A. O'Hearn
committed
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = i;
Kurt A. O'Hearn
committed
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
*H_sp_top = *H_sp_top + 1;
for ( pj = Start_Index(i, far_nbrs); pj < End_Index(i, far_nbrs); ++pj )
{
if ( far_nbrs->select.far_nbr_list[pj].d <= control->r_cut )
{
j = far_nbrs->select.far_nbr_list[pj].nbr;
xcut = ( system->reaxprm.sbp[ system->atoms[i].type ].b_s_acks2
+ system->reaxprm.sbp[ system->atoms[j].type ].b_s_acks2 )
/ 2.0;
if ( far_nbrs->select.far_nbr_list[pj].d < xcut &&
far_nbrs->select.far_nbr_list[pj].d > 0.001 )
{
d = far_nbrs->select.far_nbr_list[pj].d / xcut;
bond_softness = system->reaxprm.gp.l[34] * POW( d, 3.0 ) * POW( 1.0 - d, 6.0 );
H->j[*Htop] = system->N + j + 1;
H->val[*Htop] = MAX( 0.0, bond_softness );
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = system->N + j + 1;
H_sp->val[*H_sp_top] = MAX( 0.0, bond_softness );
*H_sp_top = *H_sp_top + 1;
X_diag[i] -= bond_softness;
X_diag[j] -= bond_softness;
}
}
}
H->j[*Htop] = system->N + i + 1;
H->val[*Htop] = 0.0;
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = system->N + i + 1;
H_sp->val[*H_sp_top] = 0.0;
*H_sp_top = *H_sp_top + 1;
}
H->start[system->N_cm - 1] = *Htop;
H_sp->start[system->N_cm - 1] = *H_sp_top;
for ( i = system->N + 1; i < system->N_cm - 1; ++i )
{
for ( pj = H->start[i]; pj < H->start[i + 1]; ++pj )
{
if ( H->j[pj] == i )
{
H->val[pj] = X_diag[i - system->N - 1];
break;
}
}
for ( pj = H_sp->start[i]; pj < H_sp->start[i + 1]; ++pj )
{
if ( H_sp->j[pj] == i )
{
H_sp->val[pj] = X_diag[i - system->N - 1];
break;
}
}
}
for ( i = system->N + 1; i < system->N_cm - 1; ++i )
{
H->j[*Htop] = i;
Kurt A. O'Hearn
committed
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = i;
Kurt A. O'Hearn
committed
*H_sp_top = *H_sp_top + 1;
}
H->j[*Htop] = system->N_cm - 1;
H->val[*Htop] = 0.0;
*Htop = *Htop + 1;
H_sp->j[*H_sp_top] = system->N_cm - 1;
H_sp->val[*H_sp_top] = 0.0;
*H_sp_top = *H_sp_top + 1;
sfree( X_diag, "Init_Charge_Matrix_Remaining_Entries::X_diag" );
Kurt A. O'Hearn
committed
break;
default:
break;
}
}
Kurt A. O'Hearn
committed
static void Init_Forces( reax_system *system, control_params *control,
Kurt A. O'Hearn
committed
simulation_data *data, static_storage *workspace,
Kurt A. O'Hearn
committed
reax_list **lists, output_controls *out_control )
{
int i, j, pj;
int start_i, end_i;
int type_i, type_j;
int Htop, H_sp_top, btop_i, btop_j, num_bonds, num_hbonds;
Kurt A. O'Hearn
committed
real r_ij, r2;
real C12, C34, C56;
real Cln_BOp_s, Cln_BOp_pi, Cln_BOp_pi2;
real BO, BO_s, BO_pi, BO_pi2;
sparse_matrix *H, *H_sp;
Kurt A. O'Hearn
committed
reax_list *far_nbrs, *bonds, *hbonds;
single_body_parameters *sbp_i, *sbp_j;
two_body_parameters *twbp;
far_neighbor_data *nbr_pj;
reax_atom *atom_i, *atom_j;
bond_data *ibond, *jbond;
bond_order_data *bo_ij, *bo_ji;
Kurt A. O'Hearn
committed
far_nbrs = &(*lists)[FAR_NBRS];
bonds = &(*lists)[BONDS];
hbonds = &(*lists)[HBONDS];
H_sp = workspace->H_sp;
Kurt A. O'Hearn
committed
btop_i = 0;
btop_j = 0;
for ( i = 0; i < system->N; ++i )
{
atom_i = &(system->atoms[i]);
type_i = atom_i->type;
Kurt A. O'Hearn
committed
start_i = Start_Index( i, far_nbrs );
end_i = End_Index( i, far_nbrs );
H_sp->start[i] = H_sp_top;
btop_i = End_Index( i, bonds );
sbp_i = &(system->reaxprm.sbp[type_i]);
ihb = ihb_top = -1;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
}
for ( pj = start_i; pj < end_i; ++pj )
{
nbr_pj = &( far_nbrs->select.far_nbr_list[pj] );
j = nbr_pj->nbr;
atom_j = &(system->atoms[j]);
flag = 0;
Kurt A. O'Hearn
committed
if ( (data->step - data->prev_steps) % control->reneighbor == 0 )
if ( nbr_pj->d <= control->r_cut )
{
if ( nbr_pj->d <= control->r_sp_cut )
{
flag_sp = 1;
}
}
else
{
flag = 0;
flag_sp = 0;
}
}
else if ((nbr_pj->d = Sq_Distance_on_T3(atom_i->x, atom_j->x, &(system->box),
Kurt A. O'Hearn
committed
nbr_pj->dvec)) <= SQR(control->r_cut))
if ( nbr_pj->d <= SQR(control->r_sp_cut))
{
flag_sp = 1;
}
nbr_pj->d = SQRT( nbr_pj->d );
flag = 1;
}
if ( flag )
{
type_j = system->atoms[j].type;
r_ij = nbr_pj->d;
sbp_j = &(system->reaxprm.sbp[type_j]);
twbp = &(system->reaxprm.tbp[type_i][type_j]);
Kurt A. O'Hearn
committed
H->j[Htop] = j;
Kurt A. O'Hearn
committed
H->val[Htop] = Init_Charge_Matrix_Entry( system, control, i, j,
r_ij, OFF_DIAGONAL );
/* H_sp matrix entry */
if ( flag_sp )
{
Kurt A. O'Hearn
committed
H_sp->j[H_sp_top] = j;
H_sp->val[H_sp_top] = H->val[Htop - 1];
++H_sp_top;
}
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
/* hydrogen bond lists */
if ( control->hb_cut > 0 && (ihb == 1 || ihb == 2) &&
nbr_pj->d <= control->hb_cut )
{
// fprintf( stderr, "%d %d\n", atom1, atom2 );
jhb = sbp_j->p_hbond;
if ( ihb == 1 && jhb == 2 )
{
hbonds->select.hbond_list[ihb_top].nbr = j;
hbonds->select.hbond_list[ihb_top].scl = 1;
hbonds->select.hbond_list[ihb_top].ptr = nbr_pj;
++ihb_top;
++num_hbonds;
}
else if ( ihb == 2 && jhb == 1 )
{
jhb_top = End_Index( workspace->hbond_index[j], hbonds );
hbonds->select.hbond_list[jhb_top].nbr = i;
hbonds->select.hbond_list[jhb_top].scl = -1;
hbonds->select.hbond_list[jhb_top].ptr = nbr_pj;
Set_End_Index( workspace->hbond_index[j], jhb_top + 1, hbonds );
++num_hbonds;
}
}
/* uncorrected bond orders */
if ( far_nbrs->select.far_nbr_list[pj].d <= control->nbr_cut )
{
Kurt A. O'Hearn
committed
r2 = SQR( r_ij );
Kurt A. O'Hearn
committed
if ( sbp_i->r_s > 0.0 && sbp_j->r_s > 0.0 )
{
C12 = twbp->p_bo1 * POW( r_ij / twbp->r_s, twbp->p_bo2 );
BO_s = (1.0 + control->bo_cut) * EXP( C12 );
}
Kurt A. O'Hearn
committed
else
{
BO_s = 0.0;
C12 = 0.0;
}
Kurt A. O'Hearn
committed
if ( sbp_i->r_pi > 0.0 && sbp_j->r_pi > 0.0 )
{
C34 = twbp->p_bo3 * POW( r_ij / twbp->r_p, twbp->p_bo4 );
BO_pi = EXP( C34 );
}
Kurt A. O'Hearn
committed
else
{
BO_pi = 0.0;
C34 = 0.0;
}
Kurt A. O'Hearn
committed
if ( sbp_i->r_pi_pi > 0.0 && sbp_j->r_pi_pi > 0.0 )
{
C56 = twbp->p_bo5 * POW( r_ij / twbp->r_pp, twbp->p_bo6 );
BO_pi2 = EXP( C56 );
}
Kurt A. O'Hearn
committed
else
{
BO_pi2 = 0.0;
C56 = 0.0;
}
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
/* Initially BO values are the uncorrected ones, page 1 */
BO = BO_s + BO_pi + BO_pi2;
if ( BO >= control->bo_cut )
{
num_bonds += 2;
/****** bonds i-j and j-i ******/
ibond = &( bonds->select.bond_list[btop_i] );
btop_j = End_Index( j, bonds );
jbond = &(bonds->select.bond_list[btop_j]);
ibond->nbr = j;
jbond->nbr = i;
ibond->d = r_ij;
jbond->d = r_ij;
rvec_Copy( ibond->dvec, nbr_pj->dvec );
rvec_Scale( jbond->dvec, -1, nbr_pj->dvec );
ivec_Copy( ibond->rel_box, nbr_pj->rel_box );
ivec_Scale( jbond->rel_box, -1, nbr_pj->rel_box );
ibond->dbond_index = btop_i;
jbond->dbond_index = btop_i;
ibond->sym_index = btop_j;
jbond->sym_index = btop_i;
++btop_i;
Set_End_Index( j, btop_j + 1, bonds );
bo_ij = &( ibond->bo_data );
bo_ji = &( jbond->bo_data );
bo_ji->BO = bo_ij->BO = BO;
bo_ji->BO_s = bo_ij->BO_s = BO_s;
bo_ji->BO_pi = bo_ij->BO_pi = BO_pi;
bo_ji->BO_pi2 = bo_ij->BO_pi2 = BO_pi2;
/* Bond Order page2-3, derivative of total bond order prime */
Cln_BOp_s = twbp->p_bo2 * C12 / r2;
Cln_BOp_pi = twbp->p_bo4 * C34 / r2;
Cln_BOp_pi2 = twbp->p_bo6 * C56 / r2;
/* Only dln_BOp_xx wrt. dr_i is stored here, note that
dln_BOp_xx/dr_i = -dln_BOp_xx/dr_j and all others are 0 */
Kurt A. O'Hearn
committed
rvec_Scale( bo_ij->dln_BOp_s, -bo_ij->BO_s * Cln_BOp_s, ibond->dvec );
rvec_Scale( bo_ij->dln_BOp_pi, -bo_ij->BO_pi * Cln_BOp_pi, ibond->dvec );
rvec_Scale( bo_ij->dln_BOp_pi2,
-bo_ij->BO_pi2 * Cln_BOp_pi2, ibond->dvec );
rvec_Scale( bo_ji->dln_BOp_s, -1., bo_ij->dln_BOp_s );
rvec_Scale( bo_ji->dln_BOp_pi, -1., bo_ij->dln_BOp_pi );
rvec_Scale( bo_ji->dln_BOp_pi2, -1., bo_ij->dln_BOp_pi2 );
/* Only dBOp wrt. dr_i is stored here, note that
dBOp/dr_i = -dBOp/dr_j and all others are 0 */
rvec_Scale( bo_ij->dBOp,
-(bo_ij->BO_s * Cln_BOp_s +
bo_ij->BO_pi * Cln_BOp_pi +
bo_ij->BO_pi2 * Cln_BOp_pi2), ibond->dvec );
rvec_Scale( bo_ji->dBOp, -1., bo_ij->dBOp );
rvec_Add( workspace->dDeltap_self[i], bo_ij->dBOp );
rvec_Add( workspace->dDeltap_self[j], bo_ji->dBOp );
bo_ij->BO_s -= control->bo_cut;
bo_ij->BO -= control->bo_cut;
bo_ji->BO_s -= control->bo_cut;
bo_ji->BO -= control->bo_cut;
Kurt A. O'Hearn
committed
workspace->total_bond_order[i] += bo_ij->BO;
workspace->total_bond_order[j] += bo_ji->BO;
Kurt A. O'Hearn
committed
bo_ij->Cdbo = 0.0;
bo_ij->Cdbopi = 0.0;
bo_ij->Cdbopi2 = 0.0;
bo_ji->Cdbo = 0.0;
bo_ji->Cdbopi = 0.0;
bo_ji->Cdbopi2 = 0.0;
Set_End_Index( j, btop_j + 1, bonds );
}
}
}
}
/* diagonal entry */
Kurt A. O'Hearn
committed
H->j[Htop] = i;
Kurt A. O'Hearn
committed
H->val[Htop] = Init_Charge_Matrix_Entry( system, control, i, i,
Kurt A. O'Hearn
committed
r_ij, DIAGONAL );
Kurt A. O'Hearn
committed
H_sp->j[H_sp_top] = i;
H_sp->val[H_sp_top] = H->val[Htop - 1];
Kurt A. O'Hearn
committed
{
Set_End_Index( workspace->hbond_index[i], ihb_top, hbonds );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
Init_Charge_Matrix_Remaining_Entries( system, control, far_nbrs,
H, H_sp, &Htop, &H_sp_top );
Kurt A. O'Hearn
committed
H->start[system->N_cm] = Htop;
H_sp->start[system->N_cm] = H_sp_top;
/* validate lists - decide if reallocation is required! */
Validate_Lists( workspace, lists,
Kurt A. O'Hearn
committed
data->step, system->N, H->m, Htop, num_bonds, num_hbonds );
fprintf( stderr, "step%d: Htop = %d, num_bonds = %d, num_hbonds = %d\n",
data->step, Htop, num_bonds, num_hbonds );
Kurt A. O'Hearn
committed
static void Init_Forces_Tab( reax_system *system, control_params *control,
Kurt A. O'Hearn
committed
simulation_data *data, static_storage *workspace,
Kurt A. O'Hearn
committed
reax_list **lists, output_controls *out_control )
{
int i, j, pj;
int start_i, end_i;
int type_i, type_j;
int Htop, H_sp_top, btop_i, btop_j, num_bonds, num_hbonds;
int flag, flag_sp;
Kurt A. O'Hearn
committed
real r_ij, r2;
real C12, C34, C56;
real Cln_BOp_s, Cln_BOp_pi, Cln_BOp_pi2;
real BO, BO_s, BO_pi, BO_pi2;
sparse_matrix *H, *H_sp;
Kurt A. O'Hearn
committed
reax_list *far_nbrs, *bonds, *hbonds;
single_body_parameters *sbp_i, *sbp_j;
two_body_parameters *twbp;
far_neighbor_data *nbr_pj;
reax_atom *atom_i, *atom_j;
bond_data *ibond, *jbond;
bond_order_data *bo_ij, *bo_ji;
Kurt A. O'Hearn
committed
far_nbrs = &(*lists)[FAR_NBRS];
bonds = &(*lists)[BONDS];
hbonds = &(*lists)[HBONDS];
H_sp = workspace->H_sp;
H_sp_top = 0;
Kurt A. O'Hearn
committed
btop_i = 0;
btop_j = 0;
for ( i = 0; i < system->N; ++i )
{
atom_i = &(system->atoms[i]);
type_i = atom_i->type;
Kurt A. O'Hearn
committed
start_i = Start_Index( i, far_nbrs );
end_i = End_Index( i, far_nbrs );
H_sp->start[i] = H_sp_top;
btop_i = End_Index( i, bonds );
sbp_i = &(system->reaxprm.sbp[type_i]);
ihb = ihb_top = -1;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
}
for ( pj = start_i; pj < end_i; ++pj )
{
nbr_pj = &( far_nbrs->select.far_nbr_list[pj] );
j = nbr_pj->nbr;
atom_j = &(system->atoms[j]);
flag = 0;
flag_sp = 0;
Kurt A. O'Hearn
committed
if ( (data->step - data->prev_steps) % control->reneighbor == 0 )
{
if ( nbr_pj->d <= control->r_sp_cut )
{
flag_sp = 1;
}
}
else
{
flag = 0;
flag_sp = 0;
}
}
else if ((nbr_pj->d = Sq_Distance_on_T3(atom_i->x, atom_j->x, &(system->box),
Kurt A. O'Hearn
committed
nbr_pj->dvec)) <= SQR(control->r_cut))
if ( nbr_pj->d <= SQR(control->r_sp_cut))
{
flag_sp = 1;
}
Kurt A. O'Hearn
committed
nbr_pj->d = SQRT( nbr_pj->d );
flag = 1;
}
if ( flag )
{
type_j = system->atoms[j].type;
r_ij = nbr_pj->d;
sbp_j = &(system->reaxprm.sbp[type_j]);
twbp = &(system->reaxprm.tbp[type_i][type_j]);
Kurt A. O'Hearn
committed
H->j[Htop] = j;
Kurt A. O'Hearn
committed
H->val[Htop] = Init_Charge_Matrix_Entry( system, control, i, j,
r_ij, OFF_DIAGONAL );
/* H_sp matrix entry */
if ( flag_sp )
{
H_sp->j[H_sp_top] = j;
H_sp->val[H_sp_top] = H->val[Htop - 1];
++H_sp_top;
}
/* hydrogen bond lists */
if ( control->hb_cut > 0 && (ihb == 1 || ihb == 2) &&
nbr_pj->d <= control->hb_cut )
{
// fprintf( stderr, "%d %d\n", atom1, atom2 );
jhb = sbp_j->p_hbond;
if ( ihb == 1 && jhb == 2 )
{
hbonds->select.hbond_list[ihb_top].nbr = j;
hbonds->select.hbond_list[ihb_top].scl = 1;
hbonds->select.hbond_list[ihb_top].ptr = nbr_pj;
++ihb_top;
++num_hbonds;
}
else if ( ihb == 2 && jhb == 1 )
{
jhb_top = End_Index( workspace->hbond_index[j], hbonds );
hbonds->select.hbond_list[jhb_top].nbr = i;
hbonds->select.hbond_list[jhb_top].scl = -1;
hbonds->select.hbond_list[jhb_top].ptr = nbr_pj;