ESyS-Particle  2.3.2
CheckedScalarInteractionFieldSlaveTagged.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_tag=tag;
37  m_mask=mask;
38 }
39 
43 template <typename T>
45 {
46  vector<pair<Vec3,pair<bool,double> > > raw_data;
47  vector<pair<Vec3,double> > data;
48 
49  // get raw field data from interaction storage
50  raw_data=this->m_pis->forAllTaggedInnerInteractionsGetWithPos(this->m_rdf,m_tag,m_mask);
51 
52  // filter data
53  for(vector<pair<Vec3,pair<bool,double> > >::iterator iter=raw_data.begin();
54  iter!=raw_data.end();
55  iter++){
56  if(iter->second.first){
57  data.push_back(make_pair(iter->first,iter->second.second));
58  }
59  }
60 
61  // send data to master
62  this->m_comm->send_gather(data,0);
63 }
64 
68 template <typename T>
70 {
71  vector<pair<bool,double> >data_vec;
72 
73  // get data from interactions
74  this->m_pis->forAllTaggedInnerInteractionsGet(data_vec,this->m_rdf,m_tag,m_mask);
75 
76  // sum data
77  double sum=0.0;
78  for(vector<pair<bool,double> >::iterator iter=data_vec.begin();
79  iter!=data_vec.end();
80  iter++)
81  {
82  if(iter->first) sum+=iter->second;
83  }
84 
85  vector<double> sum_vec;
86  sum_vec.push_back(sum);
87  this->m_comm->send_gather(sum_vec,0);
88 }
89 
93 template <typename T>
95 {
96  vector<pair<bool,double> >data_vec;
97 
98  // get data from interactions
99  this->m_pis->forAllTaggedInnerInteractionsGet(data_vec,this->m_rdf,m_tag,m_mask);
100 
101  // get max
102  double max;
103  bool is_set=false;
104  for(vector<pair<bool,double> >::iterator iter=data_vec.begin();
105  iter!=data_vec.end();
106  iter++){
107  if(iter->first) {
108  if(is_set){
109  max=(iter->second > max) ? iter->second : max;
110  } else {
111  max=iter->second;
112  is_set=true;
113  }
114  }
115  }
116 
117  vector<double> max_vec;
118  max_vec.push_back(max);
119  this->m_comm->send_gather(max_vec,0);
120 }