ESyS-Particle  4.0.1
pi_storage_eb.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_unbreakable=false;
17 }
18 
22 template<typename P,typename InteractionType>
24 {
25  bool res=false;
26 
27  if(!m_unbreakable){
28  console.XDebug() << "PIS_E::updating\n";
29  typename list<InteractionType>::iterator iter = this->m_interactions.begin();
30  while (iter != this->m_interactions.end()){
31  if(iter->broken()){
32  res=true;
33  typename list<InteractionType>::iterator er_iter=iter;
34  // get IDs to remove from set
35  vector<int> pids=iter->getAllID();
36  this->m_set.erase(make_pair(pids[0],pids[1]));
37  iter++;
38  // remove interaction
39  this->m_interactions.erase(er_iter);
40  } else {
41  iter++;
42  }
43  }
44  } else {
45  console.XDebug() << "PIS_E::not updating\n";
46  }
47 
48  return res;
49 }
50 
54 template<typename P,typename InteractionType>
56 {
57  const std::string delim = "\n";
58  typedef typename InteractionType::CheckPointable CheckPointable;
59 
61  this->getInnerInteractionIterator();
62  oStream << InteractionType::getType() << delim;
63  oStream << it.getNumRemaining();
64  if (it.hasNext()) {
65  oStream << delim;
66  CheckPointable(it.next()).saveCheckPointData(oStream);
67  while (it.hasNext())
68  {
69  oStream << delim;
70  CheckPointable(it.next()).saveCheckPointData(oStream);
71  }
72  }
73 }
74 
78 template<typename P,typename InteractionType>
80 {
81  const std::string delim = "\n";
82  // typedef typename InteractionType::CheckPointable CheckPointable;
83 
85  this->getInnerInteractionIterator();
86  oStream << InteractionType::getType() << delim;
87  oStream << it.getNumRemaining();
88  if (it.hasNext()) {
89  oStream << delim;
90  it.next().saveRestartData(oStream);
91  while (it.hasNext())
92  {
93  oStream << delim;
94  it.next().saveRestartData(oStream);
95  }
96  }
97 }
98 
106 template<typename P,typename InteractionType>
108 {
109  // read interaction type from stream
110  std::string cp_interaction_type;
111  iStream >> cp_interaction_type;
112  // compare interaction type in stream with type of this IG
113  // in not equal, signal error
114  if(cp_interaction_type!=InteractionType::getType()){
115  std::cerr << "interaction types differ between checkpoint "
116  << cp_interaction_type << " and scipt "
117  << InteractionType::getType() << std::endl;
118  } else { // correct type -> read data
119  // read nr. of bonds in IG
120  int nconn;
121  iStream >> nconn;
122  std::cerr << "reading " << nconn << " " << InteractionType::getType() << " interactions " << std::endl;
123 
124  ParallelParticleArray<P>* t_ppa=(ParallelParticleArray<P>*)(this->m_ppa);
125 
126  // -- read bonds
127  for(int i=0;i<nconn;i++){
128  InteractionType new_bond;
129  // read a bond
130  new_bond.loadRestartData(iStream);
131  // set particle pointers
132  vector<int> pids=new_bond.getAllID();
133  P* ptr1=t_ppa->getParticlePtrByIndex(pids[0]);
134  P* ptr2=t_ppa->getParticlePtrByIndex(pids[1]);
135  if((ptr1!=NULL) && (ptr2!=NULL)){
136  new_bond.setPP(ptr1,ptr2);
137  } else {
138  std::cerr << "trying to insert bond: particles with Id " << pids[0] << " , " << pids[1] << "not present!" << std::endl;
139  }
140  // insert it into interaction storage
141  this->tryInsert(new_bond);
142  }
143  }
144 }
145 
146 template<typename P,typename InteractionType>
148 {
149  console.Debug()
150  << "calculating " << this->m_interactions.size()
151  << " heat interaction transfers\n" ;
152 
153  for(
154  typename list<InteractionType>::iterator it = this->m_interactions.begin();
155  it != this->m_interactions.end();
156  it++
157  ){
158  it->calcHeatTrans();
159  }
160 }
161 
167 template<typename P,typename InteractionType>
169 {
170  m_unbreakable=b;
171 }