00001
00007 #include "InfoStream.h"
00008 #include "ComputeBonds.h"
00009 #include "Molecule.h"
00010 #include "Parameters.h"
00011 #include "Node.h"
00012 #include "ReductionMgr.h"
00013 #include "Lattice.h"
00014 #include "PressureProfile.h"
00015 #include "Debug.h"
00016
00017 #if 0
00018 void BondElem::loadTuplesForAtom
00019 (void *voidlist, AtomID atomID, Molecule *molecule)
00020 {
00021 DebugM(1, "::loadTuplesForAtom - atomID " << atomID << std::endl );
00022 UniqueSet<BondElem> &bondList =
00023 *( (UniqueSet<BondElem>*) voidlist );
00024
00025 DebugM(1, "::loadTuplesForAtom - current list size " << bondList.size() << std::endl );
00026
00027
00028 int *bonds = molecule->get_bonds_for_atom(atomID);
00029 DebugM(1, "::loadTuplesForAtom - atomID " << atomID << std::endl );
00030
00031
00032 int bondNum = *bonds;
00033 while(bondNum != -1)
00034 {
00035
00036 DebugM(1, "::loadTuplesForAtom - loading bond " << bondNum << std::endl );
00037 bondList.add(BondElem(molecule->get_bond(bondNum)));
00038 bondNum = *(++bonds);
00039 }
00040 }
00041 #endif
00042
00043
00044 int BondElem::pressureProfileSlabs = 0;
00045 int BondElem::pressureProfileAtomTypes = 1;
00046 BigReal BondElem::pressureProfileThickness = 0;
00047 BigReal BondElem::pressureProfileMin = 0;
00048
00049 void BondElem::getMoleculePointers
00050 (Molecule* mol, int* count, int32*** byatom, Bond** structarray)
00051 {
00052 #ifdef MEM_OPT_VERSION
00053 NAMD_die("Should not be called in BondElem::getMoleculePointers in memory optimized version!");
00054 #else
00055 *count = mol->numBonds;
00056 *byatom = mol->bondsByAtom;
00057 *structarray = mol->bonds;
00058 #endif
00059 }
00060
00061 void BondElem::getParameterPointers(Parameters *p, const BondValue **v) {
00062 *v = p->bond_array;
00063 }
00064
00065 void BondElem::computeForce(BigReal *reduction,
00066 BigReal *pressureProfileData)
00067 {
00068 DebugM(1, "::computeForce() localIndex = " << localIndex[0] << " "
00069 << localIndex[1] << std::endl);
00070
00071 BigReal r;
00072 BigReal diff;
00073 BigReal energy;
00074
00075
00076
00077
00078 Real k = value->k * scale;
00079 Real x0 = value->x0;
00080
00081
00082 const Lattice & lattice = p[0]->p->lattice;
00083 const Vector r12 = lattice.delta(p[0]->x[localIndex[0]].position,
00084 p[1]->x[localIndex[1]].position);
00085 r = r12.length();
00086
00087
00088 diff = r - x0;
00089
00090
00091 energy = k*diff*diff;
00092
00093
00094 diff *= -2.0*k;
00095
00096
00097 const Force f12 = r12 * (diff/r);
00098
00099
00100 p[0]->f[localIndex[0]] += f12;
00101 p[1]->f[localIndex[1]] -= f12;
00102
00103 DebugM(3, "::computeForce() -- ending with delta energy " << energy << std::endl);
00104 reduction[bondEnergyIndex] += energy;
00105 reduction[virialIndex_XX] += f12.x * r12.x;
00106 reduction[virialIndex_XY] += f12.x * r12.y;
00107 reduction[virialIndex_XZ] += f12.x * r12.z;
00108 reduction[virialIndex_YX] += f12.y * r12.x;
00109 reduction[virialIndex_YY] += f12.y * r12.y;
00110 reduction[virialIndex_YZ] += f12.y * r12.z;
00111 reduction[virialIndex_ZX] += f12.z * r12.x;
00112 reduction[virialIndex_ZY] += f12.z * r12.y;
00113 reduction[virialIndex_ZZ] += f12.z * r12.z;
00114
00115 if (pressureProfileData) {
00116 BigReal z1 = p[0]->x[localIndex[0]].position.z;
00117 BigReal z2 = p[1]->x[localIndex[1]].position.z;
00118 int n1 = (int)floor((z1-pressureProfileMin)/pressureProfileThickness);
00119 int n2 = (int)floor((z2-pressureProfileMin)/pressureProfileThickness);
00120 pp_clamp(n1, pressureProfileSlabs);
00121 pp_clamp(n2, pressureProfileSlabs);
00122 int p1 = p[0]->x[localIndex[0]].partition;
00123 int p2 = p[1]->x[localIndex[1]].partition;
00124 int pn = pressureProfileAtomTypes;
00125 pp_reduction(pressureProfileSlabs,
00126 n1, n2,
00127 p1, p2, pn,
00128 f12.x * r12.x, f12.y * r12.y, f12.z * r12.z,
00129 pressureProfileData);
00130 }
00131 }
00132
00133 void BondElem::submitReductionData(BigReal *data, SubmitReduction *reduction)
00134 {
00135 reduction->item(REDUCTION_BOND_ENERGY) += data[bondEnergyIndex];
00136 ADD_TENSOR(reduction,REDUCTION_VIRIAL_NORMAL,data,virialIndex);
00137 }
00138