Commit c482c97d authored by Lukas Riedel's avatar Lukas Riedel

Verify SimulationBase::step routine by adding adaptivity policy to test

parent 3895ff70
......@@ -5,21 +5,37 @@
#include <dune/dorie/interface/simulation_base.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/float_cmp.hh>
/// Dummy model for testing.
/** Makes sure that all functions of SimulationBase are properly overridden
* and called.
*/
class DummyModel : public Dune::Dorie::SimulationBase
{
public:
DummyModel()
: Dune::Dorie::SimulationBase(Dune::Dorie::OutputPolicy::EndOfStep)
, _dt(.1)
, _current_time(begin_time())
, _current_time(begin_time())
, _end_time(1.0)
, _grid_was_adapted(false)
{}
double begin_time() const override {return 0.;}
double end_time() const override {return 1.;}
double current_time() const override {return _current_time;}
void suggest_timestep(double dt) override {_dt = std::min(dt,_dt);}
void step() override {_current_time+=_dt;}
double begin_time() const override { return 0.; }
double end_time() const override { return _end_time; }
double current_time() const override { return _current_time; }
void suggest_timestep(double dt) override { _dt = std::min(dt,_dt); }
void step() override { _current_time+=_dt; }
/// Do nothing.
void mark_grid () override {};
/// Grid was adapted!
void adapt_grid () override
{
_grid_was_adapted = true;
}
void write_data() const override
{
......@@ -29,15 +45,32 @@ public:
private:
double _dt;
double _current_time;
public:
double _end_time;
bool _grid_was_adapted;
};
int main(int argc, char **argv)
{
Dune::MPIHelper::instance(argc, argv);
bool passed = true;
auto& helper = Dune::MPIHelper::instance(argc, argv);
try {
DummyModel model;
// run the model without adaptivity
model.run();
assert(not model._grid_was_adapted);
assert(Dune::FloatCmp::ge(model.current_time(), model.end_time()));
// now set adaptivity
model.set_policy(Dune::Dorie::AdaptivityPolicy::WaterFlux);
model._end_time += 1.0;
model.run();
assert(model._grid_was_adapted);
assert(Dune::FloatCmp::ge(model.current_time(), model.end_time()));
} catch (Dune::Exception& e) {
std::cout << e.what() << std::endl;
passed &= false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment