From cc65f0520822a940b0fd5e1b745f3ad058de9191 Mon Sep 17 00:00:00 2001 From: Beatrix Becker Date: Fri, 29 Jun 2018 14:19:14 +0200 Subject: [PATCH 1/2] [sequential] problems can choose the gridView gridView is leafGridView by default and can be overwritten by implementation. --- .../sequential/impetproblem.hh | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/dumux/porousmediumflow/sequential/impetproblem.hh b/dumux/porousmediumflow/sequential/impetproblem.hh index 9b2cf6dea9..faffcb2b86 100644 --- a/dumux/porousmediumflow/sequential/impetproblem.hh +++ b/dumux/porousmediumflow/sequential/impetproblem.hh @@ -96,22 +96,19 @@ public: * \param gridView gridview to the grid. */ IMPETProblem(TimeManager &timeManager, Grid& grid) - : gridView_(grid.leafGridView()), - grid_(nullptr), + : grid_(&grid), bBoxMin_(std::numeric_limits::max()), bBoxMax_(-std::numeric_limits::max()), timeManager_(&timeManager), - variables_(grid.leafGridView()), + variables_(gridView()), outputInterval_(1), outputTimeInterval_(0.0), vtkOutputLevel_(-1) { - setGrid(grid); - // calculate the bounding box of the grid view using std::min; using std::max; - for (const auto& vertex : vertices(grid.leafGridView())) { + for (const auto& vertex : vertices(gridView())) { for (int i=0; i 1) + if (gridView().comm().size() > 1) for (int i = 0; i < dim; ++i) { - bBoxMin_[i] = grid.leafGridView().comm().min(bBoxMin_[i]); - bBoxMax_[i] = grid.leafGridView().comm().max(bBoxMax_[i]); + bBoxMin_[i] = gridView().comm().min(bBoxMin_[i]); + bBoxMax_[i] = gridView().comm().max(bBoxMax_[i]); } pressModel_ = std::make_shared(asImp_()); @@ -380,12 +377,12 @@ public: if (Dune::FloatCmp::eq(t, 0.0, 1.0e-30) && Dune::FloatCmp::ne(timeManager().timeStepSize(), 0.0, 1.0e-30)) { - if (this->gridView().comm().size() > 1) - dt = this->gridView().comm().min(dt); + if (gridView().comm().size() > 1) + dt = gridView().comm().min(dt); // check if assigned initialDt is in accordance with dt from first transport step if (timeManager().timeStepSize() > dt - && this->gridView().comm().rank() == 0) + && gridView().comm().rank() == 0) Dune::dwarn << "Initial timestep of size " << timeManager().timeStepSize() << " is larger then dt=" << dt <<" from transport" << std::endl; // internally assign next timestep size @@ -393,8 +390,8 @@ public: } //make sure the right time-step is used by all processes in the parallel case - if (this->gridView().comm().size() > 1) - dt = this->gridView().comm().min(dt); + if (gridView().comm().size() > 1) + dt = gridView().comm().min(dt); // check maximum allowed time step size timeManager().setTimeStepSize(dt); @@ -568,8 +565,10 @@ public: /*! * \brief The GridView which used by the problem. */ - const GridView &gridView() const - { return gridView_; } + const GridView gridView() const + { return asImp_().gridView_(); } + GridView gridView() + { return asImp_().gridView_(); } /*! * \brief Returns the current grid which used by the problem. @@ -733,8 +732,8 @@ public: resultWriter().serialize(res); // do the actual serialization process: write primary variables - res.template serializeEntities<0> (*pressModel_, gridView_); - res.template serializeEntities<0> (*transportModel_, gridView_); + res.template serializeEntities<0> (*pressModel_, gridView()); + res.template serializeEntities<0> (*transportModel_, gridView()); res.serializeEnd(); @@ -771,8 +770,8 @@ public: resultWriter().deserialize(res); // do the actual serialization process: get primary variables - res.template deserializeEntities<0> (*pressModel_, gridView_); - res.template deserializeEntities<0> (*transportModel_, gridView_); + res.template deserializeEntities<0> (*pressModel_, gridView()); + res.template deserializeEntities<0> (*transportModel_, gridView()); pressureModel().updateMaterialLaws(); res.deserializeEnd(); @@ -798,7 +797,7 @@ public: std::cout << "Writing result file for current time step\n"; if (!resultWriter_) - resultWriter_ = std::make_shared(gridView_, asImp_().name()); + resultWriter_ = std::make_shared(gridView(), asImp_().name()); if (adaptiveGrid) resultWriter_->gridChanged(); resultWriter_->beginWrite(timeManager().time() + timeManager().timeStepSize()); @@ -814,14 +813,14 @@ protected: VtkMultiWriter& resultWriter() { if (!resultWriter_) - resultWriter_ = std::make_shared(gridView_, asImp_().name()); + resultWriter_ = std::make_shared(gridView(), asImp_().name()); return *resultWriter_; } //! \copydoc IMPETProblem::resultWriter() VtkMultiWriter& resultWriter() const { if (!resultWriter_) - resultWriter_ = std::make_shared(gridView_, asImp_().name()); + resultWriter_ = std::make_shared(gridView(), asImp_().name()); return *resultWriter_; } @@ -834,10 +833,15 @@ private: const Implementation &asImp_() const { return *static_cast(this); } + const GridView gridView_() const + { return grid_->leafGridView(); } + GridView gridView_() + { return grid_->leafGridView(); } + + std::string simname_; // a string for the name of the current simulation, - // which could be set by means of an program argument, - // for example. - const GridView gridView_; + // which could be set by means of a program argument, for example. + // pointer to a possibly adaptive grid. Grid *grid_; -- GitLab From 7a0e246d1fa2a9cf3f40c875c1e80b34cc51510c Mon Sep 17 00:00:00 2001 From: Beatrix Becker Date: Thu, 5 Jul 2018 14:32:46 +0200 Subject: [PATCH 2/2] [2p sequential] Give gridView to impetproblem and add second constructor with default leafGridView --- .../2p/sequential/impes/problem.hh | 7 +++- .../sequential/impetproblem.hh | 42 +++++++++---------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/dumux/porousmediumflow/2p/sequential/impes/problem.hh b/dumux/porousmediumflow/2p/sequential/impes/problem.hh index 5ae89c762e..90b58c1b19 100644 --- a/dumux/porousmediumflow/2p/sequential/impes/problem.hh +++ b/dumux/porousmediumflow/2p/sequential/impes/problem.hh @@ -75,8 +75,11 @@ public: * \param gridView The grid view */ IMPESProblem2P(TimeManager& timeManager, Grid& grid) - : ParentType(timeManager, grid), - gravity_(0) + : IMPESProblem2P(timeManager, grid, grid.leafGridView()) + {} + + IMPESProblem2P(TimeManager& timeManager, Grid& grid, const GridView& gridView) + : ParentType(timeManager, grid, gridView), gravity_(0) { spatialParams_ = std::make_shared(asImp_()); diff --git a/dumux/porousmediumflow/sequential/impetproblem.hh b/dumux/porousmediumflow/sequential/impetproblem.hh index faffcb2b86..58d94ec3c6 100644 --- a/dumux/porousmediumflow/sequential/impetproblem.hh +++ b/dumux/porousmediumflow/sequential/impetproblem.hh @@ -96,11 +96,15 @@ public: * \param gridView gridview to the grid. */ IMPETProblem(TimeManager &timeManager, Grid& grid) + : IMPETProblem(timeManager, grid, grid.leafGridView()) + {} + + IMPETProblem(TimeManager &timeManager, Grid& grid, const GridView& gridView) : grid_(&grid), + gridView_(gridView), bBoxMin_(std::numeric_limits::max()), bBoxMax_(-std::numeric_limits::max()), timeManager_(&timeManager), - variables_(gridView()), outputInterval_(1), outputTimeInterval_(0.0), vtkOutputLevel_(-1) @@ -108,7 +112,7 @@ public: // calculate the bounding box of the grid view using std::min; using std::max; - for (const auto& vertex : vertices(gridView())) { + for (const auto& vertex : vertices(this->gridView())) { for (int i=0; i 1) + if (this->gridView().comm().size() > 1) for (int i = 0; i < dim; ++i) { - bBoxMin_[i] = gridView().comm().min(bBoxMin_[i]); - bBoxMax_[i] = gridView().comm().max(bBoxMax_[i]); + bBoxMin_[i] = this->gridView().comm().min(bBoxMin_[i]); + bBoxMax_[i] = this->gridView().comm().max(bBoxMax_[i]); } + variables_ = std::make_shared(this->gridView()); pressModel_ = std::make_shared(asImp_()); transportModel_ = std::make_shared(asImp_()); @@ -319,7 +324,7 @@ public: void init() { // set the initial condition of the model - variables_.initialize(); + variables_->initialize(); model().initialize(); if (adaptiveGrid) gridAdapt().init(); @@ -565,10 +570,10 @@ public: /*! * \brief The GridView which used by the problem. */ - const GridView gridView() const - { return asImp_().gridView_(); } - GridView gridView() - { return asImp_().gridView_(); } + const GridView& gridView() const + { + return gridView_; + } /*! * \brief Returns the current grid which used by the problem. @@ -628,13 +633,13 @@ public: * \brief Returns the mapper for vertices to indices. */ const VertexMapper &vertexMapper() const - { return variables_.vertexMapper(); } + { return variables_->vertexMapper(); } /*! * \brief Returns the mapper for elements to indices. */ const ElementMapper &elementMapper() const - { return variables_.elementMapper(); } + { return variables_->elementMapper(); } /*! * \brief The coordinate of the corner of the GridView's bounding @@ -669,11 +674,11 @@ public: * simulation process, such as pressure, saturation etc. */ Variables& variables () - { return variables_; } + { return *variables_; } //! \copydoc IMPETProblem::variables () const Variables& variables () const - { return variables_; } + { return *variables_; } /*! * \brief Returns numerical model used for the problem. @@ -833,17 +838,12 @@ private: const Implementation &asImp_() const { return *static_cast(this); } - const GridView gridView_() const - { return grid_->leafGridView(); } - GridView gridView_() - { return grid_->leafGridView(); } - - std::string simname_; // a string for the name of the current simulation, // which could be set by means of a program argument, for example. // pointer to a possibly adaptive grid. Grid *grid_; + GridView gridView_; GlobalPosition bBoxMin_; GlobalPosition bBoxMax_; @@ -851,7 +851,7 @@ private: TimeManager *timeManager_; Scalar maxTimeStepSize_; - Variables variables_; + std::shared_ptr variables_; std::shared_ptr pressModel_;//!< object including the pressure model std::shared_ptr transportModel_;//!< object including the saturation model -- GitLab