GlobalMasterEasy.C

Go to the documentation of this file.
00001 
00007 /*
00008    Forwards atoms to master node for force evaluation.
00009 */
00010 
00011 #include "InfoStream.h"
00012 #include "Node.h"
00013 #include "PatchMap.h"
00014 #include "PatchMap.inl"
00015 #include "AtomMap.h"
00016 
00017 #include "GlobalMaster.h"
00018 #include "GlobalMasterEasy.h"
00019 
00020 #include "PatchMgr.h"
00021 #include "Molecule.h"
00022 #include "ReductionMgr.h"
00023 #include "ComputeMgr.h"
00024 #include "ComputeMgr.decl.h"
00025 #include <stdio.h>
00026 
00027 //#define DEBUGM
00028 #define MIN_DEBUG_LEVEL 1
00029 #include "Debug.h"
00030 
00031 
00032 GlobalMasterEasy::GlobalMasterEasy(const char *the_config_name) {
00033   DebugM(1,"Here\n");
00034 
00035   molecule = Node::Object()->molecule;
00036   int len = strlen(the_config_name);
00037   configName = new char[len+1];
00038   strcpy(configName,the_config_name);
00039 
00040   reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00041 
00042   initialize();
00043 }
00044 
00045 GlobalMasterEasy::~GlobalMasterEasy() {
00046   delete [] configName;
00047   delete reduction;
00048 }
00049 
00050 int GlobalMasterEasy::
00051         getAtomID(const char *segid, int resid, const char *aname)
00052 {
00053   return molecule->get_atom_from_name(segid,resid,aname);
00054 }
00055 
00056 int GlobalMasterEasy::
00057         getNumAtoms(const char* segid, int resid) // 0 on error
00058 {
00059   return molecule->get_residue_size(segid,resid);
00060 }
00061 
00062 int GlobalMasterEasy::
00063         getAtomID(const char *segid, int resid, int index)
00064 {
00065   return molecule->get_atom_from_index_in_residue(segid,resid,index);
00066 }
00067 
00068 double GlobalMasterEasy::getMass(int atomid)
00069 {
00070   if ( atomid < 0 || atomid >= molecule->numAtoms ) return -1.;  // failure
00071   return molecule->atommass(atomid);
00072 }
00073 
00074 
00075 int GlobalMasterEasy::requestAtom(int atomid)
00076 {
00077   if ( atomid < 0 || atomid >= molecule->numAtoms ) return -1;  // failure
00078   modifyRequestedAtoms().add(atomid);
00079   return 0;  // success
00080 }
00081 
00082 int GlobalMasterEasy::getPosition(int atomid, Position &position)
00083 {
00084   AtomIDList::const_iterator a_i = getAtomIdBegin();
00085   AtomIDList::const_iterator a_e = getAtomIdEnd();
00086   PositionList::const_iterator p_i = getAtomPositionBegin();
00087   for ( ; a_i != a_e; ++a_i, ++p_i ) {
00088     if ( *a_i == atomid ) {
00089       position = *p_i;
00090       return 0;  // success
00091     }
00092   }
00093   return -1;  // failure
00094 }
00095 
00096 int GlobalMasterEasy::addForce(int atomid, Force force)
00097 {
00098   if ( atomid < 0 || atomid >= molecule->numAtoms ) return -1;  // failure
00099   modifyForcedAtoms().add(atomid);
00100   modifyAppliedForces().add(force);
00101   return 0;  // success
00102 }
00103 
00104 void GlobalMasterEasy::addEnergy(BigReal e) {
00105   energy += e;
00106 }
00107 
00108 void GlobalMasterEasy::initialize() {
00109   DebugM(1,"Here\n");
00110   DebugM(4,"Initializing master\n");
00111 
00112   // Get the script for subclasses
00113   StringList *script = Node::Object()->configList->find(configName);
00114 
00115   config = new char[1];
00116   config[0] = '\0';
00117 
00118   for ( ; script; script = script->next) {
00119     if ( strstr(script->data,"\n") ) {
00120       size_t add_len = strlen(script->data);
00121       size_t config_len = 0;
00122       config_len = strlen(config);
00123       char *new_config = new char[config_len + add_len + 2];
00124       strcpy(new_config,config);
00125       strcat(new_config,script->data);
00126       strcat(new_config,"\n");  // just to be safe
00127       delete [] config;
00128       config = new_config;
00129     } else {
00130       FILE *infile = fopen(script->data,"r");
00131       if ( ! infile ) {
00132         char errmsg[256];
00133         sprintf(errmsg,"Error trying to read file %s!\n",script->data);
00134         NAMD_die(errmsg);
00135       }
00136       fseek(infile,0,SEEK_END);
00137       size_t add_len = ftell(infile);
00138       size_t config_len = 0;
00139       config_len = strlen(config);
00140       char *new_config = new char[config_len + add_len + 3];
00141       strcpy(new_config,config);
00142       delete [] config;
00143       config = new_config;
00144       new_config += config_len;
00145       rewind(infile);
00146       fread(new_config,sizeof(char),add_len,infile);
00147       new_config += add_len;
00148       new_config[0] = '\n';
00149       new_config[1] = '\0';
00150       fclose(infile);
00151     }
00152   }
00153 
00154 }
00155 
00156 void GlobalMasterEasy::calculate() {
00157   DebugM(1,"Here\n");
00158 
00159   /* zero out the forces */
00160   modifyForcedAtoms().resize(0);
00161   modifyAppliedForces().resize(0);
00162 
00163   /* XXX is this necessary? */
00164   modifyGroupForces().resize(getGroupMassEnd() - getGroupMassBegin());
00165   modifyGroupForces().setall(Vector(0,0,0));
00166   energy = 0.0;
00167 
00168   // Build results here
00169   easy_calc();
00170 
00171   reduction->item(REDUCTION_MISC_ENERGY) += energy;
00172   reduction->submit();
00173 }
00174 
00175 void GlobalMasterEasy::easy_init(const char *) {
00176   CkPrintf("Default GlobalMasterEasy::easy_init() called.\n");
00177 }
00178 
00179 void GlobalMasterEasy::easy_calc() {
00180   CkPrintf("Default GlobalMasterEasy::easy_calc() called.\n");
00181 }

Generated on Sun Nov 19 01:17:13 2017 for NAMD by  doxygen 1.4.7