/**
* @file test/test.cpp
* @author See the AUTHORS file
*/
/*
* Copyright (C) 2012-2016 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#define CATCH_CONFIG_MAIN
#include
#include
#include
#include
#include
#include
struct GlobalParameters
{ };
struct ModelParameters
{ };
using namespace artis::kernel;
using namespace artis::utils;
template < typename T >
using AtomicModel = AbstractAtomicModel < T, DoubleTime, ModelParameters >;
class AModel : public AtomicModel < AModel >
{
public:
enum externals { };
enum internalsB { BX };
enum internalsI { IX };
enum internals { DX };
AModel()
{
internalI(IX, &AModel::_ix);
internalB(BX, &AModel::_bx);
internal(DX, &AModel::_dx);
}
virtual ~AModel()
{ }
void compute(double /* t */, bool /* update */)
{
++_ix;
_bx = not _bx;
++_dx;
}
void init(double /* t */, const ModelParameters& /* parameters */)
{
_ix = 0;
_bx = false;
_dx = 0.;
}
private:
int _ix;
bool _bx;
double _dx;
};
class BModel : public AtomicModel < BModel >
{
public:
enum externalsB { BX };
enum externalsI { IX };
enum externals { DX };
enum internalsB { BY };
enum internalsI { IY };
enum internals { DY };
BModel()
{
externalI(IX, &BModel::_ix);
externalB(BX, &BModel::_bx);
external(DX, &BModel::_dx);
internalI(IY, &BModel::_iy);
internalB(BY, &BModel::_by);
internal(DY, &BModel::_dy);
}
virtual ~BModel()
{ }
void compute(double /* t */, bool update)
{
if (update)
std::cout << "UPDATE" << std::endl;
_iy = _ix + 1;
_by = not _bx;
_dy = _dx + 1;
}
void init(double /* t */, const ModelParameters& /* parameters */)
{
_iy = 0;
_by = false;
_dy = 0.;
}
private:
// externals
int _ix;
bool _bx;
double _dx;
// internals
int _iy;
bool _by;
double _dy;
};
class RootModel :
public artis::kernel::AbstractCoupledModel < RootModel,
artis::utils::DoubleTime,
ModelParameters,
GlobalParameters >
{
public:
enum submodels { A, B };
RootModel()
{
S({ { A, &_a }, { B, &_b } });
}
virtual ~RootModel()
{ }
void compute(double t, bool /* update */)
{
_a(t);
OUT_I(t, &_a, AModel::IX) >> IN_I(t, &_b, BModel::IX);
OUT_B(t, &_a, AModel::BX) >> IN_B(t, &_b, BModel::BX);
OUT(t, &_a, AModel::DX) >> IN(t, &_b, BModel::DX);
_b(t);
}
void init(double t, const ModelParameters& parameters)
{
_a.init(t, parameters);
_b.init(t, parameters);
}
private:
AModel _a;
BModel _b;
};
typedef artis::kernel::Simulator < RootModel,
artis::utils::DoubleTime,
ModelParameters,
GlobalParameters > Simulator;
class AView : public artis::observer::View < artis::utils::DoubleTime,
ModelParameters >
{
public:
AView()
{
selectorI("A::I", { RootModel::A, AModel::IX });
selectorB("A::B", { RootModel::A, AModel::BX });
selector("A::D", { RootModel::A, AModel::DX });
selectorI("B::I", { RootModel::B, BModel::IY });
selectorB("B::B", { RootModel::B, BModel::BY });
selector("B::D", { RootModel::B, BModel::DY });
}
virtual ~AView()
{ }
};
typedef artis::observer::Output < artis::utils::DoubleTime,
ModelParameters > Output;
TEST_CASE("Simulator_tests", "simple")
{
GlobalParameters globalParameters;
ModelParameters modelParameters;
::Simulator simulator(new RootModel, globalParameters);
simulator.attachView("Root", new AView);
artis::utils::Trace < artis::utils::DoubleTime >::trace().clear();
simulator.init(0, modelParameters);
simulator.run(0, 10);
::Output output(simulator.observer());
output();
}