ESyS-Particle
4.0.1
|
00001 00002 // // 00003 // Copyright (c) 2003-2011 by The University of Queensland // 00004 // Earth Systems Science Computational Centre (ESSCC) // 00005 // http://www.uq.edu.au/esscc // 00006 // // 00007 // Primary Business: Brisbane, Queensland, Australia // 00008 // Licensed under the Open Software License version 3.0 // 00009 // http://www.opensource.org/licenses/osl-3.0.php // 00010 // // 00012 00013 00014 #include "pis/pi_storage.h" 00015 00016 //---------------------------------------------- 00017 // CElasticInteractionGroup functions 00018 //---------------------------------------------- 00019 template<class T> 00020 CElasticInteractionGroup<T>::CElasticInteractionGroup() 00021 { 00022 m_exIG=NULL; 00023 this->m_update_timestamp=0; 00024 } 00025 00026 template<class T> 00027 CElasticInteractionGroup<T>::CElasticInteractionGroup(const CElasticIGP* Param) 00028 { 00029 m_exIG=NULL; 00030 m_k=Param->getSpringConst(); 00031 this->m_update_timestamp=0; 00032 } 00033 00034 template<class T> 00035 void CElasticInteractionGroup<T>::setParam(const CElasticIGP* Param) 00036 { 00037 m_k=Param->getSpringConst(); 00038 } 00039 00040 template<class T> 00041 void CElasticInteractionGroup<T>::calcForces() 00042 { 00043 00044 console.Debug() << "calculating " << m_interactions.size() << " elastic forces\n" ; 00045 00046 for(vector<CElasticInteraction>::iterator it=m_interactions.begin();it!=m_interactions.end();it++){ 00047 it->calcForces(); 00048 } 00049 } 00050 00054 template<class T> 00055 void CElasticInteractionGroup<T>::Update(ParallelParticleArray<T>* PPA) 00056 { 00057 console.XDebug() << "CElasticInteractionGroup::Update\n"; 00058 int count_l=0; 00059 00060 if(this->m_update_timestamp!=PPA->getTimeStamp()){// PPA rebuild since last update 00061 // clean out old interactions 00062 m_interactions.erase(m_interactions.begin(),m_interactions.end()); 00063 this->m_set.erase(this->m_set.begin(),this->m_set.end()); 00064 // get list of pairs from PPA 00065 typename ParallelParticleArray<T>::PairListHandle plh=PPA->getFullPairList(); 00066 // generate interactions from pairs 00067 for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin(); 00068 iter!=plh->end(); 00069 iter++){ 00070 // check vs. ExIG 00071 vector<int> tv; 00072 tv.push_back(iter->first->getID()); 00073 tv.push_back(iter->second->getID()); 00074 if(m_exIG!=NULL){ 00075 if(!m_exIG->isIn(tv)){ 00076 m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k)); 00077 this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID())); 00078 console.XDebug()<<"adding pair: " << iter->first->getID() << " - " 00079 << iter->second->getID() << "\n"; 00080 count_l++; 00081 } else { 00082 console.XDebug()<<"not adding pair: " << iter->first->getID() << " - " 00083 << iter->second->getID() << "\n"; 00084 } 00085 } else { 00086 m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k)); 00087 this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID())); 00088 console.XDebug()<<"adding pair: " << iter->first->getID() << " - " 00089 << iter->second->getID() << "\n"; 00090 } 00091 } 00092 } else { // PPA not rebuild since last update -> just get additional interactions 00093 // get list of pairs from PPA 00094 typename ParallelParticleArray<T>::PairListHandle plh=PPA->getNewPairList(); 00095 for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin(); 00096 iter!=plh->end(); 00097 iter++){ 00098 // check vs. ExIG 00099 vector<int> tv; 00100 tv.push_back(iter->first->getID()); 00101 tv.push_back(iter->second->getID()); 00102 if(m_exIG!=NULL){ 00103 if(!m_exIG->isIn(tv)){ 00104 m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k)); 00105 this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID())); 00106 console.XDebug()<<"adding pair: " << iter->first->getID() << " - " 00107 << iter->second->getID() << "\n"; 00108 count_l++; 00109 } else { 00110 console.XDebug()<<"not adding pair: " << iter->first->getID() << " - " 00111 << iter->second->getID() << "\n"; 00112 } 00113 } else { 00114 m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k)); 00115 this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID())); 00116 console.XDebug()<<"adding pair: " << iter->first->getID() << " - " 00117 << iter->second->getID() << "\n"; 00118 } 00119 } 00120 } 00121 this->m_update_timestamp=PPA->getTimeStamp(); 00122 console.XDebug() << "added " << count_l << " pairs to EIG\n"; 00123 00124 console.XDebug() << "end CElasticInteractionGroup::Update\n"; 00125 } 00126 00127 template<class T> 00128 ostream& operator<<(ostream& ost,const CElasticInteractionGroup<T>& E) 00129 { 00130 ost << "CElasticInteractionGroup : \n"; 00131 for(vector<CElasticInteraction>::const_iterator it=E.m_interactions.begin();it!=E.m_interactions.end();it++){ 00132 ost << *it << " , " ; 00133 } 00134 ost << "exchange list: \n"; 00135 for(set<pair<int,int> >::const_iterator vit=E.m_exchg_list.begin();vit!=E.m_exchg_list.end();vit++){ 00136 ost << "[ " << vit->first << " from " << vit->second << " ] , "; 00137 } 00138 return ost; 00139 }