From 47c9b39e3b31c9edc12c7561868b5bf7880f7c8e Mon Sep 17 00:00:00 2001 From: Robert Kloefkorn Date: Fri, 8 Jan 2016 12:08:04 -0700 Subject: [PATCH] FingerProblem: bug fix, store pointers of MaterialLaw since copying seems not ot work. LensProblem: use structuredgridmanager from ewoms/io. --- examples/problems/fingerproblem.hh | 40 +++-- examples/problems/lensproblem.hh | 2 +- examples/problems/structuredgridmanager.hh | 193 --------------------- 3 files changed, 26 insertions(+), 209 deletions(-) delete mode 100644 examples/problems/structuredgridmanager.hh diff --git a/examples/problems/fingerproblem.hh b/examples/problems/fingerproblem.hh index e1445ce9c..aa9d46153 100644 --- a/examples/problems/fingerproblem.hh +++ b/examples/problems/fingerproblem.hh @@ -29,7 +29,7 @@ // uncomment to run problem in 3d // #define GRIDDIM 3 -#include "structuredgridmanager.hh" +#include #include #include @@ -194,7 +194,7 @@ class FingerProblem : public GET_PROP_TYPE(TypeTag, BaseProblem) typedef typename GridView :: Grid Grid; - typedef Dune::PersistentContainer< Grid, MaterialLawParams > MaterialLawParamsContainer; + typedef Dune::PersistentContainer< Grid, MaterialLawParams* > MaterialLawParamsContainer; //!\endcond public: @@ -206,7 +206,8 @@ public: FingerProblem(Simulator &simulator) : ParentType(simulator), materialParams_( simulator.gridManager().grid(), codim ) - { } + { + } /*! * \name Auxiliary methods @@ -269,17 +270,22 @@ public: // initialize the material parameter objects of the individual // finite volumes, resize will resize the container to the number of elements - materialParams_.resize(); + materialParams_.resize( (MaterialLawParams*) 0 ); for (auto it = materialParams_.begin(), end = materialParams_.end(); it != end; ++it ) { - MaterialLawParams& materialParams = *it ; - materialParams.setMicParams(&micParams_); - materialParams.setMdcParams(&mdcParams_); - materialParams.setSwr(0.0); - materialParams.setSnr(0.1); - materialParams.finalize(); - ParkerLenhard::reset(materialParams); + MaterialLawParams* materialParams = *it ; + if( ! materialParams ) + { + materialParams = new MaterialLawParams(); + materialParams->setMicParams(&micParams_); + materialParams->setMdcParams(&mdcParams_); + materialParams->setSwr(0.0); + materialParams->setSnr(0.1); + materialParams->finalize(); + ParkerLenhard::reset(*materialParams); + *it = materialParams; + } } K_ = this->toDimMatrix_(4.6e-10); @@ -359,10 +365,12 @@ public: */ template MaterialLawParams &materialLawParams(const Context &context, - int spaceIdx, int timeIdx) + const int spaceIdx, const int timeIdx) { const auto& entity = context.stencil(timeIdx).entity( spaceIdx ); - return materialParams_[ entity ]; + MaterialLawParams* params = materialParams_[ entity ]; + assert( params ); + return *params; } /*! @@ -370,10 +378,12 @@ public: */ template const MaterialLawParams &materialLawParams(const Context &context, - unsigned spaceIdx, unsigned timeIdx) const + const int spaceIdx, const int timeIdx) const { const auto& entity = context.stencil(timeIdx).entity( spaceIdx ); - return materialParams_[ entity ]; + const MaterialLawParams* params = materialParams_[ entity ]; + assert( params ); + return *params; } //! \} diff --git a/examples/problems/lensproblem.hh b/examples/problems/lensproblem.hh index 73ff96371..70d6c7747 100644 --- a/examples/problems/lensproblem.hh +++ b/examples/problems/lensproblem.hh @@ -26,7 +26,7 @@ #ifndef EWOMS_LENS_PROBLEM_HH #define EWOMS_LENS_PROBLEM_HH -#include "structuredgridmanager.hh" +#include #include diff --git a/examples/problems/structuredgridmanager.hh b/examples/problems/structuredgridmanager.hh deleted file mode 100644 index e6ce10d9a..000000000 --- a/examples/problems/structuredgridmanager.hh +++ /dev/null @@ -1,193 +0,0 @@ -// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -// vi: set et ts=4 sw=4 sts=4: -/* - Copyright (C) 2012-2013 by Andreas Lauser - Copyright (C) 2016 IRIS AS - - This file is part of the Open Porous Media project (OPM). - - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OPM. If not, see . -*/ -/*! - * \file - * \copydoc Ewoms::StructuredGridManager - */ -#ifndef EWOMS_STRUCTURED_GRID_MANAGER_HH -#define EWOMS_STRUCTURED_GRID_MANAGER_HH - -#include -#include -#include - -#include -#include - -//#define TESTS_USE_ALUGRID 1 -#if TESTS_USE_ALUGRID -#include -#include -#endif - -#include -#include - -#include -#include - -namespace Ewoms { - -template -class StructuredGridManager; - -namespace Properties { -NEW_TYPE_TAG(StructuredGridManager); - -// declare the properties required by the for the lens grid manager -NEW_PROP_TAG(Grid); -NEW_PROP_TAG(Scalar); - -NEW_PROP_TAG(DomainSizeX); -NEW_PROP_TAG(DomainSizeY); -NEW_PROP_TAG(DomainSizeZ); - -NEW_PROP_TAG(CellsX); -NEW_PROP_TAG(CellsY); -NEW_PROP_TAG(CellsZ); - -NEW_PROP_TAG(GridGlobalRefinements); - -// GRIDDIM is only set by the finger problem -#ifndef GRIDDIM -static const int dim = 2; -#else -static const int dim = GRIDDIM; -#endif - -// set the Grid and GridManager properties -#if TESTS_USE_ALUGRID -SET_TYPE_PROP(StructuredGridManager, Grid, Dune::ALUGrid< dim, dim, Dune::cube, Dune::nonconforming >); -#else -SET_TYPE_PROP(StructuredGridManager, Grid, Dune::YaspGrid< dim >); -#endif - -SET_TYPE_PROP(StructuredGridManager, GridManager, Ewoms::StructuredGridManager); -} // namespace Properties - -/*! - * \ingroup TestProblems - * - * \brief Helper class for grid instantiation of the lens problem. - */ -template -class StructuredGridManager : public BaseGridManager -{ - typedef BaseGridManager ParentType; - typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; - typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator; - typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid; - - typedef std::unique_ptr GridPointer; - - static const int dim = Grid::dimension; - -public: - /*! - * \brief Register all run-time parameters for the grid manager. - */ - static void registerParameters() - { - EWOMS_REGISTER_PARAM(TypeTag, unsigned, GridGlobalRefinements, - "The number of global refinements of the grid " - "executed after it was loaded"); - EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeX, - "The size of the domain in x direction"); - EWOMS_REGISTER_PARAM(TypeTag, int, CellsX, - "The number of intervalls in x direction"); - if (dim > 1) { - EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeY, - "The size of the domain in y direction"); - EWOMS_REGISTER_PARAM(TypeTag, int, CellsY, - "The number of intervalls in y direction"); - } - if (dim > 2) { - EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeZ, - "The size of the domain in z direction"); - EWOMS_REGISTER_PARAM(TypeTag, int, CellsZ, - "The number of intervalls in z direction"); - } - } - - /*! - * \brief Create the grid for the lens problem - */ - StructuredGridManager(Simulator &simulator) - : ParentType(simulator) - { - Dune::FieldVector cellRes; - - typedef double GridScalar; - Dune::FieldVector upperRight; - Dune::FieldVector lowerLeft( 0 ); - - upperRight[0] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeX); - upperRight[1] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeY); - - cellRes[0] = EWOMS_GET_PARAM(TypeTag, int, CellsX); - cellRes[1] = EWOMS_GET_PARAM(TypeTag, int, CellsY); - if (dim == 3) { - upperRight[2] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeZ); - cellRes[2] = EWOMS_GET_PARAM(TypeTag, int, CellsZ); - } - - std::stringstream dgffile; - dgffile << "DGF" << std::endl; - dgffile << "INTERVAL" << std::endl; - dgffile << lowerLeft << std::endl; - dgffile << upperRight << std::endl; - dgffile << cellRes << std::endl; - dgffile << "#" << std::endl; - dgffile << "GridParameter" << std::endl; - dgffile << "overlap 1" << std::endl; - dgffile << "#" << std::endl; - dgffile << "Simplex" << std::endl; - dgffile << "#" << std::endl; - - // use DGF parser to create a grid from interval block - gridPtr_.reset( Dune::GridPtr< Grid >( dgffile ).release() ); - - unsigned numRefinements = EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements); - gridPtr_->globalRefine(numRefinements); - - this->finalizeInit_(); - } - - /*! - * \brief Return a reference to the grid object. - */ - Grid& grid() - { return *gridPtr_; } - - /*! - * \brief Return a constant reference to the grid object. - */ - const Grid& grid() const - { return *gridPtr_; } - -private: - GridPointer gridPtr_; -}; - -} // namespace Ewoms - -#endif