// // slbmpi.h // MHDA // // Created by Dr. Jacques C. Richard on 1/31/12. // #ifndef _slbmpi_h #define _slbmpi_h #include #include const double c1_3 = 1.e0/3.e0; const double c1_18 = 1.e0/18.e0; const double c1_36 = 1.e0/36.e0; const double w_epsi=3.0e0; const double w_epsi_j=-11.0e0/2.0e0; const double w_xx=-1.e0/2.0e0; //const double c4=1.e0/4.e0; //JCR: un-used const double c8=1.e0/8.e0; const double c10=1.e0/10.0e0; const double c12=1.e0/12.0; const double c18=1.e0/18.0; const double c19=1.e0/19.0; const double c21=1.e0/21.0; const double c23=2.0e0/3.0; const double c24=1.e0/24.0; const double c36=1.e0/36.0; const double c40=1.e0/40.0; const double c63=1.e0/63.0; const double c252=1.e0/252.0; const double c399=5.e0/399.0; const double c1197=4.e0/1197.0; const double c2394=11.e0/2394.0; const double rh0=1.0e0; //KGK Function to set lattice ID for a lattice struct lattice_ID { int mm,nn,rr; const int MM,NN,RR; lattice_ID (int& mm1, int& nn1, int& rr1, int& MM1, int& NN1, int& RR1) : mm(mm1),nn(nn1),rr(rr1),MM(MM1),NN(NN1),RR(RR1) {} void operator()(lattice_type& lattice) { if (rr > RR) { rr = 1; nn++; if (nn > NN) { nn = 1; mm++; } } lattice.rr = rr++; lattice.nn = nn; lattice.mm = mm; if (mm > MM || nn > NN) std::cout << " Error in lattice_ID in math_functions.h " << std::endl; } }; //KGK Interface function to set lattice ID for all lattices in the grid void set_lattice_ID(const xyz_type PhysicalSpaceSize, grid_type& grid) { int MM = PhysicalSpaceSize.x+2; int NN = PhysicalSpaceSize.y+2; int RR = PhysicalSpaceSize.z+2; int mm=1; int nn=1; int rr=1; std::for_each(grid.begin(), grid.end(), lattice_ID(mm, nn, rr, MM, NN, RR)); }; template struct init_internal_neighbors_wf { #ifdef BOOST_MPI_HPP const boost::mpi::communicator &world ; init_internal_neighbors_wf( const boost::mpi::communicator &W ) : world( W ) { } #endif void operator()(T& lattice) const { //JCR: NT, for some reason, used (x,y,z)_offset[1..en] = - (cx, cy, cz)[1..en] here?! Is that to use "+" in idx._ + _offset? const int x_offset[ en - 1 ] = {-1, 1, 0, 0, 0, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 0, 0, 0}; const int y_offset[ en - 1 ] = { 0, 0, -1, 1, 0, 0, -1, -1, 1, 1, 0, 0, 0, 0, -1, 1, -1, 1}; const int z_offset[ en - 1 ] = { 0, 0, 0, 0, -1, 1, 0, 0, 0, 0, -1, -1, 1, 1, -1, -1, 1, 1}; const xyz_type& idx = lattice.idx; const xyz_type& dims = lattice.dims; for (int i=0; i < en - 1; i++) { #ifdef BOOST_MPI_HPP if ( world.size() > 1 ) //( ( idx > T::dims / world.size() ) || ( idx.x < 0 ) || ( idx.y < 0 ) || ( idx.z < 0 ) ) { std::vector< boost::mpi::request > reqs ; std::vector< T > Neighbor2Proc ; std::vector< T > Neighbor4Proc( en - 1 ) ; int Sender = world.rank( ) ; // also = tag & dest & src int Receiver = Sender + 1 ; if(Receiver >= world.size())Receiver = Sender - 1 ;if(( Receiver<0)||(Receiver==Sender)) return ; int SendTag = 0 ; int RecvTag = 1 ; int NewOffset_x = 0 ; // ( idx.x > T::dims.x / world.size() ? abs( x_offset[i] ) : x_offset[i] ) ; int NewOffset_y = 0 ; // ( idx.y > T::dims.y / world.size() ? abs( y_offset[i] ) : y_offset[i] ) ; int NewOffset_z = 0 ; // ( idx.z > T::dims.z / world.size() ? abs( z_offset[i] ) : z_offset[i] ) ; Neighbor2Proc.push_back (*(T::begin_iterator + T::offset(idx.x+x_offset[i]-NewOffset_x, idx.y+y_offset[i]-NewOffset_y, idx.z+z_offset[i]-NewOffset_z))); //Neighbor2Proc[ Sender ] = (*(T::begin_iterator + T::offset(idx.x+x_offset[i]-NewOffset_x, idx.y+y_offset[i]-NewOffset_y, idx.z+z_offset[i]-NewOffset_z))); long int Msg2Send_size = Neighbor2Proc.size() ; // T::begin_iterator + ; Msg2Send_size += (idx.x+x_offset[i]-NewOffset_x)*(idx.y+y_offset[i]-NewOffset_y)*(idx.z+z_offset[i]-NewOffset_z) ; std::copy( Neighbor2Proc.begin() , Neighbor2Proc.end() , Neighbor4Proc.begin() ) ; // a dflt !? #ifdef DEBUG std::cout<< "\ninit_internal_neighbors_wf: Process "< 0 ) // if @ a location w/something 2 exchange?! { std::cerr << "DEBUG: slbmpi.h:" << __LINE__ << std::endl << std::flush; // ORIG: reqs.push_back( world.isend( Sender , SendTag , &Neighbor2Proc[ i ] , Msg2Send_size ) ) ; reqs.push_back( world.isend( Receiver , SendTag , Neighbor2Proc[i] ) ); #ifdef DEBUG std::cout<< "\ninit_internal_neighbors_wf: Process "<() << " from " << msg.source() << " with tag " << msg.tag() << std::endl << std::flush; }; #endif SendTag = ( SendTag == msg.source() ? msg.source() : SendTag ) ; //SendTag = msg.source() ; RecvTag = msg.tag() ; reqs.push_back( world.irecv( msg.source() , msg.tag() , Neighbor4Proc[ i ] ) ) ; // , Msg2Send_size: not compiling: request irecv(int source, int tag, T * values, int n) const; @ http://www.boost.org/doc/libs/1_48_0/doc/html/boost/mpi/communicator.html#id444949-bb #ifdef DEBUG std::cout<< "\ninit_internal_neighbors_wf: Process "<=0 && (idx.y+y_offset[i])>=0 && (idx.z+z_offset[i])>=0 && (idx.x+x_offset[i])mm; lattice.neighborID[i][1] = lattice.neighbors[i]->nn; lattice.neighborID[i][2] = lattice.neighbors[i]->rr; } } }; struct init_f { const IBC_data &IBc_Data ; const int solver ; const int compres ; const std::vector &v, &b, &e ; const r_Space &t_0, &r_0 ; init_f(const IBC_data &IBc_Dat, const int Solver, const int Compres , const std::vector &V, const std::vector &B, const std::vector &E, const r_Space &T0, const r_Space &R0 ) : IBc_Data(IBc_Dat), solver(Solver), compres(Compres), v(V), b(B), e(E), t_0(T0), r_0(R0) { } void operator()(lattice_type& lattice) const { const int n = lattice.offset(lattice.idx.x, lattice.idx.y, lattice.idx.z);//cout<<" Checking: idx="< 0 ) lattice.u = v[ n ] ; //if when=t4ReStart b4 init_f; OVERRIDES is_velinlet ck lattice.B = b[ n ] ; lattice.E = e[ n ] ; lattice.T = t_0[ n ] ; lattice.rho = r_0[ n ] ; lattice.A = 0.0 ; // MUST initialize lattice.J = lattice.rho * lattice.u ; lattice.curlJ = 0.0 ; lattice.gradrho = 0.0 ; lattice.Phi = 0.0 ; { Normalizer = 1.0 ; lattice.rho = rh0; lattice.fi[0] = c1_3*rh0; std::fill(lattice.fi + 1, lattice.fi + 7, c1_18 * rh0); std::fill(lattice.fi + 7, lattice.fi + en, c1_36 * rh0); } lattice.T = 0.0 ; // to get from f instead of pre-set for(int i=0; i<=en-1;i++) { lattice.T += ( cix[i] * cix[i] + ciy[i] * ciy[i] + ciz[i] * ciz[i] ) * lattice.fi[i] / lattice.rho ; //really m(v_molec_av)^2/2 =(3/2)k_B T but try this } lattice.p = Fluid_Species::p_EqState(lattice.rho,lattice.T) ; //actually p_d or p_u could be used but don't want to over-specify p(r,T) std::copy(lattice.fi, lattice.fi + en, lattice.old_fi); #ifdef DEBUG // if( n == 0 ) std::cout<<"\n @ all n for 7>Solver>2 else @ n=0=(i,j,k), setting Normalizer="<1.0e10) || isinf(lattice.fi[i]) || isnan(lattice.fi[i]) || (fabs(lattice.fi[i])10.0) || (lattice.rho10.0)||(lattice.rho1.0e10) || isinf(lattice.fi[i]) || isnan(lattice.fi[i]) || (fabs(lattice.fi[i])>1.0e1) ) { cout<<" fi[i="<