Main Page | Class List | File List | Class Members | File Members

step_defn.h

00001 /*
00002  * Copyright (C) 2007 by David J. Hardy.  All rights reserved.
00003  */
00004 
00005 #ifndef STEPDEFN_H
00006 #define STEPDEFN_H
00007 
00008 #include "step/step.h"
00009 #include "random/random.h"
00010 
00011 #ifdef __cplusplus
00012 extern "C" {
00013 #endif
00014 
00015   /* Boolean values */
00016   enum { STEP_FALSE = 0, STEP_TRUE = 1 };
00017 
00018   /* indices for kinetic virial tensor */
00019   enum {
00020     VIRIAL_XX = 0,
00021     VIRIAL_XY,
00022     VIRIAL_XZ,
00023     VIRIAL_YX,
00024     VIRIAL_YY,
00025     VIRIAL_YZ,
00026     VIRIAL_ZX,
00027     VIRIAL_ZY,
00028     VIRIAL_ZZ,
00029     VIRIAL_LEN
00030   };
00031 
00032   /* indices for upper triangle of kinetic virial */
00033   enum {
00034     VIRIAL_UPPER_XX = 0,
00035     VIRIAL_UPPER_XY,
00036     VIRIAL_UPPER_XZ,
00037     VIRIAL_UPPER_YY,
00038     VIRIAL_UPPER_YZ,
00039     VIRIAL_UPPER_ZZ,
00040     VIRIAL_UPPER_LEN
00041   };
00042 
00043   /* indices for Step::sham array */
00044   enum {
00045     SHADOW2=0, SHADOW4, SHADOW6, SHADOW8,
00046     SHADOW10, SHADOW12, SHADOW14, SHADOW16,
00047     SHADOW18, SHADOW20, SHADOW22,  SHADOW24,
00048 
00049     ORDERK, ORDERK1
00050   };
00051 
00052   /* Drude helper class */
00053   typedef struct DrudeBond_t {
00054     double massRatio;
00055     int32 atomIndex;
00056     int32 drudeIndex;
00057   } DrudeBond;
00058 
00059 
00064   struct Step_t {
00065     StepParam *param;       /* shallow copy of user StepParam object */
00066     StepSystem *system;     /* allocated */
00067     int32 cleanup_vel;      /* did we alloc vel array? */
00068     int32 cleanup_force;    /* did we alloc force array? */
00069     int32 doFixedAtoms;
00070     int32 doRigidWaters;
00071 
00072     Random random;          /* random number generator */
00073 
00074 #if 0
00075     int32 is_force_valid;
00078 #endif
00079 
00080     double tempkonst;       /* constant needed to compute temperature */
00081     double *scal_inv_mass;  /* compute array of scaled inverse mass,
00082                                for efficiency */
00083     MD_Dvec *half_vel;      /* half-step velocities for kinetic reductions */
00084 
00085     /* buffer for error messages */
00086     char errmsg[512];
00087 
00088     /* retain method compute and done routines */
00089     int (*compute)(struct Step_t *, int32 numsteps);
00090     void (*done)(struct Step_t *);
00091 
00092     /* 
00093      * Variables for calculating shadow Hamiltonian using
00094      * backward differences (Engle, Skeel, & Drees, 2005).
00095      */
00096     int orderk;        /* related to order of approximation */
00097     double *sham;      /* stores shadow Hamiltonian approximations */
00098 
00099     MD_Dvec **dif_q;   /* backward difference table for position */
00100     MD_Dvec **dif_p;   /* backward difference table for momentum */
00101     double *dif_beta;  /* backward difference table for beta */
00102     double **Atab;
00103     double **coef;
00104     MD_Dvec *old_f;    /* stores previous forces */
00105     /* end shadow Hamiltonian */
00106 
00107     /*
00108      * Variables for weak-coupling to temperature bath.
00109      */
00110     double dt_tau;     /* timestep / relaxation_time */
00111     double twoke_bath;
00112 
00113     /*
00114      * Variables for Nose-Hoover.
00115      */
00116     double twice_desired_ke;  /* twice desired kinetic energy,
00117                                  internal units of AMU A^2 / fs^2 */
00118     double nh_qmass;          /* thermostat "mass" for extended Lagrangian */
00119     double dt_over_qmass;     /* timestep / Qmass */
00120     double xi;                /* thermodynamic friction coefficient */
00121     double eta;               /* log s */
00122     double twoke;             /* twice kinetic energy */
00123     
00124     /*
00125      * Variables for thermalized Drude oscillators.
00126      *
00127      * Atoms are transformed into
00128      * com (centers of mass) and dbond (Drude bonds)
00129      * which are propagated using a dual thermostat,
00130      * warm for com, cold for dbond.
00131      *
00132      * natoms = 2*num_drudeBond + num_nonPolarized
00133      *
00134      * num_dbond = num_drudeBond
00135      * num_com = num_drudeBond + num_nonPolarized
00136      */
00137 
00138     /* this is transformed system state */
00139     int32 num_com, num_dbond;
00140     MD_Dvec *pos_com, *pos_dbond;
00141     MD_Dvec *vel_com, *vel_dbond;
00142     MD_Dvec *f_com, *f_dbond;
00143     double *mass_com, *mass_dbond;
00144     double *scal_inv_mass_com, *scal_inv_mass_dbond;
00145 
00146     /* this is for dual thermostat */
00147     double eta_com, eta_dbond;
00148     double xi_com, xi_dbond;
00149     double qmass_com, qmass_dbond;
00150     double twice_desired_ke_com;
00151     double twice_desired_ke_dbond;
00152     double dt_over_qmass_com;
00153     double dt_over_qmass_dbond;
00154     double twoke_com, twoke_dbond;
00155     double tempkonst_com, tempkonst_dbond;
00156 
00157     /* this is the map that transforms between atoms and (com, dbond) */
00158     DrudeBond *drudeBond;    /* the Drude bond topology */
00159     int32 num_drudeBond;
00160     int32 *nonPolarized;     /* the remaining non-polarized atoms */
00161     int32 num_nonPolarized;
00162     int32 is_drude;
00163 
00164     /*
00165      * Variables for CG minimization.
00166      */
00167     double u;
00168     double fdf;
00169     MD_Dvec *starting_position;
00170     MD_Dvec *search_direction;
00171     /* end CG minimization */
00172 
00173     /*
00174      * Variables for SETTLE
00175      */
00176     MD_Dvec *refpos;  /* have to retain reference positions */
00177     double o_mass;  /* mass of oxygen */
00178     double h_mass;  /* mass of hydrogen */
00179     double ra, rb, rc;  /* canonical positions of water atoms */
00180   };
00181 
00182 
00183   /* for error handling */
00184   int step_error(Step *, const char *fmt, ...);
00185 
00186   /* for setting up velocities */
00187   int step_set_random_velocities(Step *);
00188   void step_remove_com_motion(Step *);
00189 
00190   /* callback to provide simulation results */
00191   int step_results(Step *, int32 delta_stepnum);
00192   void step_results_twoke(double *e_sum,
00193       const MD_Dvec *v, const MD_Atom *atom, int32 natoms);
00194   void step_results_linmo(MD_Dvec *linmo,
00195       const MD_Dvec *v, const MD_Atom *atom, int32 natoms);
00196   void step_results_angmo(MD_Dvec *angmo,
00197       const MD_Dvec *r, const MD_Dvec *v, const MD_Atom *atom, int32 natoms);
00198   void step_results_kvirial(double u_kv[VIRIAL_UPPER_LEN],
00199       const MD_Dvec *v, const MD_Atom *atom, int32 natoms);
00200 
00201   /* callback to compute force */
00202   int step_force(Step *);
00203 
00204   /* callback to send text output */
00205   int step_output(Step *, const char *fmt, ...);
00206 
00207   /* integration methods */
00208   int step_compute_verlet(Step *, int32 numsteps);
00209   int step_init_verlet(Step *);
00210   void step_done_verlet(Step *);
00211 
00212   int step_compute_shadow(Step *, int32 numsteps);
00213   int step_init_shadow(Step *);
00214   void step_done_shadow(Step *);
00215 
00216   int step_compute_tempbath(Step *, int32 numsteps);
00217   int step_init_tempbath(Step *);
00218   void step_done_tempbath(Step *);
00219 
00220   int step_compute_nosehoover_explicit(Step *, int32 numsteps);
00221   int step_init_nosehoover_explicit(Step *);
00222   void step_done_nosehoover_explicit(Step *);
00223   
00224   int step_compute_drude_thermal(Step *, int32 numsteps);
00225   int step_init_drude_thermal(Step *);
00226   void step_done_drude_thermal(Step *);
00227   
00228   int step_compute_drude_roux(Step *, int32 numsteps);
00229   int step_init_drude_roux(Step *);
00230   void step_done_drude_roux(Step *);
00231   
00232   int step_compute_drude_chen(Step *, int32 numsteps);
00233   int step_init_drude_chen(Step *);
00234   void step_done_drude_chen(Step *);
00235   
00236   int step_compute_cgmin(Step *, int32 numsteps);
00237   int step_init_cgmin(Step *);
00238   void step_done_cgmin(Step *);
00239 
00240 
00241   /* for SETTLE */
00242   int step_setup_settle(Step *s);
00243   void step_cleanup_settle(Step *s);
00244   int step_settle_startup(Step *s);
00245   int step_settle_prep(Step *s);
00246   int step_settle1(Step *s, const double dt);
00247   int step_settle2(Step *s, const double dt);
00248 
00249 
00250 #ifdef __cplusplus
00251 }
00252 #endif
00253 
00254 #endif /* STEPDEFN_H */

Generated on Thu Feb 7 18:11:40 2008 for MDX by  doxygen 1.3.9.1