Ejemplo n.º 1
0
/******************
 *  unit test of QSS2 on lotka_volterra model,
 *  based  on powerdevs results
 *
 *  note: results have to be the same as test_QSS2_LotkaVolterra
 ******************/
void test_QSS2_LotkaVolterraXY()
{
    auto ctx = vu::make_context();
    std::cout << "  test_QSS2_LotkaVolterraXY " << std::endl;
    vle::utils::Package pack(ctx, "vle.ode_test");
    std::unique_ptr<vz::Vpz> vpz(new vz::Vpz(pack.getExpFile("LotkaVolterraXY.vpz", vle::utils::PKG_BINARY)));
    ttconfOutputPlugins(*vpz);

    {
        std::vector<std::string> conds;
        conds.push_back("condLV");
        conds.push_back("condQSS2");
        conds.push_back("condQSS2_X");
        ttattachConditions(*vpz,conds,"LotkaVolterraX");
    }
    {
        std::vector<std::string> conds;
        conds.push_back("condLV");
        conds.push_back("condQSS2");
        conds.push_back("condQSS2_Y");
        ttattachConditions(*vpz,conds,"LotkaVolterraY");
    }

    //simulation
    vm::Error error;
    vm::Simulation sim(ctx, vm::LOG_NONE, vm::SIMULATION_NONE,
            std::chrono::milliseconds(0), &std::cout);
    std::unique_ptr<va::Map> out = sim.run(std::move(vpz), &error);

    //checks that simulation has succeeded
    EnsuresEqual(error.code, 0);
    //checks the number of views
    EnsuresEqual(out->size(),1);
    //checks the selected view
    const va::Matrix& view = out->getMatrix("view");
    EnsuresEqual(view.columns(),3);
    //note: the number of rows depend on the averaging of sum of 0.01
    Ensures(view.rows() <= 15003);
    Ensures(view.rows() >= 15002);

    //gets X,Y
    int colX = ttgetColumnFromView(view, "Top model:LotkaVolterraX", "X");
    int colY = ttgetColumnFromView(view, "Top model:LotkaVolterraY", "Y");

    //check X,Y line 15000
    EnsuresApproximatelyEqual(view.getDouble(colX,15001), 0.69363324986147468, 10e-5);
    //previous 0.696088281553273

    EnsuresApproximatelyEqual(view.getDouble(colY,15001), 0.07761934820509947, 10e-5);
    //previous 0.0774536442779648
}
Ejemplo n.º 2
0
/******************
 *  Unit test based on powerdevs
 ******************/
void test_QSS2_Seir()
{
    auto ctx = vu::make_context();
    std::cout << "  test_QSS2_Seir " << std::endl;
    vle::utils::Package pack(ctx, "vle.ode_test");
    std::unique_ptr<vz::Vpz> vpz(new vz::Vpz(pack.getExpFile("Seir.vpz", vle::utils::PKG_BINARY)));

    ttconfOutputPlugins(*vpz);

    std::vector<std::string> conds;
    conds.push_back("condQSS2");
    conds.push_back("condSeir");
    ttattachConditions(*vpz,conds,"Seir");

    //simulation
    vm::Error error;
    vm::Simulation sim(ctx, vm::LOG_NONE, vm::SIMULATION_NONE,
            std::chrono::milliseconds(0), &std::cout);
    std::unique_ptr<va::Map> out = sim.run(std::move(vpz), &error);

    //checks that simulation has succeeded
    EnsuresEqual(error.code, 0);
    //checks the number of views
    EnsuresEqual(out->size(),1);
    //checks the selected view
    const va::Matrix& view = out->getMatrix("view");
    EnsuresEqual(view.columns(),5);
    //note: the number of rows depend on the averaging of sum of 0.01
    Ensures(view.rows() <= 1503);
    Ensures(view.rows() >= 1502);


    //gets S,E,I,R
    int colS = ttgetColumnFromView(view, "Top model:Seir", "S");
    int colE = ttgetColumnFromView(view, "Top model:Seir", "E");
    int colI = ttgetColumnFromView(view, "Top model:Seir", "I");
    int colR = ttgetColumnFromView(view, "Top model:Seir", "R");

    //check S,E,I,R line 1500
    EnsuresApproximatelyEqual(view.getDouble(colS,1501), 0.636836529382071, 10e-5);
    EnsuresApproximatelyEqual(view.getDouble(colE,1501), 0.636051925651117, 10e-5);
    EnsuresApproximatelyEqual(view.getDouble(colI,1501), 2.95405622447345, 10e-5);
    EnsuresApproximatelyEqual(view.getDouble(colR,1501), 6.77305532047774, 10e-5);

}
Ejemplo n.º 3
0
/******************
 *  Unit test for testing coupling of different integration methods and
 *  simultaneous perturbations, only the success of simulation is
 *  tested
 ******************/
void test_coupling()
{
    auto ctx = vu::make_context();
    std::cout << "  test_coupling " << std::endl;
    vle::utils::Package pack(ctx, "vle.ode_test");
    std::unique_ptr<vz::Vpz> vpz(new vz::Vpz(
                                     pack.getExpFile("PerturbSeirXY.vpz", vle::utils::PKG_BINARY)));


    ttconfOutputPlugins(*vpz);

    //simulation
    vm::Error error;
    vm::Simulation sim(ctx, vm::LOG_NONE, vm::SIMULATION_NONE,
                       std::chrono::milliseconds(0), &std::cout);
    std::unique_ptr<va::Map> out = sim.run(std::move(vpz), &error);

    //checks that simulation has succeeded
    EnsuresEqual(error.code, 0);
    //checks the number of views
    EnsuresEqual(out->size(),1);

}