示例#1
0
文件: main.cpp 项目: atrtnkw/sph
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;
}
示例#2
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;
}