ESyS-Particle  2.3.2
ScalarParticleFieldSlave.hpp
Go to the documentation of this file.
1 
2 // //
3 // Copyright (c) 2003-2014 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
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 //-- STL includes --
14 #include <vector>
15 #include <utility>
16 
17 using std::vector;
18 using std::pair;
19 
20 // -- IO includes --
21 #include <iostream>
22 
23 using std::cout;
24 using std::endl;
25 
33 template <typename T>
35 {
36  m_ppa=ppa;
37  m_rdf=rdf;
38 }
39 
40 
41 
45 template <typename T>
47 {
48  vector<pair<int,double> > data_vec;
49  vector<pair<int,double> > rad_vec;
50  vector<pair<int,Vec3> > pos_vec;
51 
52  data_vec=m_ppa->forAllInnerParticlesGetIndexed(m_rdf);
53  pos_vec=m_ppa->forAllInnerParticlesGetIndexed(typename T::VectorFieldFunction(&T::getPos));
54  rad_vec=m_ppa->forAllInnerParticlesGetIndexed(typename T::ScalarFieldFunction(&T::getRad));
55 
56  // send data to master
57  m_comm->send_gather(data_vec,0);
58  m_comm->send_gather(pos_vec,0);
59  m_comm->send_gather(rad_vec,0);
60 }
61 
65 template <typename T>
67 {
68  vector<double> data_vec;
69 
70  // get data from particles
71  m_ppa->forAllInnerParticlesGet(data_vec,m_rdf);
72 
73  // sum data
74  double sum=0.0;
75  for(vector<double>::iterator iter=data_vec.begin();
76  iter!=data_vec.end();
77  iter++){
78  sum+=*iter;
79  }
80 
81  vector<double> sum_vec;
82  sum_vec.push_back(sum);
83  m_comm->send_gather(sum_vec,0);
84 }
85 
89 template <typename T>
91 {
92  vector<double> data_vec;
93 
94  // get data from particles
95  m_ppa->forAllInnerParticlesGet(data_vec,m_rdf);
96 
97  // sum data
98  double max=*(data_vec.begin());
99  for(vector<double>::iterator iter=data_vec.begin();
100  iter!=data_vec.end();
101  iter++){
102  max=(*iter > max) ? *iter : max;
103  }
104 
105  vector<double> max_vec;
106  max_vec.push_back(max);
107  m_comm->send_gather(max_vec,0);
108 }
109 
113 template <typename T>
115 {
116  int coll_type;
117  m_comm->recv_broadcast(coll_type,0);
118 
119  switch(coll_type){
120  case 1: SendDataFull();break;
121  case 2: SendDataSum();break;
122  case 3: SendDataMax();break;
123  default: std::cerr << "unknown collection type" << std::endl;
124  }
125 }