~esys-p-dev/esys-particle/trunk

« back to all changes in this revision

Viewing changes to Fields/ScalarFluidInteractionFieldSlave.hpp

  • Committer: Dion Weatherley
  • Date: 2019-07-28 15:53:14 UTC
  • mfrom: (1183.1.1 ESyS-Darcy)
  • Revision ID: d.weatherley@uq.edu.au-20190728155314-at6fqkat5wwi4mw6
Merge of Dr Qi Shao's ESyS-Darcy integrated Darcy flow solver into trunk

**UNTESTED** These revisions have yet to be tested/built. Do not update to this version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.apache.org/licenses/LICENSE-2.0          //
 
10
//                                                         //
 
11
/////////////////////////////////////////////////////////////
 
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
 
 
26
#include "Foundation/triplet.h"
 
27
#include "pis/pi_storage_f.h"
 
28
 
 
29
/*!
 
30
  constructor
 
31
 
 
32
  \param comm the TML communicator used for sending the data back to the master
 
33
  \param pis a pointer to the fluid interaction storage
 
34
  \param rdf the fluid interaction member function to access the data
 
35
*/
 
36
template <typename T>
 
37
ScalarFluidInteractionFieldSlave<T>::ScalarFluidInteractionFieldSlave(TML_Comm* comm,ParallelInteractionStorage_F<T>* pis,CFluidInteraction::ScalarFieldFunction rdf):AFieldSlave(comm)
 
38
{
 
39
  m_rdf=rdf;
 
40
  m_pis=pis;
 
41
}
 
42
 
 
43
/*!
 
44
  Send data back to master. Determine the type of data (full/sum) to send back from
 
45
  the received coll_type and call the according send function.
 
46
*/
 
47
template <typename T>
 
48
void ScalarFluidInteractionFieldSlave<T>::sendData()
 
49
{
 
50
  // debug output
 
51
  console.XDebug() << "InteractionFieldSlave<T>::sendData()\n";
 
52
 
 
53
  int coll_type;
 
54
  m_comm->recv_broadcast(coll_type,0);
 
55
 
 
56
  // debug output
 
57
  console.XDebug() << "received coll_type=" << coll_type << "\n";
 
58
 
 
59
  switch(coll_type){
 
60
  case COLL_TYPE_FULL_WITH_POS : SendDataWithPos();break;
 
61
  case COLL_TYPE_FULL_WITH_ID : SendDataWithID();break;
 
62
  case COLL_TYPE_FULL_WITH_ID_POS : SendDataWithIDPos();break;
 
63
  case COLL_TYPE_FULL_WITH_PARTICLE : SendDataWithParticle();break;
 
64
  case COLL_TYPE_SUM : SendDataSum();break;
 
65
  case COLL_TYPE_MAX : SendDataMax();break;
 
66
 
 
67
  default: std::cerr << "unknown collection type" << std::endl;
 
68
  }
 
69
}
 
70
 
 
71
 
 
72
/*!
 
73
  send full field data and position of the interaction
 
74
*/
 
75
template <typename T>
 
76
void ScalarFluidInteractionFieldSlave<T>::SendDataWithPos()
 
77
{
 
78
  vector<pair<Vec3,double> > data;
 
79
 
 
80
  data=this->m_pis->forAllInnerInteractionsGetDataWithPos(m_rdf);
 
81
 
 
82
  // send data to master
 
83
  this->m_comm->send_gather(data,0);
 
84
}
 
85
 
 
86
/*!
 
87
  send full field data and id of the particle
 
88
*/
 
89
template <typename T>
 
90
void ScalarFluidInteractionFieldSlave<T>::SendDataWithID()
 
91
{
 
92
  vector<pair<int,double> > data;
 
93
 
 
94
  data=this->m_pis->forAllInnerInteractionsGetDataWithID(m_rdf);
 
95
 
 
96
  // send data to master
 
97
  this->m_comm->send_gather(data,0);
 
98
}
 
99
 
 
100
 
 
101
/*!
 
102
  send full field data and id, position of the particle
 
103
*/
 
104
template <typename T>
 
105
void ScalarFluidInteractionFieldSlave<T>::SendDataWithIDPos()
 
106
{
 
107
  vector<pair<pair<int,Vec3>,double> > data;
 
108
 
 
109
  data=this->m_pis->forAllInnerInteractionsGetDataWithIDPos(m_rdf);
 
110
 
 
111
  // send data to master
 
112
  this->m_comm->send_gather(data,0);
 
113
}
 
114
 
 
115
/*!
 
116
  send full field data and id, position and radius of the particle
 
117
*/
 
118
template <typename T>
 
119
void ScalarFluidInteractionFieldSlave<T>::SendDataWithParticle()
 
120
{
 
121
  vector<pair<esys::lsm::triplet<int,Vec3,double>,double> > data;
 
122
 
 
123
  data=this->m_pis->forAllInnerInteractionsGetDataWithParticle(m_rdf);
 
124
 
 
125
  // send data to master
 
126
  this->m_comm->send_gather(data,0);
 
127
}
 
128
 
 
129
/*!
 
130
  send sum only
 
131
*/
 
132
template <typename T>
 
133
void ScalarFluidInteractionFieldSlave<T>::SendDataSum()
 
134
{
 
135
  vector<double> data_vec;
 
136
 
 
137
  // get data from interactions
 
138
  this->m_pis->forAllInnerInteractionsGet(data_vec,m_rdf);
 
139
 
 
140
  // sum data
 
141
  double sum=0.0;
 
142
  for(vector<double>::iterator iter=data_vec.begin();
 
143
      iter!=data_vec.end();
 
144
      iter++){
 
145
    sum+=*iter;
 
146
  }
 
147
 
 
148
  vector<double> sum_vec;
 
149
  sum_vec.push_back(sum);
 
150
  this->m_comm->send_gather(sum_vec,0);
 
151
}
 
152
 
 
153
 
 
154
/*!
 
155
  send maximum only
 
156
*/
 
157
template <typename T>
 
158
void ScalarFluidInteractionFieldSlave<T>::SendDataMax()
 
159
{
 
160
  vector<double> data_vec;
 
161
 
 
162
  // get data from interactions
 
163
  this->m_pis->forAllInnerInteractionsGet(data_vec,m_rdf);
 
164
 
 
165
  // sum data
 
166
  double max=*(data_vec.begin());
 
167
  for(vector<double>::iterator iter=data_vec.begin();
 
168
      iter!=data_vec.end();
 
169
      iter++){
 
170
    max=(*iter > max) ? *iter : max;
 
171
  }
 
172
 
 
173
  vector<double> max_vec;
 
174
  max_vec.push_back(max);
 
175
  this->m_comm->send_gather(max_vec,0);
 
176
}