Commit fff5b51a authored by Lukas Riedel's avatar Lukas Riedel

Improve unit test of SimulationBase to check for calls to write_data

parent c482c97d
......@@ -2,6 +2,8 @@
#include "config.h"
#endif
#include <cassert>
#include <dune/dorie/interface/simulation_base.hh>
#include <dune/common/parallel/mpihelper.hh>
......@@ -15,11 +17,13 @@ class DummyModel : public Dune::Dorie::SimulationBase
{
public:
DummyModel()
: Dune::Dorie::SimulationBase(Dune::Dorie::OutputPolicy::EndOfStep)
: Dune::Dorie::SimulationBase(Dune::Dorie::OutputPolicy::None,
Dune::Dorie::AdaptivityPolicy::None)
, _dt(.1)
, _current_time(begin_time())
, _end_time(1.0)
, _grid_was_adapted(false)
, _data_was_written(false)
{}
double begin_time() const override { return 0.; }
......@@ -31,7 +35,7 @@ public:
/// Do nothing.
void mark_grid () override {};
/// Grid was adapted!
/// Adapt the grid in our minds.
void adapt_grid () override
{
_grid_was_adapted = true;
......@@ -40,6 +44,7 @@ public:
void write_data() const override
{
std::cout << "current time: " << _current_time << std::endl;
_data_was_written = true;
}
private:
......@@ -49,34 +54,38 @@ private:
public:
double _end_time;
bool _grid_was_adapted;
mutable bool _data_was_written;
};
int main(int argc, char **argv)
{
Dune::MPIHelper::instance(argc, argv);
bool passed = true;
try {
DummyModel model;
// run the model without adaptivity
model.run();
assert(not model._grid_was_adapted);
assert(not model._data_was_written);
assert(Dune::FloatCmp::ge(model.current_time(), model.end_time()));
// now set adaptivity
model.set_policy(Dune::Dorie::AdaptivityPolicy::WaterFlux);
model.set_policy(Dune::Dorie::OutputPolicy::EndOfStep);
model._end_time += 1.0;
model.run();
assert(model._grid_was_adapted);
assert(model._data_was_written);
assert(Dune::FloatCmp::ge(model.current_time(), model.end_time()));
} catch (Dune::Exception& e) {
std::cout << e.what() << std::endl;
passed &= false;
return 1;
} catch (...) {
std::cerr << "Exception occurred!" << std::endl;
passed &= false;
return 1;
}
return !passed;
return 0;
}
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