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