void destroy(const IdType classId, const IdType objectId) { #ifndef PMI_OPTIMIZE // check whether the class has an associated constructorCaller if (classId >= destructorCallers.size()) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "does not have a destructorCaller for class id " \ << classId << "."); // check if the object is defined if (objectId >= objects.size() || objects[objectId] == NULL) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "does not have an initialized object at object id " \ << objectId << " (destroy)."); // TODO: check if object is of the right class PMI_REPORT_OK; #endif // delete object LOG4ESPP_INFO(logger, printWorkerId() \ << "destroys object id " << objectId \ << " of class id " << classId << "."); void* voidPtr = objects[objectId]; DestructorCallerType dc = destructorCallers[classId]; (*dc)(voidPtr); objects[objectId] = NULL; }
////////////////////////////////////////////////// // INLINE IMPLEMENTATION ////////////////////////////////////////////////// template < typename _DihedralPotential > inline void FixedQuadrupleListInteractionTemplate < _DihedralPotential >:: addForces() { LOG4ESPP_INFO(theLogger, "add forces computed by FixedQuadrupleList"); const bc::BC& bc = *getSystemRef().bc; // boundary conditions for (FixedQuadrupleList::QuadrupleList::Iterator it(*fixedquadrupleList); it.isValid(); ++it) { Particle &p1 = *it->first; Particle &p2 = *it->second; Particle &p3 = *it->third; Particle &p4 = *it->fourth; Real3D dist21, dist32, dist43; // bc.getMinimumImageVectorBox(dist21, p2.position(), p1.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); bc.getMinimumImageVectorBox(dist43, p4.position(), p3.position()); Real3D force1, force2, force3, force4; // result forces potential->_computeForce(force1, force2, force3, force4, dist21, dist32, dist43); p1.force() += force1; p2.force() += force2; //p2.force() -= force2; p3.force() += force3; p4.force() += force4; } }
void create(const IdType classId, const IdType objectId) { #ifndef PMI_OPTIMIZE // check whether the class has an associated constructorCaller if (classId >= constructorCallers.size()) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "does not have a constructorCaller for class id " \ << classId << "."); // check whether the object is already defined if (objectId < objects.size() && objects[objectId] != NULL) { PMI_REPORT_INTL_ERROR(printWorkerId() \ << "has object id " \ << objectId << " already defined."); } else if (objectId >= objects.size()+1) { PMI_REPORT_INTL_ERROR(printWorkerId() \ << ": object id " << objectId \ << " overshoots (size " << objects.size() \ << ")."); } PMI_REPORT_OK; #endif LOG4ESPP_INFO(logger, printWorkerId() \ << "creates an instance of class id " \ << classId << ", object id is " << objectId << "."); // create object ConstructorCallerType cc = constructorCallers[classId]; if (objectId == objects.size()) objects.push_back((*cc)()); else objects[objectId] = (*cc)(); }
void invoke(const IdType classId, const IdType methodId, const IdType objectId) { #ifndef PMI_OPTIMIZE // check whether the method has an associated methodCaller if (methodId >= methodCallers.size()) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "does not have a methodCaller for method id " \ << methodId << "."); if (objectId >= objects.size() || objects[objectId] == NULL) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "does not have an initialized object at object id " \ << objectId << " (invoke)."); // TODO: check if object is of the right class PMI_REPORT_OK; #endif // call method LOG4ESPP_INFO(logger, printWorkerId() \ << "invokes method id " << methodId \ << " of object id " << objectId \ << " of class id " << classId << "."); void* voidPtr = objects[objectId]; MethodCallerType mc = methodCallers[methodId]; (*mc)(voidPtr); }
inline real FixedTripleListTypesInteractionTemplate<_Potential>:: computeVirial() { LOG4ESPP_INFO(theLogger, "compute the virial for the FixedTriple List with types"); real w = 0.0; const bc::BC &bc = *getSystemRef().bc; // boundary conditions for (FixedTripleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; int type1 = p1.type(); int type2 = p2.type(); int type3 = p3.type(); const Potential &potential = getPotential(type1, type2, type3); Real3D dist12, dist32; bc.getMinimumImageVectorBox(dist12, p1.position(), p2.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); Real3D force12, force32; potential._computeForce(force12, force32, dist12, dist32); w += dist12 * force12 + dist32 * force32; } // reduce over all CPUs real wsum; boost::mpi::all_reduce(*mpiWorld, w, wsum, std::plus<real>()); return wsum; }
inline void FixedQuadrupleListInteractionTemplate < _DihedralPotential >:: computeVirialTensor(Tensor& w) { LOG4ESPP_INFO(theLogger, "compute the virial tensor of the quadruples"); Tensor wlocal(0.0); const bc::BC& bc = *getSystemRef().bc; for (FixedQuadrupleList::QuadrupleList::Iterator it(*fixedquadrupleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; const Particle &p4 = *it->fourth; Real3D dist21, dist32, dist43; bc.getMinimumImageVectorBox(dist21, p2.position(), p1.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); bc.getMinimumImageVectorBox(dist43, p4.position(), p3.position()); Real3D force1, force2, force3, force4; potential->_computeForce(force1, force2, force3, force4, dist21, dist32, dist43); // TODO: formulas are not correct yet wlocal += Tensor(dist21, force1) - Tensor(dist32, force2); } // reduce over all CPUs Tensor wsum(0.0); boost::mpi::all_reduce(*mpiWorld, (double*)&wlocal, 6, (double*)&wsum, std::plus<double>()); w += wsum; }
////////////////////////////////////////////////// // INLINE IMPLEMENTATION ////////////////////////////////////////////////// template < typename _Potential > inline void FixedPairListTypesInteractionTemplate < _Potential >::addForces() { LOG4ESPP_INFO(theLogger, "add forces computed by the FixedPair List"); const bc::BC& bc = *getSystemRef().bc; for (FixedPairList::PairList::Iterator it(*fixedpairList); it.isValid(); ++it) { Particle &p1 = *it->first; Particle &p2 = *it->second; int type1 = p1.type(); int type2 = p2.type(); const Potential &potential = getPotential(type1, type2); // shared_ptr<Potential> potential = getPotential(type1, type2); Real3D force(0.0); //if(potential._computeForce(force, p1, p2)) { ////if(potential->_computeForce(force, p1, p2)) { // p1.force() += force; // p2.force() -= force; // LOG4ESPP_TRACE(theLogger, "id1=" << p1.id() << " id2=" << p2.id() << " force=" << force); //} Real3D dist; bc.getMinimumImageVectorBox(dist, p1.position(), p2.position()); if(potential._computeForce(force, p1, p2, dist)) { p1.force() += force; p2.force() -= force; } } }
inline real FixedQuadrupleListInteractionTemplate < _DihedralPotential >:: computeVirial() { LOG4ESPP_INFO(theLogger, "compute scalar virial of the quadruples"); real w = 0.0; const bc::BC& bc = *getSystemRef().bc; // boundary conditions for (FixedQuadrupleList::QuadrupleList::Iterator it(*fixedquadrupleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; const Particle &p4 = *it->fourth; Real3D dist21, dist32, dist43; bc.getMinimumImageVectorBox(dist21, p2.position(), p1.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); bc.getMinimumImageVectorBox(dist43, p4.position(), p3.position()); Real3D force1, force2, force3, force4; potential->_computeForce(force1, force2, force3, force4, dist21, dist32, dist43); // TODO: formulas are not correct yet? w += dist21 * force1 + dist32 * force2; } real wsum; boost::mpi::all_reduce(*mpiWorld, w, wsum, std::plus<real>()); return w; }
template < typename _AngularPotential > inline void FixedTripleAngleListInteractionTemplate < _AngularPotential >:: computeVirialTensor(Tensor *w, int n) { LOG4ESPP_INFO(theLogger, "compute the virial tensor of the triples"); std::cout << "Warning! At the moment IK computeVirialTensor for fixed triples does'n work"<<std::endl; }
inline void FixedTripleListTypesInteractionTemplate<_Potential>::computeVirialTensor(Tensor &w) { LOG4ESPP_INFO(theLogger, "compute the virial tensor for the FixedTriple List"); Tensor wlocal(0.0); const bc::BC& bc = *getSystemRef().bc; for (FixedTripleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; int type1 = p1.type(); int type2 = p2.type(); int type3 = p3.type(); const Potential &potential = getPotential(type1, type2, type3); Real3D r12, r32; bc.getMinimumImageVectorBox(r12, p1.position(), p2.position()); bc.getMinimumImageVectorBox(r32, p3.position(), p2.position()); Real3D force12, force32; potential._computeForce(force12, force32, r12, r32); wlocal += Tensor(r12, force12) + Tensor(r32, force32); } // reduce over all CPUs Tensor wsum(0.0); boost::mpi::all_reduce(*mpiWorld, wlocal, wsum, std::plus<Tensor>()); w += wsum; }
template < typename _AngularPotential > inline void FixedTripleAngleListInteractionTemplate < _AngularPotential >:: computeVirialTensor(Tensor& w) { LOG4ESPP_INFO(theLogger, "compute the virial tensor of the triples"); Tensor wlocal(0.0); const bc::BC& bc = *getSystemRef().bc; for (FixedTripleAngleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it){ const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; //const Potential &potential = getPotential(0, 0); Real3D r12, r32; bc.getMinimumImageVectorBox(r12, p1.position(), p2.position()); bc.getMinimumImageVectorBox(r32, p3.position(), p2.position()); Real3D force12, force32; real currentAngle = fixedtripleList->getAngle(p1.getId(), p2.getId(), p3.getId()); potential->_computeForce(force12, force32, r12, r32, currentAngle); wlocal += Tensor(r12, force12) + Tensor(r32, force32); } // reduce over all CPUs Tensor wsum(0.0); boost::mpi::all_reduce(*mpiWorld, (double*)&wlocal,6, (double*)&wsum, std::plus<double>()); w += wsum; }
inline real FixedTripleListTypesInteractionTemplate<_Potential>:: computeEnergy() { LOG4ESPP_INFO(theLogger, "compute energy of the FixedTriple list pairs"); real e = 0.0; const bc::BC &bc = *getSystemRef().bc; // boundary conditions for (FixedTripleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; int type1 = p1.type(); int type2 = p2.type(); int type3 = p3.type(); const Potential &potential = getPotential(type1, type2, type3); Real3D dist12 = bc.getMinimumImageVector(p1.position(), p2.position()); Real3D dist32 = bc.getMinimumImageVector(p3.position(), p2.position()); e += potential._computeEnergy(dist12, dist32); LOG4ESPP_TRACE(theLogger, "id1=" << p1.id() << " id2=" << p2.id() << " id3=" << p3.id() << " potential energy=" << e); } // reduce over all CPUs real esum; boost::mpi::all_reduce(*mpiWorld, e, esum, std::plus<real>()); return esum; }
template < typename _AngularPotential > inline real FixedTripleAngleListInteractionTemplate < _AngularPotential >:: computeVirial() { LOG4ESPP_INFO(theLogger, "compute scalar virial of the triples"); const bc::BC& bc = *getSystemRef().bc; real w = 0.0; for (FixedTripleAngleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; //const Potential &potential = getPotential(p1.type(), p2.type()); const espresso::bc::BC& bc = *getSystemRef().bc; Real3D dist12, dist32; bc.getMinimumImageVectorBox(dist12, p1.position(), p2.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); Real3D force12, force32; real currentAngle = fixedtripleList->getAngle(p1.getId(), p2.getId(), p3.getId()); potential->_computeForce(force12, force32, dist12, dist32, currentAngle); w += dist12 * force12 + dist32 * force32; } real wsum; boost::mpi::all_reduce(*mpiWorld, w, wsum, std::plus<real>()); return wsum; }
template < typename _Potential > inline real FixedPairListTypesInteractionTemplate < _Potential >:: computeVirial() { LOG4ESPP_INFO(theLogger, "compute the virial for the Fixed Pair List with types"); std::cout << "Warning! computeVirial in FixedPairListTypesInteractionTemplate has not been tested." << std::endl; real w = 0.0; const bc::BC& bc = *getSystemRef().bc; // boundary conditions for (FixedPairList::PairList::Iterator it(*fixedpairList); it.isValid(); ++it) { Particle &p1 = *it->first; Particle &p2 = *it->second; int type1 = p1.type(); int type2 = p2.type(); const Potential &potential = getPotential(type1, type2); // shared_ptr<Potential> potential = getPotential(type1, type2); Real3D force(0.0, 0.0, 0.0); Real3D r21; bc.getMinimumImageVectorBox(r21, p1.position(), p2.position()); if(potential._computeForce(force, p1, p2, r21)) { // if(potential->_computeForce(force, p1, p2)) { //Real3D r21 = p1.position() - p2.position(); w = w + r21 * force; } } // reduce over all CPUs real wsum; boost::mpi::all_reduce(*mpiWorld, w, wsum, std::plus<real>()); return wsum; }
inline real FixedPairListTypesInteractionTemplate < _Potential >:: computeEnergy() { LOG4ESPP_INFO(theLogger, "compute energy of the FixedPair list pairs"); real e = 0.0; real es = 0.0; const bc::BC& bc = *getSystemRef().bc; // boundary conditions for (FixedPairList::PairList::Iterator it(*fixedpairList); it.isValid(); ++it) { Particle &p1 = *it->first; Particle &p2 = *it->second; int type1 = p1.type(); int type2 = p2.type(); const Potential &potential = getPotential(type1, type2); // shared_ptr<Potential> potential = getPotential(type1, type2); Real3D r21; bc.getMinimumImageVectorBox(r21, p1.position(), p2.position()); //e = potential._computeEnergy(p1, p2); // e = potential->_computeEnergy(p1, p2); e = potential._computeEnergy(p1,p2,r21); es += e; LOG4ESPP_TRACE(theLogger, "id1=" << p1.id() << " id2=" << p2.id() << " potential energy=" << e); //std::cout << "id1=" << p1.id() << " id2=" << p2.id() << " potential energy=" << e << std::endl; } // reduce over all CPUs real esum; boost::mpi::all_reduce(*mpiWorld, es, esum, std::plus<real>()); return esum; }
inline real FixedQuadrupleListInteractionTemplate < _DihedralPotential >:: computeEnergy() { LOG4ESPP_INFO(theLogger, "compute energy of the quadruples"); const bc::BC& bc = *getSystemRef().bc; // boundary conditions real e = 0.0; for (FixedQuadrupleList::QuadrupleList::Iterator it(*fixedquadrupleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; const Particle &p4 = *it->fourth; Real3D dist21, dist32, dist43; // bc.getMinimumImageVectorBox(dist21, p2.position(), p1.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); bc.getMinimumImageVectorBox(dist43, p4.position(), p3.position()); e += potential->_computeEnergy(dist21, dist32, dist43); } real esum; boost::mpi::all_reduce(*mpiWorld, e, esum, std::plus<real>()); return esum; }
FixedListComm::~FixedListComm() { //std::cout << "~fixedlist" << std::endl; LOG4ESPP_INFO(theLogger, "~FixedListComm"); con1.disconnect(); con2.disconnect(); con3.disconnect(); }
void FixedListComm::onParticlesChanged() { LOG4ESPP_INFO(theLogger, "rebuild local bond list from global\n"); //this->clear(); longint lastpid1 = -1; Particle* p, * pK; std::vector<Particle*> tmp; GlobalList::const_iterator it = globalLists.begin(); int size = it->second.size()+1; if (size == 2) this->PairList::clear(); else if (size == 3) this->TripleList::clear(); else if (size == 4) this->QuadrupleList::clear(); // iterate through keys of map for (;it != globalLists.end(); ++it) { if (it->first != lastpid1) { // don't check same pid twice pK = storage->lookupRealParticle(it->first); if (pK == NULL) { printf("SERIOUS ERROR: particle %d not available\n", it->first); } lastpid1 = it->first; } // iterate through vector in map for (pvec::const_iterator it2 = it->second.begin(); it2!=it->second.end(); ++it2) { p = storage->lookupLocalParticle(*it2); if (p == NULL) { printf("SERIOUS ERROR: particle %d not available\n", *it2); } tmp.push_back(p); } // add the particles if (size == 2) this->PairList::add(pK, tmp.at(0)); else if (size == 3) this->TripleList::add(pK, tmp.at(0), tmp.at(1)); else if (size == 4) this->QuadrupleList::add(pK, tmp.at(0), tmp.at(1), tmp.at(2)); tmp.clear(); } LOG4ESPP_INFO(theLogger, "regenerated local fixed list from global list"); }
FixedListComm::FixedListComm(shared_ptr <storage::Storage> _storage) : storage(_storage), globalLists(){ //std::cout << "fixedlist" << std::endl; LOG4ESPP_INFO(theLogger, "construct FixedPairList"); con1 = storage->beforeSendParticles.connect (boost::bind(&FixedListComm::beforeSendParticles, this, _1, _2)); con2 = storage->afterRecvParticles.connect (boost::bind(&FixedListComm::afterRecvParticles, this, _1, _2)); con3 = storage->onParticlesChanged.connect (boost::bind(&FixedListComm::onParticlesChanged, this)); }
bool FixedListComm::add(pvec pids) { // ADD THE LOCAL PARTICLES Particle* p; std::vector<Particle*> tmp; pvec::iterator it = pids.begin(); p = storage->lookupRealParticle(*it); //wrong, last particle is key if (!p) return false; tmp.push_back(p); for (++it; it!=pids.end(); ++it) { p = storage->lookupLocalParticle(*it); if (!p) // Particle does not exist here, return false return false; tmp.push_back(p); } //add(tmp); if (pids.size() == 2) this->PairList::add(tmp.at(1), tmp.at(0)); else if (pids.size() == 3) this->TripleList::add(tmp.at(0), tmp.at(2), tmp.at(1)); else if (pids.size() == 4) this->QuadrupleList::add(tmp.at(3), tmp.at(0), tmp.at(1), tmp.at(2)); tmp.clear(); // ADD THE GLOBAL PARTICLES longint pidK = pids.back(); // last pid is key pids.pop_back(); // remove last pid std::pair<GlobalList::const_iterator, GlobalList::const_iterator> equalRange = globalLists.equal_range(pidK); // see whether the particle already has pairs if (equalRange.first == globalLists.end()) { // it hasn't, insert the new pair //globalLists.insert(make_pair(pid1, pid2)); globalLists.insert(make_pair(pidK, pids)); } else {// otherwise test whether the pair already exists for (GlobalList::const_iterator it = equalRange.first; it != equalRange.second; ++it) { if (it->second == pids) { // TODO: Pair already exists, generate error! } // if not, insert the new pair globalLists.insert(equalRange.first, make_pair(pidK, pids)); } } LOG4ESPP_INFO(theLogger, "added fixed pair to global pair list"); return true; }
void FixedListComm::beforeSendParticles (ParticleList& pl, OutBuffer& buf) { std::vector<longint> toSend; // loop over the particle list for (ParticleList::Iterator pit(pl); pit.isValid(); ++pit) { longint pid = pit->id(); LOG4ESPP_DEBUG(theLogger, "send particle with pid " << pid << ", find pairs"); // find all particles that involve this particle id int n = globalLists.count(pid); if (n > 0) { std::pair<GlobalList::const_iterator, GlobalList::const_iterator> equalRange = globalLists.equal_range(pid); // get the length of the vector in the map int l = equalRange.first->second.size(); toSend.reserve(toSend.size()+3+n*l); // first write the pid of the first particle toSend.push_back(pid); // then the number of partners toSend.push_back(n); // then the size of the vector toSend.push_back(l); // and then the pids of the partners for (GlobalList::const_iterator it = equalRange.first; it != equalRange.second; ++it) { // iterate through vector to add pids for (pvec::const_iterator it2=it->second.begin(); it2!=it->second.end(); ++it2) { toSend.push_back(*it2); LOG4ESPP_DEBUG(theLogger, "send global bond: pid " << pid << " and its vector"); } } // delete all of these pairs from the global list globalLists.erase(equalRange.first, equalRange.second); } } // send the list buf.write(toSend); LOG4ESPP_INFO(theLogger, "prepared fixed pair list before send particles"); }
inline void FixedQuadrupleListTypesInteractionTemplate<_DihedralPotential>:: computeVirialTensor(Tensor &w, real z) { LOG4ESPP_INFO(theLogger, "compute the virial tensor of the quadruples"); Tensor wlocal(0.0); const bc::BC &bc = *getSystemRef().bc; std::cout << "Warning!!! computeVirialTensor in specified volume doesn't work for " "FixedQuadrupleListTypesInteractionTemplate at the moment" << std::endl; for (FixedQuadrupleList::QuadrupleList::Iterator it(*fixedquadrupleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; const Particle &p4 = *it->fourth; longint type1 = p1.type(); longint type2 = p2.type(); longint type3 = p3.type(); longint type4 = p4.type(); const Potential &potential = getPotential(type1, type2, type3, type4); Real3D dist21, dist32, dist43; bc.getMinimumImageVectorBox(dist21, p2.position(), p1.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); bc.getMinimumImageVectorBox(dist43, p4.position(), p3.position()); Real3D force1, force2, force3, force4; potential.computeForce(force1, force2, force3, force4, dist21, dist32, dist43); // TODO: formulas are not correct yet wlocal += Tensor(dist21, force1) - Tensor(dist32, force2); } // reduce over all CPUs Tensor wsum(0.0); boost::mpi::all_reduce(*mpiWorld, (double *) &wlocal, 6, (double *) &wsum, std::plus<double>()); w += wsum; }
void associateMethod(const string &name, const IdType id) { if (methodCallersByName().find(name) == methodCallersByName().end()) PMI_REPORT_USER_ERROR(printWorkerId() \ << "has not registered method \"" << name \ << "\" (methodCaller undefined)."); #ifndef PMI_OPTIMIZE // check whether the vector has the right size if (methodCallers.size() != id) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "has " << methodCallers.size() \ << " associated methods, but received id " \ << id << " as the next id."); PMI_REPORT_OK; #endif LOG4ESPP_INFO(logger, printWorkerId() \ << "associates method \"" \ << name << "\" to method id " << id << "."); MethodCallerType mc = methodCallersByName()[name]; methodCallers.push_back(mc); methodCallersByName().erase(name); }
////////////////////////////////////////////////// // INLINE IMPLEMENTATION ////////////////////////////////////////////////// template < typename _AngularPotential > inline void FixedTripleAngleListInteractionTemplate <_AngularPotential>:: addForces() { LOG4ESPP_INFO(theLogger, "add forces computed by FixedTripleAngleList"); const bc::BC& bc = *getSystemRef().bc; // boundary conditions for (FixedTripleAngleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it) { Particle &p1 = *it->first; Particle &p2 = *it->second; Particle &p3 = *it->third; //const Potential &potential = getPotential(p1.type(), p2.type()); Real3D dist12, dist32; bc.getMinimumImageVectorBox(dist12, p1.position(), p2.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); Real3D force12, force32; real currentAngle = fixedtripleList->getAngle(p1.getId(), p2.getId(), p3.getId()); potential->_computeForce(force12, force32, dist12, dist32, currentAngle); p1.force() += force12; p2.force() -= force12 + force32; p3.force() += force32; } }
template < typename _AngularPotential > inline real FixedTripleAngleListInteractionTemplate < _AngularPotential >:: computeEnergy() { LOG4ESPP_INFO(theLogger, "compute energy of the triples"); const bc::BC& bc = *getSystemRef().bc; real e = 0.0; for (FixedTripleAngleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it) { const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; //const Potential &potential = getPotential(p1.type(), p2.type()); Real3D dist12 = bc.getMinimumImageVector(p1.position(), p2.position()); Real3D dist32 = bc.getMinimumImageVector(p3.position(), p2.position()); real currentAngle = fixedtripleList->getAngle(p1.getId(), p2.getId(), p3.getId()); e += potential->_computeEnergy(dist12, dist32, currentAngle); } real esum; boost::mpi::all_reduce(*mpiWorld, e, esum, std::plus<real>()); return esum; }
template < typename _AngularPotential > inline void FixedTripleAngleListInteractionTemplate < _AngularPotential >:: computeVirialTensor(Tensor& w, real z) { LOG4ESPP_INFO(theLogger, "compute the virial tensor of the triples"); std::cout << "Warning! At the moment IK computeVirialTensor for fixed triples does'n work"<<std::endl; /* Tensor wlocal(0.0); const bc::BC& bc = *getSystemRef().bc; for (FixedTripleAngleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it){ const Particle &p1 = *it->first; const Particle &p2 = *it->second; const Particle &p3 = *it->third; Real3D p2pos = p2.position(); if( (p2pos[0]>xmin && p2pos[0]<xmax && p2pos[1]>ymin && p2pos[1]<ymax && p2pos[2]>zmin && p2pos[2]<zmax) ){ Real3D r12, r32; bc.getMinimumImageVectorBox(r12, p1.position(), p2.position()); bc.getMinimumImageVectorBox(r32, p3.position(), p2.position()); Real3D force12, force32; real currentAngle = fixedtripleList->getAngle(p1.getId(), p2.getId(), p3.getId()); potential->_computeForce(force12, force32, r12, r32, currentAngle); wlocal += Tensor(r12, force12) + Tensor(r32, force32); } } // reduce over all CPUs Tensor wsum(0.0); boost::mpi::all_reduce(*mpiWorld, (double*)&wlocal, 6, (double*)&wsum, std::plus<double>()); w += wsum; */ }
void FixedListComm::afterRecvParticles (ParticleList &pl,InBuffer& buf) { std::vector<longint> received, pids; int n, l, tl; longint pid1; GlobalList::iterator it = globalLists.begin(); // receive the bond list buf.read(received); int size = received.size(); int i = 0; while (i < size) { // unpack the list pid1 = received[i++]; n = received[i++]; l = received[i++]; LOG4ESPP_DEBUG(theLogger, "recv particle " << pid1 << ", has " << n << " global pairs"); for (; n > 0; --n) { for (tl = l; tl > 0; --tl) { pids.push_back(received[i++]); } // add the bond to the global list LOG4ESPP_DEBUG(theLogger, "received vector for pid " << pid1); it = globalLists.insert(it, std::make_pair(pid1, pids)); pids.clear(); } } if (i != size) { LOG4ESPP_ERROR(theLogger, "recv particles might have read garbage\n"); } LOG4ESPP_INFO(theLogger, "received fixed particle list after receive particles"); }
inline void FixedTripleListTypesInteractionTemplate<_Potential>::addForces() { LOG4ESPP_INFO(theLogger, "add forces computed by the FixedTriple List"); const bc::BC &bc = *getSystemRef().bc; for (FixedTripleList::TripleList::Iterator it(*fixedtripleList); it.isValid(); ++it) { Particle &p1 = *it->first; Particle &p2 = *it->second; Particle &p3 = *it->third; int type1 = p1.type(); int type2 = p2.type(); int type3 = p3.type(); const Potential &potential = getPotential(type1, type2, type3); Real3D dist12, dist32; bc.getMinimumImageVectorBox(dist12, p1.position(), p2.position()); bc.getMinimumImageVectorBox(dist32, p3.position(), p2.position()); Real3D force12, force32; potential._computeForce(force12, force32, dist12, dist32); p1.force() += force12; p2.force() -= force12 + force32; p3.force() += force32; } }
void associateClass(const string &name, const IdType id) { if (constructorCallersByName().find(name) == constructorCallersByName().end()) PMI_REPORT_USER_ERROR(printWorkerId() \ << "has not registered class \"" << name \ << "\" (constructor undefined)."); #ifndef PMI_OPTIMIZE if (destructorCallersByName().find(name) == destructorCallersByName().end()) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "has not registered class \"" << name \ << "\" (constructur defined, but destructor undefined)."); // check whether the vector has the right size if (constructorCallers.size() != id) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "has " << constructorCallers.size() \ << " associated constructors, but received id " \ << id << " as the next id."); // check whether the vector has the right size if (destructorCallers.size() != id) PMI_REPORT_INTL_ERROR(printWorkerId() \ << "has " << destructorCallers.size() \ << " associated destructors, but received id " \ << id << " as the next id."); PMI_REPORT_OK; #endif LOG4ESPP_INFO(logger, printWorkerId() \ << "associates class \"" \ << name << "\" to class id " << id << "."); ConstructorCallerType cc = constructorCallersByName()[name]; constructorCallers.push_back(cc); constructorCallersByName().erase(name); DestructorCallerType dc = destructorCallersByName()[name]; destructorCallers.push_back(dc); destructorCallersByName().erase(name); }
inline void FixedTripleListTypesInteractionTemplate<_Potential>:: computeVirialTensor(Tensor *w, int n) { LOG4ESPP_INFO(theLogger, "compute the virial tensor for the FixedTriple List"); }