ESyS-Particle  4.0.1
RotSubLattice.hpp
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 
00020 template <class T>
00021 TRotSubLattice<T>::TRotSubLattice(const esys::lsm::CLatticeParam &prm, int rank, MPI_Comm comm, MPI_Comm worker_comm):
00022   TSubLattice<T>(prm,rank,comm,worker_comm)
00023 {}
00024 
00028 template <class T>
00029 TRotSubLattice<T>::~TRotSubLattice()
00030 {}
00031 
00035 template <class T>
00036 void TRotSubLattice<T>::setParticleAngularVelocity()
00037 { 
00038   console.Debug() << "TSubLattice<T>::setParticleAngularVelocity()\n";
00039   CVarMPIBuffer buffer(this->m_comm);
00040 
00041   buffer.receiveBroadcast(0); // get data from master
00042   int id=buffer.pop_int();
00043   Vec3 mv=buffer.pop_vector();
00044   this->m_ppa->forParticle(id,(void (T::*)(Vec3))(&T::setAngVel),mv);
00045   console.XDebug() << "end TSubLattice<T>::setParticleAngularVelocity()\n";
00046 }
00047 
00055 template <class T>
00056 bool TRotSubLattice<T>::doAddPIG(const string& name,const string& type,CVarMPIBuffer& param_buffer)
00057 {
00058   bool res;
00059 
00060   // try interactions defined in the base class
00061   res=TSubLattice<T>::doAddPIG(name,type,param_buffer);
00062   if(!res){ // if not successfull, try interactions defined here
00063     
00064   }
00065   return res;
00066 
00067 }
00068 
00075 template <class T>
00076 bool TRotSubLattice<T>::doAddDamping(const string& type,CVarMPIBuffer& param_buffer)
00077 {
00078   bool res=false;
00079 
00080   AParallelInteractionStorage* DG=NULL;
00081   string damping_name;
00082   if (type=="RotDamping") {
00083     CDampingIGP *params=extractDampingIGP(&param_buffer);
00084     console.Debug() << "add rotational damping\n";
00085     DG=new ParallelInteractionStorage_Single<T,CRotDamping<T> >(this->m_ppa,*params); // dodgy
00086     damping_name="RotDamping";
00087     res=true;
00088     // add to map
00089     this->m_damping.insert(make_pair(damping_name,DG));
00090     this->m_damping[damping_name]->update();
00091   }
00092   else if (type=="RotLocalDamping") {
00093     CLocalDampingIGP *params=extractLocalDampingIGP(&param_buffer);
00094     console.Debug() << "add rotational damping\n";
00095     DG=new ParallelInteractionStorage_Single<T,CRotLocalDamping<T> >(this->m_ppa,*params); // dodgy
00096     damping_name="RotLocalDamping";
00097     res=true;
00098     // add to map
00099     this->m_damping.insert(make_pair(damping_name,DG));
00100     this->m_damping[damping_name]->update();
00101   } else {
00102     res=TSubLattice<T>::doAddDamping(type,param_buffer);
00103   }
00104 
00105   return res;
00106 }
00107 
00112 template <class T>
00113 void TRotSubLattice<T>::addRotBondedIG()
00114 {
00115   console.XDebug()  << "TSubLattice<T>::addRotBondedIG()\n";
00116   CVarMPIBuffer param_buffer(this->m_comm);
00117   vector<int> conns;
00118 
00119   // get params
00120   param_buffer.receiveBroadcast(0);
00121   int tag=param_buffer.pop_int();
00122   string name=string(param_buffer.pop_string());
00123   double kr = param_buffer.pop_double();
00124   double ks = param_buffer.pop_double();
00125   double kt = param_buffer.pop_double();
00126   double kb = param_buffer.pop_double();
00127   double max_nForce  = param_buffer.pop_double();
00128   double max_shForce = param_buffer.pop_double();
00129   double max_tMoment = param_buffer.pop_double();
00130   double max_bMoment = param_buffer.pop_double();
00131   bool   scaling = static_cast<bool>(param_buffer.pop_int());
00132   
00133   conns = TSubLattice<T>::m_temp_conn[tag];
00134 
00135   console.XDebug()
00136     << "Got RotBondedIG parameters: tag=" << tag
00137     << ", name=" << name.c_str()
00138     << ", kr=" << kr
00139     << ", ks=" << ks
00140     << ", kt=" << kt
00141     << ", kb=" << kb
00142     << ", nFrc=" << max_nForce
00143     << ", sFrc=" << max_shForce
00144     << ", tMom=" << max_tMoment
00145     << ", bMom=" << max_bMoment
00146     << ", scaling=" << scaling
00147     << "\n";
00148   // setup InteractionGroup
00149   CRotBondedIGP param;
00150   param.tag=tag;
00151   param.kr=kr;
00152   param.ks=ks;
00153   param.kt=kt;
00154   param.kb=kb;
00155   param.max_nForce = max_nForce ;
00156   param.max_shForce = max_shForce ;
00157   param.max_tMoment = max_tMoment ;
00158   param.max_bMoment = max_bMoment ;
00159   param.scaling = scaling;
00160   ParallelInteractionStorage_EB<CRotParticle,CRotBondedInteraction> *B_PIS = 
00161     new ParallelInteractionStorage_EB<CRotParticle,CRotBondedInteraction>(this->m_ppa,param);
00162 
00163  // recv broadcast connection data
00164  // console.XDebug() << "rank=" << this->m_tml_comm.rank() << "TSubLattice<T>::addRotBondedIG(): receiving conn_data.\n";
00165  // vector<int> conn_data;
00166  // this->m_tml_comm.recv_broadcast_cont(conn_data,0);
00167  // console.XDebug() << "rank=" <<this->m_tml_comm.rank() << "TSubLattice<T>::addRotBondedIG(): conn_data.size()=" << conn_data.size() << "\n";
00168  vector<int> vi(2,-1);
00169   for(size_t i=0;i<conns.size();i+=2){
00170     vi[0] = (conns[i]);
00171     vi[1] = (conns[i+1]);
00172     B_PIS->tryInsert(vi);
00173   }
00174 
00175   // add InteractionGroup to map
00176   this->m_bpis.insert(make_pair(name,B_PIS));
00177 
00178   console.XDebug()  << "end TSubLattice<T>::addRotBondedIG()\n";
00179 }
00180  
00185 template <class T>
00186 void TRotSubLattice<T>::addRotThermBondedIG()
00187 {
00188   console.XDebug()  << "TRotSubLattice<T>::addRotThermBondedIG()\n";
00189   CVarMPIBuffer param_buffer(this->m_comm);
00190   vector<int> conns;
00191 
00192   // get params
00193   param_buffer.receiveBroadcast(0);
00194   int tag=param_buffer.pop_int();
00195   string name=string(param_buffer.pop_string());
00196   double kr = param_buffer.pop_double();
00197   double ks = param_buffer.pop_double();
00198   double kt = param_buffer.pop_double();
00199   double kb = param_buffer.pop_double();
00200   double max_nForce  = param_buffer.pop_double();
00201   double max_shForce = param_buffer.pop_double();
00202   double max_tMoment = param_buffer.pop_double();
00203   double max_bMoment = param_buffer.pop_double();
00204   double diffusivity = param_buffer.pop_double();
00205 
00206   conns = TSubLattice<T>::m_temp_conn[tag];
00207 
00208   console.XDebug()
00209     << "Got RotThermBondedIG parameters: tag=" << tag
00210     << ", name=" << name.c_str()
00211     << ", kr=" << kr
00212     << ", ks=" << ks
00213     << ", kt=" << kt
00214     << ", kb=" << kb
00215     << ", nFrc=" << max_nForce
00216     << ", sFrc=" << max_shForce
00217     << ", tMom=" << max_tMoment
00218     << ", bMom=" << max_bMoment
00219     << ", diffusivity=" << diffusivity
00220     << "\n";
00221   // setup InteractionGroup
00222   CRotThermBondedIGP param;
00223   param.tag = tag;
00224   param.kr=kr;
00225   param.ks=ks;
00226   param.kt=kt;
00227   param.kb=kb;
00228   param.max_nForce = max_nForce ;
00229   param.max_shForce = max_shForce ;
00230   param.max_tMoment = max_tMoment ;
00231   param.max_bMoment = max_bMoment ;
00232   param.diffusivity = diffusivity ;
00233   ParallelInteractionStorage_E<CRotThermParticle,CRotThermBondedInteraction> *B_PIS = 
00234     new ParallelInteractionStorage_EB<CRotThermParticle,CRotThermBondedInteraction>(this->m_ppa,param);
00235 
00236  // recv broadcast connection data
00237  // console.XDebug() << "rank=" << this->m_tml_comm.rank() << "TSubLattice<T>::addRotThermBondedIG(): receiving conn_data.\n";
00238  // vector<int> conn_data;
00239  // this->m_tml_comm.recv_broadcast_cont(conn_data,0);
00240  // console.XDebug() << "rank=" <<this->m_tml_comm.rank() << "TSubLattice<T>::addRotThermBondedIG(): conn_data.size()=" << conn_data.size() << "\n";
00241  vector<int> vi(2,-1);
00242   for(size_t i=0;i<conns.size();i+=2){
00243     vi[0] = (conns[i]);
00244     vi[1] = (conns[i+1]);
00245     B_PIS->tryInsert(vi);
00246   }
00247 
00248   // add InteractionGroup to map
00249   this->m_bpis.insert(make_pair(name,B_PIS));
00250 
00251   console.XDebug()  << "end TRotSubLattice<T>::addRotThermBondedIG()\n";
00252 }