diff --git a/dumux/discretization/CMakeLists.txt b/dumux/discretization/CMakeLists.txt index a55ac8b0ff9b4c3e3cdd089835c164b9d08ce049..f3b5244a42a56a2c1c09d35bc42bb491ec0c7429 100644 --- a/dumux/discretization/CMakeLists.txt +++ b/dumux/discretization/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(staggered) install(FILES basefvgridgeometry.hh +checkoverlapsize.hh darcyslaw.hh effectivestresslaw.hh elementsolution.hh diff --git a/dumux/discretization/box/fvgridgeometry.hh b/dumux/discretization/box/fvgridgeometry.hh index 1df7688e820701b2670a5cd5546782df42604edd..f5f142aee5b5691fd6f8f0e143f4b9152ef88f15 100644 --- a/dumux/discretization/box/fvgridgeometry.hh +++ b/dumux/discretization/box/fvgridgeometry.hh @@ -32,6 +32,7 @@ #include <dumux/discretization/methods.hh> #include <dumux/common/defaultmappertraits.hh> #include <dumux/discretization/basefvgridgeometry.hh> +#include <dumux/discretization/checkoverlapsize.hh> #include <dumux/discretization/box/boxgeometryhelper.hh> #include <dumux/discretization/box/fvelementgeometry.hh> #include <dumux/discretization/box/subcontrolvolume.hh> @@ -112,7 +113,13 @@ public: //! Constructor BoxFVGridGeometry(const GridView gridView) - : ParentType(gridView) {} + : ParentType(gridView) + { + // Check if the overlap size is what we expect + if (!CheckOverlapSize<DiscretizationMethod::box>::isValid(gridView)) + DUNE_THROW(Dune::InvalidStateException, "The box discretization method only works with zero overlap for parallel computations. " + << " Set the parameter \"Grid.Overlap\" in the input file."); + } //! the vertex mapper is the dofMapper //! this is convenience to have better chance to have the same main files for box/tpfa/mpfa... @@ -316,7 +323,13 @@ public: //! Constructor BoxFVGridGeometry(const GridView gridView) - : ParentType(gridView) {} + : ParentType(gridView) + { + // Check if the overlap size is what we expect + if (!CheckOverlapSize<DiscretizationMethod::box>::isValid(gridView)) + DUNE_THROW(Dune::InvalidStateException, "The box discretization method only works with zero overlap for parallel computations. " + << " Set the parameter \"Grid.Overlap\" in the input file."); + } //! the vertex mapper is the dofMapper //! this is convenience to have better chance to have the same main files for box/tpfa/mpfa... diff --git a/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh b/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh index 46e7f5df1ce7760a82df85468b98fb7289416c82..e2ebeeaa96059b34a5626efdd631acf05f45275e 100644 --- a/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh +++ b/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh @@ -31,6 +31,7 @@ #include <dumux/common/parameters.hh> #include <dumux/discretization/methods.hh> #include <dumux/discretization/basefvgridgeometry.hh> +#include <dumux/discretization/checkoverlapsize.hh> namespace Dumux { @@ -48,6 +49,16 @@ namespace Dumux { template<class GridView, class Traits, bool enableCache> class CCMpfaFVGridGeometry; +//! check the overlap size for parallel computations +template<class GridView> +void checkOverlapSizeCCMpfa(const GridView& gridView) +{ + // Check if the overlap size is what we expect + if (!CheckOverlapSize<DiscretizationMethod::ccmpfa>::isValid(gridView)) + DUNE_THROW(Dune::InvalidStateException, "The ccmpfa discretization method needs at least an overlap of 1 for parallel computations. " + << " Set the parameter \"Grid.Overlap\" in the input file."); +} + /*! * \ingroup CCMpfaDiscretization * \brief The finite volume geometry (scvs and scvfs) for cell-centered mpfa models on a grid view @@ -108,13 +119,17 @@ public: : ParentType(gridView) , secondaryIvIndicator_([] (const Element& e, const Intersection& is, bool isBranching) { return is.boundary() || isBranching; } ) - {} + { + checkOverlapSizeCCMpfa(gridView); + } //! Constructor with user-defined indicator function for secondary interaction volumes CCMpfaFVGridGeometry(const GridView& gridView, const SecondaryIvIndicatorType& indicator) : ParentType(gridView) , secondaryIvIndicator_(indicator) - {} + { + checkOverlapSizeCCMpfa(gridView); + } //! the element mapper is the dofMapper //! this is convenience to have better chance to have the same main files for box/tpfa/mpfa... @@ -467,13 +482,17 @@ public: : ParentType(gridView) , secondaryIvIndicator_([] (const Element& e, const Intersection& is, bool isBranching) { return is.boundary() || isBranching; } ) - {} + { + checkOverlapSizeCCMpfa(gridView); + } //! Constructor with user-defined indicator function for secondary interaction volumes CCMpfaFVGridGeometry(const GridView& gridView, const SecondaryIvIndicatorType& indicator) : ParentType(gridView) , secondaryIvIndicator_(indicator) - {} + { + checkOverlapSizeCCMpfa(gridView); + } //! the element mapper is the dofMapper //! this is convenience to have better chance to have the same main files for box/tpfa/mpfa... diff --git a/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh b/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh index 9cbf47d78debdff59d75885e42885efafe066730..71e48353a0654dbff43c6bd684b5ebd4d1eb215c 100644 --- a/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh +++ b/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh @@ -31,6 +31,7 @@ #include <dumux/common/defaultmappertraits.hh> #include <dumux/discretization/methods.hh> #include <dumux/discretization/basefvgridgeometry.hh> +#include <dumux/discretization/checkoverlapsize.hh> #include <dumux/discretization/cellcentered/subcontrolvolume.hh> #include <dumux/discretization/cellcentered/connectivitymap.hh> #include <dumux/discretization/cellcentered/tpfa/fvelementgeometry.hh> @@ -116,7 +117,12 @@ public: //! Constructor CCTpfaFVGridGeometry(const GridView& gridView) : ParentType(gridView) - {} + { + // Check if the overlap size is what we expect + if (!CheckOverlapSize<DiscretizationMethod::cctpfa>::isValid(gridView)) + DUNE_THROW(Dune::InvalidStateException, "The cctpfa discretization method needs at least an overlap of 1 for parallel computations. " + << " Set the parameter \"Grid.Overlap\" in the input file."); + } //! the element mapper is the dofMapper //! this is convenience to have better chance to have the same main files for box/tpfa/mpfa... @@ -389,7 +395,12 @@ public: //! Constructor CCTpfaFVGridGeometry(const GridView& gridView) : ParentType(gridView) - {} + { + // Check if the overlap size is what we expect + if (!CheckOverlapSize<DiscretizationMethod::cctpfa>::isValid(gridView)) + DUNE_THROW(Dune::InvalidStateException, "The cctpfa discretization method needs at least an overlap of 1 for parallel computations. " + << " Set the parameter \"Grid.Overlap\" in the input file."); + } //! the element mapper is the dofMapper //! this is convenience to have better chance to have the same main files for box/tpfa/mpfa... diff --git a/dumux/discretization/checkoverlapsize.hh b/dumux/discretization/checkoverlapsize.hh new file mode 100644 index 0000000000000000000000000000000000000000..2637fc9d18bd20b61637ab40d207eefbb3b637b9 --- /dev/null +++ b/dumux/discretization/checkoverlapsize.hh @@ -0,0 +1,57 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/***************************************************************************** + * See the file COPYING for full copying permissions. * + * * + * This program 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. * + * * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. * + *****************************************************************************/ +/*! + * \file + * \ingroup Discretization + * \brief Check the overlap size for different discretization methods + */ +#ifndef DUMUX_DISCRETIZATION_CHECK_OVERLAP_SIZE_HH +#define DUMUX_DISCRETIZATION_CHECK_OVERLAP_SIZE_HH + +#include <dumux/discretization/methods.hh> + +namespace Dumux { + +/*! + * \ingroup Discretization + * \brief Check if the overlap size is valid for a given discretization method + * \note the default checks if the grid has at least an overlap of one if there are no ghosts + * \note for sequential grids every overlap is fine + * \note specialize this for your discretization method if the default doesn't apply + */ +template<DiscretizationMethod discMethod> +struct CheckOverlapSize +{ + template<class GridView> + static bool isValid(const GridView& gridView) noexcept + { return gridView.comm().size() <= 1 || gridView.overlapSize(0) + gridView.ghostSize(0) > 0; } +}; + +//! specialization for the box method which requires an overlap size of 0 +template<> +struct CheckOverlapSize<DiscretizationMethod::box> +{ + template<class GridView> + static bool isValid(const GridView& gridView) noexcept + { return gridView.comm().size() <= 1 || gridView.overlapSize(0) == 0; } +}; + +} // end namespace Dumux + +#endif diff --git a/dumux/discretization/staggered/fvgridgeometry.hh b/dumux/discretization/staggered/fvgridgeometry.hh index c37ea7838ffc346e468bf9cb0bdfbc1c928593eb..1947615d90262761502924b261e19c5039e952d2 100644 --- a/dumux/discretization/staggered/fvgridgeometry.hh +++ b/dumux/discretization/staggered/fvgridgeometry.hh @@ -25,6 +25,7 @@ #define DUMUX_DISCRETIZATION_STAGGERED_FV_GRID_GEOMETRY #include <dumux/discretization/basefvgridgeometry.hh> +#include <dumux/discretization/checkoverlapsize.hh> #include <dumux/discretization/methods.hh> namespace Dumux { @@ -85,7 +86,13 @@ public: //! Constructor StaggeredFVGridGeometry(const GridView& gridView) : ParentType(gridView) - , intersectionMapper_(gridView) {} + , intersectionMapper_(gridView) + { + // Check if the overlap size is what we expect + if (!CheckOverlapSize<DiscretizationMethod::staggered>::isValid(gridView)) + DUNE_THROW(Dune::InvalidStateException, "The satggered discretization method needs at least an overlap of 1 for parallel computations. " + << " Set the parameter \"Grid.Overlap\" in the input file."); + } //! The total number of sub control volumes std::size_t numScv() const