From 39900761a8a7839893b1ffcea4d4bc12e418adf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 14 Dec 2015 13:51:59 +0100 Subject: [PATCH] Transform FlowMain to use CRTP. Main content is now in FlowMainBase, which takes Implementation as a template parameter. FlowMain inherits from FlowMainBase with itself as Implementation template parameter. Only the createSimulator() method is implemented in FlowMain (as opposed to in FlowMainBase). All subclasses must implement createSimulator(). --- opm/autodiff/FlowMain.hpp | 102 +++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 40 deletions(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index e5597c798..d8e775875 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -102,8 +102,8 @@ namespace Opm /// This class encapsulates the setup and running of /// a simulator based on an input deck. - template - class FlowMain + template + class FlowMainBase { public: @@ -116,23 +116,23 @@ namespace Opm int execute(int argc, char** argv) try { // Setup. - setupParallelism(argc, argv); - printStartupMessage(); - const bool ok = setupParameters(argc, argv); + asImpl().setupParallelism(argc, argv); + asImpl().printStartupMessage(); + const bool ok = asImpl().setupParameters(argc, argv); if (!ok) { return EXIT_FAILURE; } - setupOutput(); - readDeckInput(); - setupGridAndProps(); - setupState(); - distributeData(); - setupOutputWriter(); - setupLinearSolver(); - createSimulator(); + asImpl().setupOutput(); + asImpl().readDeckInput(); + asImpl().setupGridAndProps(); + asImpl().setupState(); + asImpl().distributeData(); + asImpl().setupOutputWriter(); + asImpl().setupLinearSolver(); + asImpl().createSimulator(); // Run. - return runSimulator(); + return asImpl().runSimulator(); } catch (const std::exception &e) { std::cerr << "Program threw an exception: " << e.what() << "\n"; @@ -141,7 +141,7 @@ namespace Opm - private: + protected: @@ -571,30 +571,6 @@ namespace Opm - // Create simulator instance. - // Writes to: - // simulator_ - void createSimulator() - { - // Create the simulator instance. - simulator_.reset(new Simulator(param_, - grid_init_->grid(), - *geoprops_, - *fluidprops_, - rock_comp_->isActive() ? rock_comp_.get() : nullptr, - *fis_solver_, - gravity_.data(), - deck_->hasKeyword("DISGAS"), - deck_->hasKeyword("VAPOIL"), - eclipse_state_, - *output_writer_, - threshold_pressures_)); - } - - - - - // Run the simulator. // Returns EXIT_SUCCESS if it does not throw. int runSimulator() @@ -643,7 +619,53 @@ namespace Opm } - }; // class FlowMain + + + + // Access the most-derived class used for + // static polymorphism (CRTP). + Implementation& asImpl() + { + return static_cast(*this); + } + + + }; // class FlowMainBase + + + + + + + // The FlowMain class is the basic black-oil simulator case. + template + class FlowMain : public FlowMainBase, Grid, Simulator> + { + protected: + using Base = FlowMainBase, Grid, Simulator>; + friend Base; + + // Create simulator instance. + // Writes to: + // simulator_ + void createSimulator() + { + // Create the simulator instance. + Base::simulator_.reset(new Simulator(Base::param_, + Base::grid_init_->grid(), + *Base::geoprops_, + *Base::fluidprops_, + Base::rock_comp_->isActive() ? Base::rock_comp_.get() : nullptr, + *Base::fis_solver_, + Base::gravity_.data(), + Base::deck_->hasKeyword("DISGAS"), + Base::deck_->hasKeyword("VAPOIL"), + Base::eclipse_state_, + *Base::output_writer_, + Base::threshold_pressures_)); + } + }; + } // namespace Opm