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 
00180     void stochRescaleVelocities(int);
00181 
00182     int stochRescale_count;
00185     BigReal stochRescaleTimefactor;
00189     void berendsenPressure(int);
00190       // Tensor berendsenPressure_avg;
00191       // int berendsenPressure_count;
00192     void langevinPiston1(int);
00193     void langevinPiston2(int);
00194       Tensor langevinPiston_origStrainRate;
00195       Tensor strainRate_old;  // for langevinPistonBarrier no
00196       Tensor positionRescaleFactor;  // for langevinPistonBarrier no
00197 
00198     void multigratorPressure(int step, int callNumber);
00199     BigReal multigratorXi;
00200     BigReal multigratorXiT;
00201     Tensor momentumSqrSum;
00202     void multigratorTemperature(int step, int callNumber);
00203     std::vector<BigReal> multigratorNu;
00204     std::vector<BigReal> multigratorNuT;
00205     std::vector<BigReal> multigratorOmega;
00206     std::vector<BigReal> multigratorZeta;
00207     RequireReduction *multigratorReduction;
00208     BigReal multigatorCalcEnthalpy(BigReal potentialEnergy, int step, int minimize);
00209 
00210     int ldbSteps;
00211     void rebalanceLoad(int);
00212       int fflush_count;
00213     void cycleBarrier(int,int); 
00214         
00215         void traceBarrier(int, int);
00216 
00217 #ifdef MEASURE_NAMD_WITH_PAPI
00218         void papiMeasureBarrier(int, int);
00219 #endif
00220 
00221     // void suspend(void) { CthSuspend(); };
00222     void terminate(void);
00223 
00224     Random *random;
00225     SimParameters *const simParams;     // for convenience
00226     NamdState *const state;             // access data in state
00227     RequireReduction *reduction;
00228     RequireReduction *amd_reduction;
00229     SubmitReduction *submit_reduction;
00230 
00231     // data for pressure profile reductions and output
00232     PressureProfileReduction *ppbonded;
00233     PressureProfileReduction *ppnonbonded;
00234     PressureProfileReduction *ppint;
00235     int pressureProfileSlabs;
00236     int pressureProfileCount;
00237     BigReal *pressureProfileAverage;
00238 
00239     CollectionMaster *const collection;
00240     
00241     ControllerBroadcasts * broadcast;
00242     ofstream_namd xstFile;
00243     void outputExtendedSystem(int step);
00244     void writeExtendedSystemLabels(ofstream_namd &file);
00245     void writeExtendedSystemData(int step, ofstream_namd &file);
00246 
00247 //fepb
00248     ofstream_namd fepFile;
00249     void outputFepEnergy(int step);
00250     void writeFepEnergyData(int step, ofstream_namd &file);
00251 //fepe
00252     ofstream_namd tiFile;
00253     void outputTiEnergy(int step);
00254     BigReal computeAlchWork(const int step);
00255     void writeTiEnergyData(int step, ofstream_namd &file);
00256 
00257     // for checkpoint/revert
00258     int checkpoint_stored;
00259     Lattice checkpoint_lattice;
00260     ControllerState checkpoint_state;
00261 
00262     struct checkpoint {
00263       Lattice lattice;
00264       ControllerState state;
00265     };
00266     std::map<std::string,checkpoint*> checkpoints;
00267     int checkpoint_task;
00268     void recvCheckpointReq(const char *key, int task, checkpoint &cp);
00269     void recvCheckpointAck(checkpoint &cp);
00270 
00271     Lattice origLattice;
00272 
00273 //for accelMD
00274    inline void calc_accelMDG_mean_std
00275    (BigReal testV, int step_n, 
00276     BigReal *Vmax, BigReal *Vmin, BigReal *Vavg, BigReal *M2, BigReal *sigmaV);
00277 
00278    inline void calc_accelMDG_E_k
00279    (int iE, int V_n, BigReal sigma0, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, 
00280     BigReal* k0, BigReal* k, BigReal* E, int* iEused, char *warn);
00281 
00282    inline void calc_accelMDG_force_factor
00283    (BigReal k, BigReal E, BigReal testV, Tensor vir_orig,
00284     BigReal *dV, BigReal *factor, Tensor *vir);
00285 
00286    void write_accelMDG_rest_file
00287        (int step_n, char type, int V_n, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, BigReal M2,
00288         BigReal E, BigReal k, bool write_topic, bool lasttime);
00289 
00290    void rescaleaccelMD (int step, int minimize = 0);
00291    BigReal accelMDdVAverage;
00292 
00293 //JS for adaptive temperature sampling
00294    void adaptTempInit(int step);
00295    void adaptTempUpdate(int step, int minimize = 0);
00296    void adaptTempWriteRestart(int step);
00297    BigReal *adaptTempPotEnergyAveNum;
00298    BigReal *adaptTempPotEnergyAveDen;
00299    BigReal *adaptTempPotEnergyVarNum;
00300    BigReal *adaptTempPotEnergyAve;
00301    BigReal *adaptTempPotEnergyVar;
00302    int     *adaptTempPotEnergySamples;
00303    BigReal *adaptTempBetaN;
00304    BigReal adaptTempT;
00305    BigReal adaptTempDTave;
00306    BigReal adaptTempDTavenum;
00307    BigReal adaptTempBetaMin;
00308    BigReal adaptTempBetaMax;
00309    int     adaptTempBin;
00310    int     adaptTempBins;
00311    BigReal adaptTempDBeta;
00312    BigReal adaptTempCg;
00313    BigReal adaptTempDt;
00314    Bool    adaptTempAutoDt;
00315    BigReal adaptTempDtMin;
00316    BigReal adaptTempDtMax;
00317    ofstream_namd adaptTempRestartFile;
00318   
00319 private:
00320     CthThread thread;
00321     static void threadRun(Controller*);
00322 
00323     double startCTime;
00324     double startWTime;
00325     double firstCTime;
00326     double firstWTime;
00327     double startBenchTime;
00328 
00329     int computesPartitioned;
00330 };
00331 
00332 //Modifications for alchemical fep
00333 static char *FEPTITLE(int X)
00334 {
00335   static char tmp_string[21];
00336   sprintf(tmp_string, "FepEnergy: %6d ",X);
00337   return tmp_string;
00338 }
00339 
00340 static char *FEPTITLE2(int X)
00341 {
00342   static char tmp_string[21];
00343   sprintf(tmp_string, "FEP:    %7d",X);
00344   return tmp_string;
00345 }
00346 
00347 static char *TITITLE(int X)
00348 {
00349   static char tmp_string[21];
00350   sprintf(tmp_string, "TI:     %7d",X);
00351   return tmp_string;
00352 }
00353 //fepe
00354 
00355 #endif // CONTROLLER_H
00356 

Generated on Sat May 26 01:17:12 2018 for NAMD by  doxygen 1.4.7