ESyS-Particle  2.3.2
ScalarParticleFieldSlaveTagged.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 
35 template <typename T>
36 ScalarParticleFieldSlaveTagged<T>::ScalarParticleFieldSlaveTagged(TML_Comm* comm,ParallelParticleArray<T>* ppa,typename T::ScalarFieldFunction rdf,int tag,int mask):ScalarParticleFieldSlave<T>(comm,ppa,rdf)
37 {
38  m_tag=tag;
39  m_mask=mask;
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 =
53  this->m_ppa->forAllInnerTaggedParticlesGetIndexed(
54  this->m_rdf,
55  m_tag,
56  m_mask
57  );
58  pos_vec =
59  this->m_ppa->forAllInnerTaggedParticlesGetIndexed(
60  typename T::VectorFieldFunction(&T::getPos),
61  m_tag,
62  m_mask
63  );
64  rad_vec =
65  this->m_ppa->forAllInnerTaggedParticlesGetIndexed(
66  typename T::ScalarFieldFunction(&T::getRad),
67  m_tag,
68  m_mask
69  );
70 
71  // send data to master
72  this->m_comm->send_gather(data_vec,0);
73  this->m_comm->send_gather(pos_vec,0);
74  this->m_comm->send_gather(rad_vec,0);
75 }
76 
80 template <typename T>
82 {
83  vector<double> data_vec;
84 
85  // get data from particles
86  this->m_ppa->forAllTaggedInnerParticlesGet(data_vec,this->m_rdf,m_tag,m_mask);
87 
88  // sum data
89  double sum=0.0;
90  for(vector<double>::iterator iter=data_vec.begin();
91  iter!=data_vec.end();
92  iter++){
93  sum+=*iter;
94  }
95 
96  vector<double> sum_vec;
97  sum_vec.push_back(sum);
98  this->m_comm->send_gather(sum_vec,0);
99 }
100 
101 
105 template <typename T>
107 {
108  vector<double> data_vec;
109 
110  // get data from particles
111  this->m_ppa->forAllTaggedInnerParticlesGet(
112  data_vec,
113  this->m_rdf,
114  m_tag,
115  m_mask
116  );
117 
118  // sum data
119  double max=*(data_vec.begin());
120  for(vector<double>::iterator iter=data_vec.begin();
121  iter!=data_vec.end();
122  iter++){
123  max=(*iter > max) ? *iter : max;
124  }
125 
126  vector<double> max_vec;
127  max_vec.push_back(max);
128  this->m_comm->send_gather(max_vec,0);
129 }