ESyS-Particle  4.0.1
pi_storage_ed.hpp
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 template<typename P,typename I>
15 {
16  m_exIG=NULL;
17  m_update_timestamp=0;
18 }
19 
20 template<typename P,typename InteractionType>
22 {
23  console.Debug() << "setExIG " << eg << "\n";
24  m_exIG=eg;
25  // clean out excluded interactions
26  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
27  while(iter != this->m_interactions.end()){
28  // check if in exIG
29  vector<int> rm_pids=iter->getAllID();
30  if(m_exIG->isIn(rm_pids)){
31  console.XDebug() << "removing excluded: " << rm_pids[0] << " - " << rm_pids[1] << "\n";
32  typename list<InteractionType>::iterator er_iter=iter;
33  // get particle ids and remove pair from set
34  this->m_set.erase(make_pair(rm_pids[0],rm_pids[1]));
35  iter++;
36  this->m_interactions.erase(er_iter);
37  } else {
38  iter++;
39  }
40  }
41 }
42 
43 template<typename T,typename InteractionType>
45  double dt
46 )
47 {
48  console.Debug()
49  << "setting time step size for "
50  << this->m_interactions.size() << " interaction forces\n" ;
51  this->m_param.setTimeStepSize(dt);
52  for (
53  typename std::list<InteractionType>::iterator it = this->m_interactions.begin();
54  it != this->m_interactions.end();
55  it++
56  ){
57  it->setTimeStepSize(dt);
58  }
59 }
60 
64 template<typename T,typename InteractionType>
66 {
67  //std::cout << "ParallelInteractionStorage_ED::update at node " << m_comm.rank() << std::endl << std::flush;
68  int count_l=0;
69  bool res=true;
70 
71  if (this->m_update_timestamp != this->m_ppa->getTimeStamp()){// m_ppa rebuild since last update
72  console.XDebug() << "node " << this->m_comm.rank() << " ppa has been rebuilt\n";
73  // clean out old interactions if not flagged as persistent
74  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
75  while(iter != this->m_interactions.end()){
76  if(iter->isPersistent()){
77  iter++;
78  //console.XDebug() << "node " << m_comm.rank() << "persistent interaction\n";
79  }else{
80  typename list<InteractionType>::iterator er_iter=iter;
81  // get particle ids and remove pair from set
82  vector<int> rm_pids=iter->getAllID();
83  this->m_set.erase(make_pair(rm_pids[0],rm_pids[1]));
84  iter++;
85  this->m_interactions.erase(er_iter);
86  }
87  }
88  // get list of pairs from m_ppa
89  typename ParallelParticleArray<T>::PairListHandle plh =
90  ((ParallelParticleArray<T>*)this->m_ppa)->getFullPairList();
91  // generate interactions from pairs
92  for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
93  iter!=plh->end();
94  iter++){
95  // check vs. ExIG
96  vector<int> tv;
97  // ids in pair
98  int id1=iter->first->getID();
99  int id2=iter->second->getID();
100  tv.push_back(id1);
101  tv.push_back(id2);
102  if(m_exIG!=NULL){ // if there is an ExIG
103  if((!m_exIG->isIn(tv))&&(!this->isIn(tv))){ // if not already in or in ExIG
104  this->m_interactions.push_back(
105  InteractionType(iter->first,iter->second,this->m_param)
106  );
107  this->m_set.insert(make_pair(id1,id2));
108  count_l++;
109  }
110  } else if (!(this->isIn(tv))) { // if no ExIG -> check only if alrady in
111  this->m_interactions.push_back(
112  InteractionType(iter->first,iter->second,this->m_param)
113  );
114  this->m_set.insert(make_pair(id1,id2));
115  }
116  }
117  } else { // m_ppa not rebuild since last update -> just get additional interactions
118  console.XDebug() << "node " << this->m_comm.rank() << " ppa not rebuilt\n";
119  // get list of pairs from m_ppa
120  typename ParallelParticleArray<T>::PairListHandle plh =
121  ((ParallelParticleArray<T>*)this->m_ppa)->getNewPairList();
122  for (
123  typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
124  iter!=plh->end();
125  iter++
126  ){
127  // check vs. ExIG
128  vector<int> tv;
129  // ids in pair
130  int id1=iter->first->getID();
131  int id2=iter->second->getID();
132  tv.push_back(id1);
133  tv.push_back(id2);
134  if(m_exIG!=NULL){
135  if((!m_exIG->isIn(tv))&&(!(this->isIn(tv)))) {
136  this->m_interactions.push_back(
137  InteractionType(iter->first,iter->second, this->m_param)
138  );
139  this->m_set.insert(make_pair(id1,id2));
140  count_l++;
141  }
142  } else if (!(this->isIn(tv))) {
143  this->m_interactions.push_back(
144  InteractionType(iter->first,iter->second,this->m_param)
145  );
146  this->m_set.insert(make_pair(id1,id2));
147  }
148  }
149  }
150  m_update_timestamp = this->m_ppa->getTimeStamp();
151 
152  console.Debug() << "added " << count_l << " pairs to ParallelInteractionStorage_ED\n";
153  // std::cout << "end ParallelInteractionStorage_ED::update at node " << m_comm.rank() << std::endl << std::flush;
154 
155  return res;
156 }
157 
158 
159 template<typename T,typename InteractionType>
161 {
162  console.Debug()
163  << "calculating "
164  << this->m_interactions.size()
165  << " frictional heatings\n" ;
166 
167  for(
168  typename list<InteractionType>::iterator it = this->m_interactions.begin();
169  it != this->m_interactions.end();
170  it++
171  ){
172  it->calcHeatFrict();
173  }
174 }
175 
176 template<typename P,typename InteractionType>
178 {
179  console.Debug()
180  << "calculating "
181  << this->m_interactions.size()
182  << " heat transfers\n" ;
183 
184  for(
185  typename list<InteractionType>::iterator it = this->m_interactions.begin();
186  it != this->m_interactions.end();
187  it++
188  ){
189  it->calcHeatTrans();
190  }
191 }
192 
196 template<typename P,typename InteractionType>
198 {
199  const std::string delim = "\n";
200 
202  this->getInnerInteractionIterator();
203  oStream << InteractionType::getType() << delim;
204  oStream << it.getNumRemaining();
205  if (it.hasNext()) {
206  oStream << delim;
207  it.next().saveRestartData(oStream);
208  while (it.hasNext())
209  {
210  oStream << delim;
211  it.next().saveRestartData(oStream);
212  }
213  }
214 }
215 
223 template<typename P,typename InteractionType>
225 {
226  // read interaction type from stream
227  std::string cp_interaction_type;
228  iStream >> cp_interaction_type;
229  // compare interaction type in stream with type of this IG
230  // in not equal, signal error
231  if(cp_interaction_type!=InteractionType::getType()){
232  std::cerr << "interaction types differ between checkpoint "
233  << cp_interaction_type << " and scipt "
234  << InteractionType::getType() << std::endl;
235  } else { // correct type -> read data
236  // read nr. of bonds in IG
237  int nconn;
238  iStream >> nconn;
239  std::cerr << "reading " << nconn << " " << InteractionType::getType() << " interactions " << std::endl;
240 
241  // -- read bonds
242  for(int i=0;i<nconn;i++){
243  InteractionType new_bond;
244  // read a bond
245  new_bond.loadRestartData(iStream);
246  // insert it into interaction storage
247  this->tryInsert(new_bond);
248  }
249  }
250 }