Ко всем библиотекам · PBHCosmo (GRChombo)

grchombo/PBHCosmo/Main_PBHCosmo.cpp

Chombo includes

112 строк · 3.3 KB · pbhgr @ 9e8e13d · как текст

/* GRChombo
 * Copyright 2012 The GRChombo collaboration.
 * Please refer to LICENSE in GRChombo's root directory.
 */

// Chombo includes
#include "parstream.H" //Gives us pout()

// System includes
#include <iostream>

// Our general includes
#include "CosmoAMR.hpp"
#include "DefaultLevelFactory.hpp"
#include "GRParmParse.hpp"
#include "MultiLevelTask.hpp"
#include "SetupFunctions.hpp"
#include "SimulationParameters.hpp"

// Problem specific includes:
#include "PBHCosmoLevel.hpp"

// Chombo namespace
#include "UsingNamespace.H"

int runGRChombo(int argc, char *argv[])
{
    // Load the parameter file and construct the SimulationParameter class
    // To add more parameters edit the SimulationParameters file.
    char *in_file = argv[1];
    GRParmParse pp(argc - 2, argv + 2, NULL, in_file);
    SimulationParameters sim_params(pp);

    if (sim_params.just_check_params)
        return 0;

    // The line below selects the problem that is simulated
    // (To simulate a different problem, define a new child of AMRLevel
    // and an associated LevelFactory)
    CosmoAMR cosmo_amr;
    DefaultLevelFactory<PBHCosmoLevel> pbh_level_fact(cosmo_amr,
                                                            sim_params);
    setupAMRObject(cosmo_amr, pbh_level_fact);
    if (sim_params.use_subcycling == 0)
    {
        pout() << "PBHCosmo: time subcycling OFF" << std::endl;
        cosmo_amr.useSubcyclingInTime(false);
    }
    if (sim_params.fixed_dt > 0.)
    {
        pout() << "PBHCosmo: fixed dt = " << sim_params.fixed_dt << " on all levels" << std::endl;
        cosmo_amr.fixedDt(sim_params.fixed_dt);
    }

    // call this after amr object setup so grids known
    // and need it to stay in scope throughout run
    AMRInterpolator<Lagrange<4>> interpolator(
        cosmo_amr, sim_params.origin, sim_params.dx, sim_params.boundary_params,
        sim_params.verbosity);
    cosmo_amr.set_interpolator(&interpolator);

#ifdef USE_AHFINDER
    if (sim_params.AH_activate)
    {
        AHSurfaceGeometry sph(sim_params.center);
        cosmo_amr.m_ah_finder.add_ah(sph, sim_params.AH_initial_guess,
                                     sim_params.AH_params);
    }
#endif

    using Clock = std::chrono::steady_clock;
    using Minutes = std::chrono::duration<double, std::ratio<60, 1>>;

    std::chrono::time_point<Clock> start_time = Clock::now();

    // Add a scheduler to call specificPostTimeStep on every AMRLevel at t=0
    auto task = [](GRAMRLevel *level)
    {
        if (level->time() == 0.)
            level->specificPostTimeStep();
    };
    MultiLevelTaskPtr<> call_task(task);
    call_task.execute(cosmo_amr);
    // Engage! Run the evolution
    cosmo_amr.run(sim_params.stop_time, sim_params.max_steps);

    auto now = Clock::now();
    auto duration = std::chrono::duration_cast<Minutes>(now - start_time);
    pout() << "Total simulation time (mins): " << duration.count() << ".\n";

    cosmo_amr.conclude();

    CH_TIMER_REPORT(); // Report results when running with Chombo timers.

    return 0;
}

int main(int argc, char *argv[])
{
    mainSetup(argc, argv);

    int status = runGRChombo(argc, argv);

    if (status == 0)
        pout() << "GRChombo finished." << std::endl;
    else
        pout() << "GRChombo failed with return code " << status << std::endl;

    mainFinalize();
    return status;
}