ESyS-Particle
4.0.1
|
00001 00002 // // 00003 // Copyright (c) 2003-2011 by The University of Queensland // 00004 // Earth Systems Science Computational Centre (ESSCC) // 00005 // http://www.uq.edu.au/esscc // 00006 // // 00007 // Primary Business: Brisbane, Queensland, Australia // 00008 // Licensed under the Open Software License version 3.0 // 00009 // http://www.opensource.org/licenses/osl-3.0.php // 00010 // // 00012 00013 //-- STL includes -- 00014 #include <vector> 00015 #include <utility> 00016 00017 using std::vector; 00018 using std::pair; 00019 using std::make_pair; 00020 00021 // -- IO includes -- 00022 #include <iostream> 00023 00024 using std::cout; 00025 using std::endl; 00026 using std::cerr; 00027 00028 // --- project includes --- 00029 #include "Foundation/triplet.h" 00030 #include "Foundation/console.h" 00031 00032 using esys::lsm::triplet; 00033 00041 template <typename T> 00042 CheckedScalarInteractionFieldSlave<T>::CheckedScalarInteractionFieldSlave(TML_Comm* comm,TParallelInteractionStorage<T>* pis,typename T::CheckedScalarFieldFunction rdf):InteractionFieldSlave<T>(comm,pis) 00043 { 00044 this->m_rdf=rdf; 00045 } 00046 00052 template <typename T> 00053 void CheckedScalarInteractionFieldSlave<T>::SendDataFull() 00054 { 00055 vector<pair<Vec3,pair<bool,double> > > raw_data; // position, [valid ?, data] 00056 vector<pair<Vec3,double> > data; // position, data 00057 00058 // get raw data 00059 raw_data=this->m_pis->forAllInnerInteractionsGetWithPos(this->m_rdf); 00060 00061 // filter data 00062 for(vector<pair<Vec3,pair<bool,double> > >::iterator iter=raw_data.begin(); 00063 iter!=raw_data.end(); 00064 iter++){ 00065 if(iter->second.first){ 00066 data.push_back(make_pair(iter->first,iter->second.second)); 00067 } 00068 } 00069 00070 // send data to master 00071 this->m_comm->send_gather(data,0); 00072 } 00073 00079 template <typename T> 00080 void CheckedScalarInteractionFieldSlave<T>::SendDataFull2() 00081 { 00082 vector<pair<esys::lsm::quintuple<Vec3,double,Vec3,double,Vec3>,pair<bool,double> > > raw_data; 00083 vector<pair<esys::lsm::quintuple<Vec3,double,Vec3,double,Vec3>,double> > data; 00084 00085 // get raw data 00086 raw_data=this->m_pis->forAllInnerInteractionsGetRaw2(this->m_rdf); 00087 00088 // filter data 00089 for(vector<pair<esys::lsm::quintuple<Vec3,double,Vec3,double,Vec3>,pair<bool,double> > >::iterator iter=raw_data.begin(); 00090 iter!=raw_data.end(); 00091 iter++){ 00092 if(iter->second.first){ 00093 data.push_back(make_pair(iter->first,iter->second.second)); 00094 } 00095 } 00096 00097 // send data to master 00098 this->m_comm->send_gather(data,0); 00099 } 00100 00101 00102 00106 template <typename T> 00107 void CheckedScalarInteractionFieldSlave<T>::SendDataSum() 00108 { 00109 vector<pair<bool,double> > data_vec; 00110 00111 // get data from interactions 00112 this->m_pis->forAllInnerInteractionsGet(data_vec,this->m_rdf); 00113 00114 // sum data 00115 double sum=0.0; 00116 for(vector<pair<bool,double> >::iterator iter=data_vec.begin(); 00117 iter!=data_vec.end(); 00118 iter++){ 00119 if(iter->first) sum+=iter->second; 00120 } 00121 00122 vector<double> sum_vec; 00123 sum_vec.push_back(sum); 00124 this->m_comm->send_gather(sum_vec,0); 00125 } 00126 00130 template <typename T> 00131 void CheckedScalarInteractionFieldSlave<T>::SendDataMax() 00132 { 00133 vector<pair<bool,double> > data_vec; 00134 00135 // get data from interactions 00136 this->m_pis->forAllInnerInteractionsGet(data_vec,this->m_rdf); 00137 00138 // sum data 00139 double max; 00140 bool is_set=false; 00141 for(vector<pair<bool,double> >::iterator iter=data_vec.begin(); 00142 iter!=data_vec.end(); 00143 iter++){ 00144 if(iter->first) { 00145 if(is_set){ 00146 max=(iter->second > max) ? iter->second : max; 00147 } else { 00148 max=iter->second; 00149 is_set=true; 00150 } 00151 } 00152 } 00153 00154 vector<double> max_vec; 00155 max_vec.push_back(max); 00156 this->m_comm->send_gather(max_vec,0); 00157 } 00158 00162 template <typename T> 00163 void CheckedScalarInteractionFieldSlave<T>::SendDataWithID() 00164 { 00165 vector<pair<triplet<int,int,Vec3>, pair<bool,double> > > raw_data; 00166 vector<pair<triplet<int,int,Vec3>, double> > data; 00167 00168 // get raw data 00169 raw_data=this->m_pis->forAllInnerInteractionsGetDataWithID(this->m_rdf); 00170 00171 console.XDebug() << "got " << raw_data.size() << " raw data\n"; 00172 00173 // filter data 00174 for(vector<pair<triplet<int,int,Vec3>, pair<bool,double> > >::iterator iter=raw_data.begin(); 00175 iter!=raw_data.end(); 00176 iter++){ 00177 if(iter->second.first){ 00178 data.push_back(make_pair(iter->first,iter->second.second)); 00179 } 00180 } 00181 00182 console.XDebug() << "got " << data.size() << " filtered data\n"; 00183 00184 // send data to master 00185 this->m_comm->send_gather(data,0); 00186 }