00001
00007 #include "Node.h"
00008 #include "Molecule.h"
00009 #include "NamdTypes.h"
00010 #include "GlobalMaster.h"
00011
00012
00013 #define MIN_DEBUG_LEVEL 1
00014 #include "Debug.h"
00015
00016 void GlobalMaster::processData(AtomIDList::iterator a_i,
00017 AtomIDList::iterator a_e,
00018 PositionList::iterator p_i,
00019 PositionList::iterator g_i,
00020 PositionList::iterator g_e,
00021 AtomIDList::iterator last_atoms_forced_i,
00022 AtomIDList::iterator last_atoms_forced_e,
00023 ForceList::iterator last_forces_i,
00024 AtomIDList::iterator forceid_i,
00025 AtomIDList::iterator forceid_e,
00026 ForceList::iterator totalforce_i) {
00027 atomIdBegin = a_i;
00028 atomIdEnd = a_e;
00029 atomPositionBegin = p_i;
00030 groupPositionBegin = g_i;
00031 groupPositionEnd = g_e;
00032 lastAtomsForcedBegin = last_atoms_forced_i;
00033 lastAtomsForcedEnd = last_atoms_forced_e;
00034 lastForcesBegin = last_forces_i;
00035 forceIdBegin = forceid_i;
00036 forceIdEnd = forceid_e;
00037 totalForceBegin = totalforce_i;
00038
00039 calculate();
00040
00041
00042 if(appForcesChanged) {
00043 if(fAtoms.size() != appForces.size())
00044 NAMD_die("# of atoms forced != # of forces given");
00045 }
00046 if(appForcesChanged) {
00047 if(reqGroups.size() != grpForces.size())
00048 NAMD_die("# of groups forced != # of groups requested");
00049 }
00050
00051
00052 if(reqGroupsChanged) {
00053 groupMasses.resize(0);
00054
00055
00056 Molecule *mol = Node::Object()->molecule;
00057
00058
00059 int g;
00060 for(g=0;g<reqGroups.size();g++) {
00061 AtomIDList &atom_list = reqGroups[g];
00062 BigReal mass = 0;
00063 int a;
00064 for(a=0;a<atom_list.size();a++) {
00065 mass += mol->atommass(a);
00066 }
00067 groupMasses.add(mass);
00068 }
00069 }
00070 }
00071
00072 void GlobalMaster::check() const {
00073
00074 if(fAtoms.size() != appForces.size())
00075 NAMD_die("# of atoms forced != # of forces given");
00076 if(reqGroups.size() != grpForces.size())
00077 NAMD_die("# of groups forced != # of groups requested");
00078 }
00079
00080 void GlobalMaster::clearChanged() {
00081 reqAtomsChanged = false;
00082 appForcesChanged = false;
00083 reqGroupsChanged = false;
00084 }
00085
00086 void GlobalMaster::calculate() {
00087 NAMD_die("Internal error: pure virtual function called");
00088 }
00089
00090 GlobalMaster::GlobalMaster() {
00091 step = -1;
00092 clearChanged();
00093 }
00094
00095 bool GlobalMaster::changedAtoms() {
00096 return reqAtomsChanged;
00097 }
00098
00099 bool GlobalMaster::changedForces() {
00100 return appForcesChanged;
00101 }
00102
00103 bool GlobalMaster::changedGroups() {
00104 return reqGroupsChanged;
00105 }
00106
00107 const AtomIDList &GlobalMaster::requestedAtoms() {
00108 return reqAtoms;
00109 }
00110
00111 AtomIDList &GlobalMaster::modifyRequestedAtoms() {
00112 reqAtomsChanged = true;
00113 return reqAtoms;
00114 }
00115
00116 const AtomIDList &GlobalMaster::forcedAtoms() {
00117 return fAtoms;
00118 }
00119
00120 const ForceList &GlobalMaster::appliedForces() {
00121 return appForces;
00122 }
00123
00124 const ForceList &GlobalMaster::groupForces() {
00125 return grpForces;
00126 }
00127
00128 const ResizeArray<AtomIDList> &GlobalMaster::requestedGroups() {
00129 return reqGroups;
00130 }
00131
00132 AtomIDList &GlobalMaster::modifyForcedAtoms() {
00133 appForcesChanged = true;
00134 return fAtoms;
00135 }
00136
00137 ForceList &GlobalMaster::modifyAppliedForces() {
00138 appForcesChanged = true;
00139 return appForces;
00140 }
00141
00142 ForceList &GlobalMaster::modifyGroupForces() {
00143
00144 appForcesChanged = true;
00145 return grpForces;
00146 }
00147
00148 ResizeArray<AtomIDList> &GlobalMaster::modifyRequestedGroups() {
00149 reqGroupsChanged = true;
00150 DebugM(1,"Groups have changed.\n");
00151 return reqGroups;
00152 }
00153
00154 AtomIDList::const_iterator GlobalMaster::getAtomIdBegin() {
00155 return atomIdBegin;
00156 }
00157
00158 AtomIDList::const_iterator GlobalMaster::getAtomIdEnd() {
00159 return atomIdEnd;
00160 }
00161
00162 PositionList::const_iterator GlobalMaster::getAtomPositionBegin() {
00163 return atomPositionBegin;
00164 }
00165
00166 PositionList::const_iterator GlobalMaster::getGroupPositionBegin() {
00167 return groupPositionBegin;
00168 }
00169
00170 PositionList::const_iterator GlobalMaster::getGroupPositionEnd() {
00171 return groupPositionEnd;
00172 }
00173
00174 ResizeArray<BigReal>::const_iterator GlobalMaster::getGroupMassBegin()
00175 {
00176 return groupMasses.begin();
00177 }
00178
00179 ResizeArray<BigReal>::const_iterator GlobalMaster::getGroupMassEnd() {
00180 return groupMasses.end();
00181 }
00182
00183 AtomIDList::const_iterator GlobalMaster::getLastAtomsForcedBegin() {
00184 return lastAtomsForcedBegin;
00185 }
00186
00187 AtomIDList::const_iterator GlobalMaster::getLastAtomsForcedEnd() {
00188 return lastAtomsForcedEnd;
00189 }
00190
00191 ForceList::const_iterator GlobalMaster::getLastForcesBegin() {
00192 return lastForcesBegin;
00193 }
00194
00195 AtomIDList::const_iterator GlobalMaster::getForceIdBegin()
00196 {
00197 return forceIdBegin;
00198 }
00199
00200 AtomIDList::const_iterator GlobalMaster::getForceIdEnd()
00201 {
00202 return forceIdEnd;
00203 }
00204
00205 ForceList::const_iterator GlobalMaster::getTotalForce()
00206 {
00207 return totalForceBegin;
00208 }