From d5539f5b34fee0128958b21c8ea6e8c0382e62ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Gl=C3=A4ser?= <dennis.glaeser@iws.uni-stuttgart.de> Date: Tue, 8 May 2018 15:06:02 +0200 Subject: [PATCH] [disc] implement physics-independent flux var cache for box This way we can reuse code more easily for geomechanics --- .../discretization/box/fluxvariablescache.hh | 101 ++++++++++++++++++ dumux/porousmediumflow/fluxvariablescache.hh | 74 +------------ 2 files changed, 106 insertions(+), 69 deletions(-) create mode 100644 dumux/discretization/box/fluxvariablescache.hh diff --git a/dumux/discretization/box/fluxvariablescache.hh b/dumux/discretization/box/fluxvariablescache.hh new file mode 100644 index 0000000000..c69fb4c9d2 --- /dev/null +++ b/dumux/discretization/box/fluxvariablescache.hh @@ -0,0 +1,101 @@ +// -*- 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 Flux variables cache class for the box scheme + */ +#ifndef DUMUX_DISCRETIZATION_BOX_FLUXVARIABLES_CACHE_HH +#define DUMUX_DISCRETIZATION_BOX_FLUXVARIABLES_CACHE_HH + +#include <dune/common/fvector.hh> +#include <dune/localfunctions/lagrange/pqkfactory.hh> + +namespace Dumux { + +/*! + * \ingroup Discretization + * \ingroup BoxDiscretization + * \brief Flux variables cache class for the box scheme. + * For the box scheme, this class does not contain any physics-/process-dependent + * data. It solely stores disretization-/grid-related data. + */ +template< class Scalar, class FVGridGeometry > +class BoxFluxVariablesCache +{ + using GridView = typename FVGridGeometry::GridView; + using Element = typename GridView::template Codim<0>::Entity; + using GlobalPosition = typename Element::Geometry::GlobalCoordinate; + + using FVElementGeometry = typename FVGridGeometry::LocalView; + using SubControlVolumeFace = typename FVGridGeometry::SubControlVolumeFace; + + static const int dim = GridView::dimension; + static const int dimWorld = GridView::dimensionworld; + + using CoordScalar = typename GridView::ctype; + using FeCache = Dune::PQkLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>; + using FeLocalBasis = typename FeCache::FiniteElementType::Traits::LocalBasisType; + using ShapeJacobian = typename FeLocalBasis::Traits::JacobianType; + using ShapeValue = typename Dune::FieldVector<Scalar, 1>; + using JacobianInverseTransposed = typename Element::Geometry::JacobianInverseTransposed; + +public: + + template< class Problem, class ElementVolumeVariables > + void update(const Problem& problem, + const Element& element, + const FVElementGeometry& fvGeometry, + const ElementVolumeVariables& elemVolVars, + const SubControlVolumeFace &scvf) + { + const auto geometry = element.geometry(); + const auto& localBasis = fvGeometry.feLocalBasis(); + + // evaluate shape functions and gradients at the integration point + const auto ipLocal = geometry.local(scvf.ipGlobal()); + jacInvT_ = geometry.jacobianInverseTransposed(ipLocal); + localBasis.evaluateJacobian(ipLocal, shapeJacobian_); + localBasis.evaluateFunction(ipLocal, shapeValues_); // shape values for rho + + // compute the gradN at for every scv/dof + gradN_.resize(fvGeometry.numScv()); + for (const auto& scv: scvs(fvGeometry)) + jacInvT_.mv(shapeJacobian_[scv.localDofIndex()][0], gradN_[scv.indexInElement()]); + } + + //! returns the shape function gradients in local coordinates at the scvf integration point + const std::vector<ShapeJacobian>& shapeJacobian() const { return shapeJacobian_; } + //! returns the shape function values at the scvf integration point + const std::vector<ShapeValue>& shapeValues() const { return shapeValues_; } + //! returns inverse transposed jacobian at the scvf integration point + const JacobianInverseTransposed& jacInvT() const { return jacInvT_; } + //! returns the shape function gradients in global coordinates at the scvf integration point + const GlobalPosition& gradN(unsigned int scvIdxInElement) const { return gradN_[scvIdxInElement]; } + +private: + std::vector<GlobalPosition> gradN_; + std::vector<ShapeJacobian> shapeJacobian_; + std::vector<ShapeValue> shapeValues_; + JacobianInverseTransposed jacInvT_; +}; + +} // end namespace Dumux + +#endif diff --git a/dumux/porousmediumflow/fluxvariablescache.hh b/dumux/porousmediumflow/fluxvariablescache.hh index 59654c9867..2dc87b9d4e 100644 --- a/dumux/porousmediumflow/fluxvariablescache.hh +++ b/dumux/porousmediumflow/fluxvariablescache.hh @@ -23,11 +23,10 @@ #ifndef DUMUX_POROUSMEDIUM_FLUXVARIABLESCACHE_HH #define DUMUX_POROUSMEDIUM_FLUXVARIABLESCACHE_HH -#include <dune/localfunctions/lagrange/pqkfactory.hh> - #include <dumux/common/properties.hh> #include <dumux/discretization/methods.hh> #include <dumux/discretization/fluxvariablescaching.hh> +#include <dumux/discretization/box/fluxvariablescache.hh> namespace Dumux { @@ -51,75 +50,12 @@ class PorousMediumFluxVariablesCacheImplementation; template<class TypeTag> using PorousMediumFluxVariablesCache = PorousMediumFluxVariablesCacheImplementation<TypeTag, GET_PROP_TYPE(TypeTag, FVGridGeometry)::discMethod>; -//! We only store discretization-related quantities for the box method. -//! Thus, we need no physics-dependent specialization. +//! We only store discretization-related quantities for the box method. Thus, we need no +//! physics-dependent specialization and simply inherit from the physics-independent implementation. template<class TypeTag> class PorousMediumFluxVariablesCacheImplementation<TypeTag, DiscretizationMethod::box> -{ - using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar); - using Problem = typename GET_PROP_TYPE(TypeTag, Problem); - using GridView = typename GET_PROP_TYPE(TypeTag, GridView); - using FluxVariables = typename GET_PROP_TYPE(TypeTag, FluxVariables); - using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::LocalView; - using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables)::LocalView; - using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace; - using Element = typename GridView::template Codim<0>::Entity; - using IndexType = typename GridView::IndexSet::IndexType; - using Stencil = std::vector<IndexType>; - using TransmissibilityVector = std::vector<IndexType>; - using GlobalPosition = typename Element::Geometry::GlobalCoordinate; - - using CoordScalar = typename GridView::ctype; - static const int dim = GridView::dimension; - static const int dimWorld = GridView::dimensionworld; - - using FeCache = Dune::PQkLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>; - using FeLocalBasis = typename FeCache::FiniteElementType::Traits::LocalBasisType; - using ShapeJacobian = typename FeLocalBasis::Traits::JacobianType; - using ShapeValue = typename Dune::FieldVector<Scalar, 1>; - using JacobianInverseTransposed = typename Element::Geometry::JacobianInverseTransposed; - -public: - - void update(const Problem& problem, - const Element& element, - const FVElementGeometry& fvGeometry, - const ElementVolumeVariables& elemVolVars, - const SubControlVolumeFace &scvf) - { - const auto geometry = element.geometry(); - const auto& localBasis = fvGeometry.feLocalBasis(); - - // evaluate shape functions and gradients at the integration point - const auto ipLocal = geometry.local(scvf.ipGlobal()); - jacInvT_ = geometry.jacobianInverseTransposed(ipLocal); - localBasis.evaluateJacobian(ipLocal, shapeJacobian_); - localBasis.evaluateFunction(ipLocal, shapeValues_); // shape values for rho - - // compute the gradN at for every scv/dof - gradN_.resize(fvGeometry.numScv()); - for (const auto& scv: scvs(fvGeometry)) - jacInvT_.mv(shapeJacobian_[scv.localDofIndex()][0], gradN_[scv.indexInElement()]); - } - - const std::vector<ShapeJacobian>& shapeJacobian() const - { return shapeJacobian_; } - - const std::vector<ShapeValue>& shapeValues() const - { return shapeValues_; } - - const JacobianInverseTransposed& jacInvT() const - { return jacInvT_; } - - const GlobalPosition& gradN(unsigned int scvIdxInElement) const - { return gradN_[scvIdxInElement]; } - -private: - std::vector<GlobalPosition> gradN_; - std::vector<ShapeJacobian> shapeJacobian_; - std::vector<ShapeValue> shapeValues_; - JacobianInverseTransposed jacInvT_; -}; +: public BoxFluxVariablesCache<typename GET_PROP_TYPE(TypeTag, Scalar), typename GET_PROP_TYPE(TypeTag, FVGridGeometry)> +{}; // the following classes choose the cache type: empty if the law disabled and the law's cache if it's enabled // if advections is disabled the advection type is still instatiated if we use std::conditional_t and has to be a full type -- GitLab