int main (int __argc, char *__argv[]) { peo :: init( __argc, __argv ); if (getNodeRank()==1) std::cout<<"\n\nTest : PSO Global Best\n\n"; rng.reseed (10); RingTopology topologyMig; eoGenContinue < Indi > genContPara (10); eoCombinedContinue <Indi> continuatorPara (genContPara); eoCheckPoint<Indi> checkpoint(continuatorPara); peoEvalFunc<Indi, double, const Indi& > plainEval(f); peoPopEval< Indi > eval(plainEval); eoUniformGenerator < double >uGen (0, 1.); eoInitFixedLength < Indi > random (2, uGen); eoUniformGenerator < double >sGen (-1., 1.); eoVelocityInitFixedLength < Indi > veloRandom (2, sGen); eoFirstIsBestInit < Indi > localInit; eoRealVectorBounds bndsFlight(2,0,1.); eoStandardFlight < Indi > flight(bndsFlight); eoPop < Indi > pop; pop.append (10, random); eoLinearTopology<Indi> topology(2); eoRealVectorBounds bnds(2,-1.,1.); eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds); eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop); eoPeriodicContinue< Indi > mig_cont( 2 ); peoPSOSelect<Indi> mig_selec(topology); peoGlobalBestVelocity<Indi> mig_replac (2.,velocity); eoContinuator<Indi> cont(mig_cont, pop); eoSelector <Indi, eoPop<Indi> > mig_select (mig_selec,1,pop); eoReplace <Indi, eoPop<Indi> > mig_replace (mig_replac,pop); eoGenContinue < Indi > genContPara2 (10); eoCombinedContinue <Indi> continuatorPara2 (genContPara2); eoCheckPoint<Indi> checkpoint2(continuatorPara2); peoEvalFunc<Indi, double, const Indi& > plainEval2(f); peoPopEval< Indi > eval2(plainEval2); eoUniformGenerator < double >uGen2 (0, 1.); eoInitFixedLength < Indi > random2 (2, uGen2); eoUniformGenerator < double >sGen2 (-1., 1.); eoVelocityInitFixedLength < Indi > veloRandom2 (2, sGen2); eoFirstIsBestInit < Indi > localInit2; eoRealVectorBounds bndsFlight2(2,0,1.); eoStandardFlight < Indi > flight2(bndsFlight2); eoPop < Indi > pop2; pop2.append (10, random2); eoLinearTopology<Indi> topology2(2); eoRealVectorBounds bnds2(2,-1.,1.); eoStandardVelocity < Indi > velocity2 (topology2,1,0.5,2.,bnds2); eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2); eoPeriodicContinue< Indi > mig_cont2( 2 ); peoPSOSelect<Indi> mig_selec2(topology2); peoGlobalBestVelocity<Indi> mig_replac2 (2.,velocity2); eoContinuator<Indi> cont2(mig_cont2,pop2); eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_selec2,1,pop2); eoReplace <Indi, eoPop<Indi> > mig_replace2 (mig_replac2,pop2); peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig); checkpoint.add( mig ); peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig); checkpoint2.add( mig2 ); eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight); peoWrapper parallelPSO( psa, pop); eval.setOwner(parallelPSO); mig.setOwner(parallelPSO); eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2); peoWrapper parallelPSO2( psa2, pop2); eval2.setOwner(parallelPSO2); mig2.setOwner(parallelPSO2); peo :: run(); peo :: finalize(); if (getNodeRank()==1) { pop.sort(); pop2.sort(); std::cout << "Final population :\n" << pop << std::endl; std::cout << "Final population :\n" << pop2 << std::endl; } }
void peano::applications::faxen::lbf::mappings::RegularGrid2SwitchFromLB2NSE::handleCell( peano::applications::faxen::lbf::RegularGridBlockVertex* const vertices, peano::applications::faxen::lbf::RegularGridBlockCell& cell, const peano::kernel::gridinterface::VertexEnumerator& enumerator ) { logTraceInWith2Arguments( "handleCell()", enumerator.toString(), cell ); // only for 2D implementation /* * positions of LB cells that are used for velocities interpolation * for NSE grid */ tarch::la::Vector<DIMENSIONS,double> positionU0; tarch::la::Vector<DIMENSIONS,double> positionU1; tarch::la::Vector<DIMENSIONS,double> positionU2; tarch::la::Vector<DIMENSIONS,double> positionU3; tarch::la::Vector<DIMENSIONS,double> positionV0; tarch::la::Vector<DIMENSIONS,double> positionV1; tarch::la::Vector<DIMENSIONS,double> positionV2; tarch::la::Vector<DIMENSIONS,double> positionV3; // cellSize tarch::la::Vector<DIMENSIONS,double> cellSize = enumerator.getCellSize(); // cellCenter tarch::la::Vector<DIMENSIONS,double> cellCenter = enumerator.getCellCenter(); // particles index int index; if(LB_BLOCKSIZE%2 == 0) { positionU0[0] = cellCenter[0] + cellSize[0]/2 - _dx/2; positionU0[1] = cellCenter[1] - _dx/2; positionU1[0] = cellCenter[0] + cellSize[0]/2 + _dx/2; positionU1[1] = cellCenter[1] - _dx/2; positionU2[0] = cellCenter[0] + cellSize[0]/2 - _dx/2; positionU2[1] = cellCenter[1] + _dx/2; positionU3[0] = cellCenter[0] + cellSize[0]/2 + _dx/2; positionU3[1] = cellCenter[1] + _dx/2; positionV0[0] = cellCenter[0] - _dx/2; positionV0[1] = cellCenter[1] + cellSize[1]/2 - _dx/2; positionV1[0] = cellCenter[0] + _dx/2; positionV1[1] = cellCenter[1] + cellSize[1]/2 - _dx/2; positionV2[0] = cellCenter[0] - _dx/2; positionV2[1] = cellCenter[1] + cellSize[1]/2 + _dx/2; positionV3[0] = cellCenter[0] +_dx/2; positionV3[1] = cellCenter[1] + cellSize[1]/2 + _dx/2; } else { positionU0[0] = cellCenter[0] + cellSize[0]/2; positionU0[1] = cellCenter[1] - _dx/2; positionU1[0] = cellCenter[0] + cellSize[0]/2; positionU1[1] = cellCenter[1] + _dx/2; positionV0[0] = cellCenter[0] - _dx/2; positionV0[1] = cellCenter[1] + cellSize[1]/2; positionV1[0] = cellCenter[0] + _dx/2; positionV1[1] = cellCenter[1] + cellSize[1]/2; } // load bottom left vertex peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance(). loadVertex(vertices[enumerator(0)].getVertexNumber()); std::bitset<LB_BLOCK_NUMBER_OF_CELLS>& inner0( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getInner()); tarch::la::Vector<LB_BLOCK_NUMBER_OF_CELLS,double>& density0( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getDensity()); _p[0] = inner0[LB_BLOCK_NUMBER_OF_CELLS-1] ? density0[LB_BLOCK_NUMBER_OF_CELLS-1] : 0.0; // load bottom right vertex peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance(). loadVertex(vertices[enumerator(1)].getVertexNumber()); std::bitset<LB_BLOCK_NUMBER_OF_CELLS>& inner1( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getInner()); tarch::la::Vector<LB_BLOCK_NUMBER_OF_CELLS,double>& density1( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getDensity()); _p[1] = inner1[LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE] ? density1[LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE] : 0.0; tarch::la::Vector<LB_BLOCK_NUMBER_OF_CELLS*DIMENSIONS,double>& velocity1(peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getVelocity()); if(LB_BLOCKSIZE%2 == 0) { if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionU0)) != -1 ){ _u[0] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[0]/_dxbydt; } else { _u[0] = inner1[(2*LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE-2)/2] ? velocity1[2*LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE-2] : 0.0; } if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionU1)) != -1 ){ _u[1] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[0]/_dxbydt; } else { _u[1] = inner1[(2*LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE)/2] ? velocity1[2*LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE] : 0.0; } } else { if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionU0)) != -1 ){ _u[0] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[0]/_dxbydt; } else { _u[0] = inner1[(2*LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE)/2] ? velocity1[2*LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE] : 0.0; } } // load top left vertex peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance(). loadVertex(vertices[enumerator(2)].getVertexNumber()); std::bitset<LB_BLOCK_NUMBER_OF_CELLS>& inner2( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getInner()); tarch::la::Vector<LB_BLOCK_NUMBER_OF_CELLS,double>& density2( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getDensity()); _p[2] = inner2[LB_BLOCKSIZE-1] ? density2[LB_BLOCKSIZE-1] : 0.0; tarch::la::Vector<LB_BLOCK_NUMBER_OF_CELLS*DIMENSIONS,double>& velocity2( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getVelocity()); if(LB_BLOCKSIZE%2 == 0) { if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionV0)) != -1 ){ _v[0] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[1]/_dxbydt; } else { _v[0] = inner2[(LB_BLOCK_NUMBER_OF_CELLS-1)/2] ? velocity2[LB_BLOCK_NUMBER_OF_CELLS-1] : 0.0; } if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionV2)) != -1 ){ _v[2] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[1]/_dxbydt; } else { _v[2] = inner2[(LB_BLOCK_NUMBER_OF_CELLS+2*LB_BLOCKSIZE-1)/2] ? velocity2[LB_BLOCK_NUMBER_OF_CELLS+2*LB_BLOCKSIZE-1] : 0.0; } } else { if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionV0)) != -1 ){ _v[0] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[1]/_dxbydt; } else { _v[0] = inner2[(LB_BLOCK_NUMBER_OF_CELLS+LB_BLOCKSIZE-1)/2] ? velocity2[LB_BLOCK_NUMBER_OF_CELLS+LB_BLOCKSIZE-1] : 0.0; } } // load top right vertex peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance(). loadVertex(vertices[enumerator(3)].getVertexNumber()); std::bitset<LB_BLOCK_NUMBER_OF_CELLS>& inner3( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getInner()); tarch::la::Vector<LB_BLOCK_NUMBER_OF_CELLS,double>& density3( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getDensity()); _p[3] = inner3[0] ? density3[0] : 0.0; tarch::la::Vector<LB_BLOCK_NUMBER_OF_CELLS*DIMENSIONS,double>& velocity3( peano::applications::latticeboltzmann::blocklatticeboltzmann::services::GridManagementService::getInstance().getVelocity()); if(LB_BLOCKSIZE%2 == 0) { if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionU2)) != -1 ){ _u[2] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[0]/_dxbydt; } else { _u[2] = inner3[(LB_BLOCKSIZE-2)/2] ? velocity3[LB_BLOCKSIZE-2] : 0.0; } if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionU3)) != -1 ){ _u[3] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[0]/_dxbydt; } else { _u[3] = inner3[LB_BLOCKSIZE/2] ? velocity3[LB_BLOCKSIZE] : 0.0; } if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionV1)) != -1 ){ _v[1] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[1]/_dxbydt; } else { _v[1] = inner3[(LB_BLOCK_NUMBER_OF_CELLS-2*LB_BLOCKSIZE+1)/2] ? velocity3[LB_BLOCK_NUMBER_OF_CELLS-2*LB_BLOCKSIZE+1] : 0.0; } if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionV3)) != -1 ){ _v[3] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[1]/_dxbydt; } else { _v[3] = inner3[(LB_BLOCK_NUMBER_OF_CELLS+1)/2] ? velocity3[LB_BLOCK_NUMBER_OF_CELLS+1] : 0.0; } } else { if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionU1)) != -1 ){ _u[1] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[0]/_dxbydt; } else { _u[1] = inner3[(LB_BLOCKSIZE-1)/2] ? velocity3[LB_BLOCKSIZE-1] : 0.0; } if( (index=peano::applications::faxen::lbf::services::ParticlesService::getInstance().belongs2Particle(positionV1)) != -1 ){ _v[1] = peano::applications::faxen::lbf::services::ParticlesService::getInstance().getParticlesVelocity(index)[1]/_dxbydt; } else { _v[1] = inner3[(LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE+1)/2] ? velocity3[LB_BLOCK_NUMBER_OF_CELLS-LB_BLOCKSIZE+1] : 0.0; } } double P_new = ((_p[0]+_p[1]+_p[2]+_p[3])/4)*_dxbydt*_dxbydt*_rho/3; double P_old = cell.getP(); // updating cell's pressure and its averages with neighbors. vertices[enumerator(1)].updateP0(P_old,P_new); vertices[enumerator(2)].updateP1(P_old,P_new); vertices[enumerator(3)].updateP0(P_old,P_new); vertices[enumerator(3)].updateP1(P_old,P_new); cell.setP(P_new); double U_new, V_new; double U_old = cell.getU(); double V_old = cell.getV(); if(LB_BLOCKSIZE%2 == 0) { U_new = _dxbydt*(_u[0]+_u[1]+_u[2]+_u[3])/4; V_new = _dxbydt*(_v[0]+_v[1]+_v[2]+_v[3])/4; } else { U_new = _dxbydt*(_u[0]+_u[1])/2; V_new = _dxbydt*(_v[0]+_v[1])/2; } // updating cell's horizontal velocity and its averages with neighbors. vertices[enumerator(0)].updateU0(U_old,U_new); vertices[enumerator(1)].updateU1(U_old,U_new); vertices[enumerator(1)].updateU0(U_old,U_new); vertices[enumerator(2)].updateU2(U_old,U_new); vertices[enumerator(3)].updateU2(U_old,U_new); vertices[enumerator(2)].updateU0(U_old,U_new); vertices[enumerator(3)].updateU1(U_old,U_new); vertices[enumerator(3)].updateU0(U_old,U_new); cell.setU(U_new); // updating cell's vertical velocity and its averages with neighbors. vertices[enumerator(0)].updateV0(V_old,V_new); vertices[enumerator(1)].updateV1(V_old,V_new); vertices[enumerator(1)].updateV0(V_old,V_new); vertices[enumerator(2)].updateV2(V_old,V_new); vertices[enumerator(3)].updateV2(V_old,V_new); vertices[enumerator(2)].updateV0(V_old,V_new); vertices[enumerator(3)].updateV1(V_old,V_new); vertices[enumerator(3)].updateV0(V_old,V_new); cell.setV(V_new); logTraceOut( "handleCell()" ); }