int main(int argc, char **argv) { PS::Initialize(argc, argv); PS::S32 rank = PS::Comm::getRank(); PS::S32 size = PS::Comm::getNumberOfProc(); Header header; PS::DomainInfo dinfo; dinfo.initialize(); PS::ParticleSystem<GeneralSPH> sph; sph.initialize(); sph.createParticle(0); sph.setNumberOfParticleLocal(0); PS::TreeForForceShort<Quantity, QuantityEPI, QuantityEPJ>::Symmetry quantity; quantity.initialize(0); header.nptcl = atoi(argv[1]); sph.readParticleAscii(argv[2], header); dinfo.decomposeDomainAll(sph); sph.exchangeParticle(dinfo); quantity.calcForceAllAndWriteBack(calcQuantity(), sph, dinfo); sph.writeParticleAscii(argv[3]); PS::Finalize(); return 0; }
int main(int argc, char* argv[]){ ////////////////// //Create vars. ////////////////// PS::Initialize(argc, argv); PS::ParticleSystem<RealPtcl> sph_system; sph_system.initialize(); PS::DomainInfo dinfo; dinfo.initialize(); PS::F64 dt, end_time; ////////////////// //Disp. Info ////////////////// DisplayInfo(); ////////////////// //Setup Initial ////////////////// SetupIC(sph_system, &end_time, dinfo); Initialize(sph_system); //Dom. info dinfo.setDomain(PS::Comm::getNumberOfProc(), 1, 1); dinfo.decomposeDomain(); sph_system.exchangeParticle(dinfo); //plant tree PS::TreeForForceShort<RESULT::Dens , EPI::Dens , EPJ::Dens >::Gather dens_tree; PS::TreeForForceShort<RESULT::Drvt , EPI::Drvt , EPJ::Drvt >::Gather drvt_tree; PS::TreeForForceShort<RESULT::Hydro, EPI::Hydro, EPJ::Hydro>::Symmetry hydr_tree; PS::TreeForForceLong <RESULT::Grav , EPI::Grav , EPJ::Grav >::Monopole grav_tree; dens_tree.initialize(sph_system.getNumberOfParticleGlobal()); drvt_tree.initialize(sph_system.getNumberOfParticleGlobal()); hydr_tree.initialize(sph_system.getNumberOfParticleGlobal()); grav_tree.initialize(sph_system.getNumberOfParticleGlobal()); for(int loop = 0 ; loop <= 5 ; ++ loop){ dens_tree.calcForceAllAndWriteBack(CalcDensity() , sph_system, dinfo); } for(PS::S32 i = 0 ; i < sph_system.getNumberOfParticleLocal() ; ++ i){ sph_system[i].setPressure(); } drvt_tree.calcForceAllAndWriteBack(CalcDerivative(), sph_system, dinfo); hydr_tree.calcForceAllAndWriteBack(CalcHydroForce(), sph_system, dinfo); //grav_tree.calcForceAllAndWriteBack(CalcGravityForce(), sph_system, dinfo); grav_tree.calcForceAllAndWriteBack(CalcGravityForce<EPJ::Grav>(), CalcGravityForce<PS::SPJMonopole>(), sph_system, dinfo); dt = getTimeStepGlobal(sph_system); std::cout << std::scientific << std::setprecision(16) << "time = " << time << ", dt = " << dt << std::endl; PS::S32 step = 0; for(PS::F64 time = 0 ; time < end_time ; time += dt, ++ step){ InitialKick(sph_system, dt); FullDrift(sph_system, dt); sph_system.adjustPositionIntoRootDomain(dinfo); Predict(sph_system, dt); dinfo.decomposeDomain(); sph_system.exchangeParticle(dinfo); for(int loop = 0 ; loop <= 2 ; ++ loop){ dens_tree.calcForceAllAndWriteBack(CalcDensity() , sph_system, dinfo); } for(PS::S32 i = 0 ; i < sph_system.getNumberOfParticleLocal() ; ++ i){ sph_system[i].setPressure(); } //std::cout << "push enter..." << std::endl; //getchar(); drvt_tree.calcForceAllAndWriteBack(CalcDerivative(), sph_system, dinfo); hydr_tree.calcForceAllAndWriteBack(CalcHydroForce(), sph_system, dinfo); //grav_tree.calcForceAllAndWriteBack(CalcGravityForce(), sph_system, dinfo); grav_tree.calcForceAllAndWriteBack(CalcGravityForce<EPJ::Grav>(), CalcGravityForce<PS::SPJMonopole>(), sph_system, dinfo); dt = getTimeStepGlobal(sph_system); FinalKick(sph_system, dt); if(step % PARAM::OUTPUT_INTERVAL == 0){ FileHeader header; header.time = time; header.Nbody = sph_system.getNumberOfParticleGlobal(); char filename[256]; sprintf(filename, "result/%04d.dat", step); sph_system.writeParticleAscii(filename, header); if(PS::Comm::getRank() == 0){ std::cout << "//================================" << std::endl; std::cout << "output " << filename << "." << std::endl; std::cout << "//================================" << std::endl; } } if(PS::Comm::getRank() == 0){ std::cout << "//================================" << std::endl; std::cout << std::scientific << std::setprecision(16) << "time = " << time << ", dt = " << dt << std::endl; std::cout << "step = " << step << std::endl; std::cout << "//================================" << std::endl; } CheckConservativeVariables(sph_system); } PS::Finalize(); return 0; }
int main(int argc, char *argv[]) { PS::F32 time = 0.0; PS::F32 tend = 10.0; PS::F32 dtime = 1.0 / 128.0; PS::F32 dtout = 1.0 / 8.0; PS::S64 ntot = 1024; PS::Initialize(argc, argv); PS::DomainInfo dinfo; dinfo.initialize(); PS::ParticleSystem<FPGrav> system_grav; system_grav.initialize(); PS::TreeForForceLong<FPGrav, FPGrav, FPGrav>:: Monopole tree_grav; tree_grav.initialize(ntot); setParticleColdUniformSphere(system_grav, ntot); dinfo.decomposeDomainAll(system_grav); system_grav.exchangeParticle(dinfo); tree_grav.calcForceAllAndWriteBack (CalcGravity<FPGrav>(), CalcGravity<PS::SPJMonopole>(), system_grav, dinfo); PS::F64 etot0 = calcEnergy(system_grav); if(PS::Comm::getRank() == 0) { fprintf(stderr, "time: %10.7f energy: %+e energy error: %+e\n", time, etot0, (etot0 - etot0) / etot0); } while(time < tend) { predict(system_grav, dtime); dinfo.decomposeDomainAll(system_grav); system_grav.exchangeParticle(dinfo); tree_grav.calcForceAllAndWriteBack (CalcGravity<FPGrav>(), CalcGravity<PS::SPJMonopole>(), system_grav, dinfo); correct(system_grav, dtime); time += dtime; PS::F64 etot1 = calcEnergy(system_grav); if(fmod(time, dtout) == 0.0 && PS::Comm::getRank() == 0) { fprintf(stderr, "time: %10.7f energy: %+e energy error: %+e\n", time, etot1, (etot1 - etot0) / etot0); } } PS::Finalize(); return 0; }