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 template<typename P,typename I> 00014 ParallelInteractionStorage_EB<P,I>::ParallelInteractionStorage_EB(AParallelParticleArray* ppa,const typename I::ParameterType& param):ParallelInteractionStorage_E<P,I>(ppa,param) 00015 { 00016 m_unbreakable=false; 00017 } 00018 00022 template<typename P,typename InteractionType> 00023 bool ParallelInteractionStorage_EB<P,InteractionType>::update() 00024 { 00025 bool res=false; 00026 00027 if(!m_unbreakable){ 00028 console.XDebug() << "PIS_E::updating\n"; 00029 typename list<InteractionType>::iterator iter = this->m_interactions.begin(); 00030 while (iter != this->m_interactions.end()){ 00031 if(iter->broken()){ 00032 res=true; 00033 typename list<InteractionType>::iterator er_iter=iter; 00034 // get IDs to remove from set 00035 vector<int> pids=iter->getAllID(); 00036 this->m_set.erase(make_pair(pids[0],pids[1])); 00037 iter++; 00038 // remove interaction 00039 this->m_interactions.erase(er_iter); 00040 } else { 00041 iter++; 00042 } 00043 } 00044 } else { 00045 console.XDebug() << "PIS_E::not updating\n"; 00046 } 00047 00048 return res; 00049 } 00050 00054 template<typename P,typename InteractionType> 00055 void ParallelInteractionStorage_EB<P,InteractionType>::saveSnapShotData(std::ostream &oStream) 00056 { 00057 const std::string delim = "\n"; 00058 typedef typename InteractionType::CheckPointable CheckPointable; 00059 00060 typename ParallelInteractionStorage_E<P,InteractionType>::InteractionIterator it = 00061 this->getInnerInteractionIterator(); 00062 oStream << InteractionType::getType() << delim; 00063 oStream << it.getNumRemaining(); 00064 if (it.hasNext()) { 00065 oStream << delim; 00066 CheckPointable(it.next()).saveCheckPointData(oStream); 00067 while (it.hasNext()) 00068 { 00069 oStream << delim; 00070 CheckPointable(it.next()).saveCheckPointData(oStream); 00071 } 00072 } 00073 } 00074 00078 template<typename P,typename InteractionType> 00079 void ParallelInteractionStorage_EB<P,InteractionType>::saveCheckPointData(std::ostream &oStream) 00080 { 00081 const std::string delim = "\n"; 00082 // typedef typename InteractionType::CheckPointable CheckPointable; 00083 00084 typename ParallelInteractionStorage_E<P,InteractionType>::InteractionIterator it = 00085 this->getInnerInteractionIterator(); 00086 oStream << InteractionType::getType() << delim; 00087 oStream << it.getNumRemaining(); 00088 if (it.hasNext()) { 00089 oStream << delim; 00090 it.next().saveRestartData(oStream); 00091 while (it.hasNext()) 00092 { 00093 oStream << delim; 00094 it.next().saveRestartData(oStream); 00095 } 00096 } 00097 } 00098 00106 template<typename P,typename InteractionType> 00107 void ParallelInteractionStorage_EB<P,InteractionType>::loadCheckPointData(std::istream &iStream) 00108 { 00109 // read interaction type from stream 00110 std::string cp_interaction_type; 00111 iStream >> cp_interaction_type; 00112 // compare interaction type in stream with type of this IG 00113 // in not equal, signal error 00114 if(cp_interaction_type!=InteractionType::getType()){ 00115 std::cerr << "interaction types differ between checkpoint " 00116 << cp_interaction_type << " and scipt " 00117 << InteractionType::getType() << std::endl; 00118 } else { // correct type -> read data 00119 // read nr. of bonds in IG 00120 int nconn; 00121 iStream >> nconn; 00122 std::cerr << "reading " << nconn << " " << InteractionType::getType() << " interactions " << std::endl; 00123 00124 ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa); 00125 00126 // -- read bonds 00127 for(int i=0;i<nconn;i++){ 00128 InteractionType new_bond; 00129 // read a bond 00130 new_bond.loadRestartData(iStream); 00131 // set particle pointers 00132 vector<int> pids=new_bond.getAllID(); 00133 P* ptr1=t_ppa->getParticlePtrByIndex(pids[0]); 00134 P* ptr2=t_ppa->getParticlePtrByIndex(pids[1]); 00135 if((ptr1!=NULL) && (ptr2!=NULL)){ 00136 new_bond.setPP(ptr1,ptr2); 00137 } else { 00138 std::cerr << "trying to insert bond: particles with Id " << pids[0] << " , " << pids[1] << "not present!" << std::endl; 00139 } 00140 // insert it into interaction storage 00141 this->tryInsert(new_bond); 00142 } 00143 } 00144 } 00145 00146 template<typename P,typename InteractionType> 00147 void ParallelInteractionStorage_EB<P,InteractionType>::calcHeatTrans() 00148 { 00149 console.Debug() 00150 << "calculating " << this->m_interactions.size() 00151 << " heat interaction transfers\n" ; 00152 00153 for( 00154 typename list<InteractionType>::iterator it = this->m_interactions.begin(); 00155 it != this->m_interactions.end(); 00156 it++ 00157 ){ 00158 it->calcHeatTrans(); 00159 } 00160 } 00161 00167 template<typename P,typename InteractionType> 00168 void ParallelInteractionStorage_EB<P,InteractionType>::setUnbreakable(bool b) 00169 { 00170 m_unbreakable=b; 00171 }