Controller.h

Go to the documentation of this file.
00001 
00007 #ifndef CONTROLLER_H
00008 #define CONTROLLER_H
00009 
00010 #include "converse.h"
00011 #include "Node.h"
00012 #include "common.h"
00013 #include "fstream_namd.h"
00014 #include <string>
00015 #include <map>
00016 
00017 class ControllerBroadcasts;
00018 class NamdState;
00019 class SimParameters;
00020 class RequireReduction;
00021 class SubmitReduction;
00022 
00023 #ifdef MEM_OPT_VERSION
00024 class CollectionMasterHandler;
00025 #else
00026 class CollectionMaster;
00027 #endif
00028 
00029 class Random;
00030 class PressureProfileReduction;
00031 
00032 struct ControllerState {
00033     Tensor langevinPiston_strainRate;
00034     Tensor berendsenPressure_avg;
00035     int berendsenPressure_count;
00036     BigReal smooth2_avg;
00037 };
00038 
00039 class Controller : protected ControllerState
00040 {
00041 public:
00042     Controller(NamdState *s);
00043     virtual ~Controller(void);
00044     void run(void);             // spawn thread, etc.
00045     void awaken(void) { CthAwaken(thread); };
00046     void resumeAfterTraceBarrier(int);
00047 #ifdef MEASURE_NAMD_WITH_PAPI
00048         void resumeAfterPapiMeasureBarrier(int step);
00049 #endif
00050 
00051 protected:
00052     friend class ScriptTcl;
00053     friend class Node;
00054     friend class CheckpointMsg;
00055     virtual void algorithm(void);       // subclasses redefine this method
00056 
00057     void integrate(int); // Verlet integrator
00058     void minimize(); // CG minimizer
00059       RequireReduction *min_reduction;
00060 
00061     void receivePressure(int step, int minimize = 0);
00062     void calcPressure(int step, int minimize,
00063       const Tensor& virial_normal_in, const Tensor& virial_nbond_in, const Tensor& virial_slow_in,
00064       const Tensor& intVirial_normal, const Tensor& intVirial_nbond, const Tensor& intVirial_slow,
00065       const Vector& extForce_normal, const Vector& extForce_nbond, const Vector& extForce_slow);
00066 
00067       Tensor pressure_normal;
00068       Tensor pressure_nbond;
00069       Tensor pressure_slow;
00070       Tensor pressure_amd;
00071       Tensor virial_amd;
00072       Tensor groupPressure_normal;
00073       Tensor groupPressure_nbond;
00074       Tensor groupPressure_slow;
00075       Tensor controlPressure_normal;
00076       Tensor controlPressure_nbond;
00077       Tensor controlPressure_slow;
00078       int nbondFreq;
00079       int slowFreq;
00080       BigReal temp_avg;
00081       BigReal pressure_avg;
00082       BigReal groupPressure_avg;
00083       int avg_count;
00084       Tensor pressure_tavg;
00085       Tensor groupPressure_tavg;
00086       int tavg_count;
00087     void compareChecksums(int,int=0);
00088       int computeChecksum;
00089       int marginViolations;
00090       int pairlistWarnings;
00091     void printTiming(int);
00092     void printMinimizeEnergies(int);
00093       BigReal min_energy;
00094       BigReal min_f_dot_f;
00095       BigReal min_f_dot_v;
00096       BigReal min_v_dot_v;
00097       int min_huge_count;
00098     void printDynamicsEnergies(int);
00099     void printEnergies(int step, int minimize);
00100       int64_t numDegFreedom;
00101       int stepInFullRun;
00102       BigReal totalEnergy;
00103       BigReal electEnergy;
00104       BigReal electEnergySlow;
00105       BigReal ljEnergy;
00106       BigReal groLJEnergy;
00107       BigReal groGaussEnergy;
00108       BigReal goNativeEnergy;
00109       BigReal goNonnativeEnergy;
00110       BigReal goTotalEnergy;
00111 //fepb
00112       BigReal bondedEnergyDiff_f;
00113       BigReal electEnergy_f;
00114       BigReal electEnergySlow_f;
00115       BigReal ljEnergy_f;
00116       BigReal ljEnergy_f_left;  // used by WCA repulsive, [s1,s2]
00117       BigReal exp_dE_ByRT;
00118       BigReal dE;
00119       BigReal net_dE;
00120       BigReal dG;
00121       int FepNo;
00122       void printFepMessage(int);
00123       BigReal fepSum;
00124 //fepe
00125       BigReal bondedEnergy_ti_1;
00126       BigReal bondedEnergy_ti_2;
00127       BigReal electEnergy_ti_1;
00128       BigReal electEnergySlow_ti_1;
00129       BigReal ljEnergy_ti_1;
00130       BigReal electEnergy_ti_2;
00131       BigReal electEnergySlow_ti_2;
00132       BigReal ljEnergy_ti_2;
00133       BigReal net_dEdl_bond_1;
00134       BigReal net_dEdl_bond_2;
00135       BigReal net_dEdl_elec_1;
00136       BigReal net_dEdl_elec_2;
00137       BigReal net_dEdl_lj_1;
00138       BigReal net_dEdl_lj_2;
00139       BigReal cumAlchWork;
00140       BigReal electEnergyPME_ti_1;
00141       BigReal electEnergyPME_ti_2;
00142       int TiNo;
00143       BigReal recent_dEdl_bond_1;
00144       BigReal recent_dEdl_bond_2;
00145       BigReal recent_dEdl_elec_1;
00146       BigReal recent_dEdl_elec_2;
00147       BigReal recent_dEdl_lj_1;
00148       BigReal recent_dEdl_lj_2;
00149       BigReal recent_alchWork;
00150       BigReal alchWork;
00151       int recent_TiNo;
00152       void printTiMessage(int);
00153 
00154       BigReal drudeBondTemp; // temperature of Drude bonds
00155       BigReal drudeBondTempAvg;
00156 
00157       BigReal kineticEnergy;
00158       BigReal kineticEnergyHalfstep;
00159       BigReal kineticEnergyCentered;
00160       BigReal temperature;
00161       // BigReal smooth2_avg;
00162       BigReal smooth2_avg2;  // avoid internal compiler error
00163       Tensor pressure;
00164       Tensor groupPressure;
00165       int controlNumDegFreedom;
00166       Tensor controlPressure;
00167     void enqueueCollections(int);
00168     void correctMomentum(int step);
00169     void rescaleVelocities(int);
00170       BigReal rescaleVelocities_sumTemps;
00171       int rescaleVelocities_numTemps;
00172     void reassignVelocities(int);
00173     void tcoupleVelocities(int);
00174     void berendsenPressure(int);
00175       // Tensor berendsenPressure_avg;
00176       // int berendsenPressure_count;
00177     void langevinPiston1(int);
00178     void langevinPiston2(int);
00179       Tensor langevinPiston_origStrainRate;
00180       Tensor strainRate_old;  // for langevinPistonBarrier no
00181       Tensor positionRescaleFactor;  // for langevinPistonBarrier no
00182 
00183     void multigratorPressure(int step, int callNumber);
00184     BigReal multigratorXi;
00185     BigReal multigratorXiT;
00186     Tensor momentumSqrSum;
00187     void multigratorTemperature(int step, int callNumber);
00188     std::vector<BigReal> multigratorNu;
00189     std::vector<BigReal> multigratorNuT;
00190     std::vector<BigReal> multigratorOmega;
00191     std::vector<BigReal> multigratorZeta;
00192     RequireReduction *multigratorReduction;
00193     BigReal multigatorCalcEnthalpy(BigReal potentialEnergy, int step, int minimize);
00194 
00195     int ldbSteps;
00196     void rebalanceLoad(int);
00197       int fflush_count;
00198     void cycleBarrier(int,int); 
00199         
00200         void traceBarrier(int, int);
00201 
00202 #ifdef MEASURE_NAMD_WITH_PAPI
00203         void papiMeasureBarrier(int, int);
00204 #endif
00205 
00206     // void suspend(void) { CthSuspend(); };
00207     void terminate(void);
00208 
00209     Random *random;
00210     SimParameters *const simParams;     // for convenience
00211     NamdState *const state;             // access data in state
00212     RequireReduction *reduction;
00213     RequireReduction *amd_reduction;
00214     SubmitReduction *submit_reduction;
00215 
00216     // data for pressure profile reductions and output
00217     PressureProfileReduction *ppbonded;
00218     PressureProfileReduction *ppnonbonded;
00219     PressureProfileReduction *ppint;
00220     int pressureProfileSlabs;
00221     int pressureProfileCount;
00222     BigReal *pressureProfileAverage;
00223 
00224     CollectionMaster *const collection;
00225     
00226     ControllerBroadcasts * broadcast;
00227     ofstream_namd xstFile;
00228     void outputExtendedSystem(int step);
00229     void writeExtendedSystemLabels(ofstream_namd &file);
00230     void writeExtendedSystemData(int step, ofstream_namd &file);
00231 
00232 //fepb
00233     ofstream_namd fepFile;
00234     void outputFepEnergy(int step);
00235     void writeFepEnergyData(int step, ofstream_namd &file);
00236 //fepe
00237     ofstream_namd tiFile;
00238     void outputTiEnergy(int step);
00239     BigReal computeAlchWork(const int step);
00240     void writeTiEnergyData(int step, ofstream_namd &file);
00241 
00242     // for checkpoint/revert
00243     int checkpoint_stored;
00244     Lattice checkpoint_lattice;
00245     ControllerState checkpoint_state;
00246 
00247     struct checkpoint {
00248       Lattice lattice;
00249       ControllerState state;
00250     };
00251     std::map<std::string,checkpoint*> checkpoints;
00252     int checkpoint_task;
00253     void recvCheckpointReq(const char *key, int task, checkpoint &cp);
00254     void recvCheckpointAck(checkpoint &cp);
00255 
00256     Lattice origLattice;
00257 
00258 //for accelMD
00259    inline void calc_accelMDG_mean_std
00260    (BigReal testV, int step_n, 
00261     BigReal *Vmax, BigReal *Vmin, BigReal *Vavg, BigReal *M2, BigReal *sigmaV);
00262 
00263    inline void calc_accelMDG_E_k
00264    (int iE, int V_n, BigReal sigma0, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, 
00265     BigReal* k0, BigReal* k, BigReal* E, int* iEused, char *warn);
00266 
00267    inline void calc_accelMDG_force_factor
00268    (BigReal k, BigReal E, BigReal testV, Tensor vir_orig,
00269     BigReal *dV, BigReal *factor, Tensor *vir);
00270 
00271    void write_accelMDG_rest_file
00272        (int step_n, char type, int V_n, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, BigReal M2,
00273         BigReal E, BigReal k, bool write_topic, bool lasttime);
00274 
00275    void rescaleaccelMD (int step, int minimize = 0);
00276    BigReal accelMDdVAverage;
00277 
00278 //JS for adaptive temperature sampling
00279    void adaptTempInit(int step);
00280    void adaptTempUpdate(int step, int minimize = 0);
00281    void adaptTempWriteRestart(int step);
00282    BigReal *adaptTempPotEnergyAveNum;
00283    BigReal *adaptTempPotEnergyAveDen;
00284    BigReal *adaptTempPotEnergyVarNum;
00285    BigReal *adaptTempPotEnergyAve;
00286    BigReal *adaptTempPotEnergyVar;
00287    int     *adaptTempPotEnergySamples;
00288    BigReal *adaptTempBetaN;
00289    BigReal adaptTempT;
00290    BigReal adaptTempDTave;
00291    BigReal adaptTempDTavenum;
00292    BigReal adaptTempBetaMin;
00293    BigReal adaptTempBetaMax;
00294    int     adaptTempBin;
00295    int     adaptTempBins;
00296    BigReal adaptTempDBeta;
00297    BigReal adaptTempCg;
00298    BigReal adaptTempDt;
00299    Bool    adaptTempAutoDt;
00300    BigReal adaptTempDtMin;
00301    BigReal adaptTempDtMax;
00302    ofstream_namd adaptTempRestartFile;
00303   
00304 private:
00305     CthThread thread;
00306     static void threadRun(Controller*);
00307 
00308     double startCTime;
00309     double startWTime;
00310     double firstCTime;
00311     double firstWTime;
00312     double startBenchTime;
00313 
00314     int computesPartitioned;
00315 };
00316 
00317 //Modifications for alchemical fep
00318 static char *FEPTITLE(int X)
00319 {
00320   static char tmp_string[21];
00321   sprintf(tmp_string, "FepEnergy: %6d ",X);
00322   return tmp_string;
00323 }
00324 
00325 static char *FEPTITLE2(int X)
00326 {
00327   static char tmp_string[21];
00328   sprintf(tmp_string, "FEP:    %7d",X);
00329   return tmp_string;
00330 }
00331 
00332 static char *TITITLE(int X)
00333 {
00334   static char tmp_string[21];
00335   sprintf(tmp_string, "TI:     %7d",X);
00336   return tmp_string;
00337 }
00338 //fepe
00339 
00340 #endif // CONTROLLER_H
00341 

Generated on Fri Sep 22 01:17:12 2017 for NAMD by  doxygen 1.4.7