From 76e4371069dd2e54c1e4c0abf9d1f2716a9fafab Mon Sep 17 00:00:00 2001 From: Robert Kloefkorn Date: Tue, 28 May 2019 16:50:33 +0200 Subject: [PATCH] Added FemSparseMatrixAdapter. --- ewoms/disc/common/fvbasediscretization.hh | 40 ++------- ewoms/linear/femsparsematrixadapter.hh | 101 ++++++++++++++++++++++ 2 files changed, 106 insertions(+), 35 deletions(-) create mode 100644 ewoms/linear/femsparsematrixadapter.hh diff --git a/ewoms/disc/common/fvbasediscretization.hh b/ewoms/disc/common/fvbasediscretization.hh index 9f8221d3e3..f16eaddffa 100644 --- a/ewoms/disc/common/fvbasediscretization.hh +++ b/ewoms/disc/common/fvbasediscretization.hh @@ -77,11 +77,7 @@ #include #include -#if HAVE_PETSC -#include -#endif -#include -#include +#include #endif // endif HAVE_DUNE_FEM #include @@ -154,46 +150,20 @@ SET_PROP(FvBaseDiscretization, SparseMatrixAdapter) { private: typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace; - typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; // discrete function storing solution data typedef Dune::Fem::ISTLBlockVectorDiscreteFunction DiscreteFunction; +public: #if USE_DUNE_FEM_PETSC_SOLVERS #warning "Using Dune-Fem PETSc solvers" - typedef Dune::Fem::PetscLinearOperator< DiscreteFunction, DiscreteFunction > LinearOperator; + typedef FemPetscMatrixAdapter< DiscreteFunction > type; #elif USE_DUNE_FEM_VIENNACL_SOLVERS #warning "Using Dune-Fem ViennaCL solvers" - typedef Dune::Fem::SparseRowLinearOperator < DiscreteFunction, DiscreteFunction > LinearOperator; + typedef FemSparseRowMatrixAdapter< DiscreteFunction > type; #else #warning "Using Dune-Fem ISTL solvers" - typedef Dune::Fem::ISTLLinearOperator < DiscreteFunction, DiscreteFunction > LinearOperator; + typedef FemISTLMatrixAdapter< DiscreteFunction > type; #endif - - struct FemMatrixBackend : public LinearOperator - { - typedef LinearOperator ParentType; - typedef typename LinearOperator :: MatrixType Matrix; - typedef typename ParentType :: MatrixBlockType MatrixBlock; - template - FemMatrixBackend( const Simulator& simulator ) - : LinearOperator("eWoms::Jacobian", simulator.model().space(), simulator.model().space() ) - {} - - void commit() - { - this->flushAssembly(); - } - - template< class LocalBlock > - void addToBlock ( const size_t row, const size_t col, const LocalBlock& block ) - { - this->addBlock( row, col, block ); - } - - void clearRow( const size_t row, const Scalar diag = 1.0 ) { this->unitRow( row ); } - }; -public: - typedef FemMatrixBackend type; }; #else SET_PROP(FvBaseDiscretization, SparseMatrixAdapter) diff --git a/ewoms/linear/femsparsematrixadapter.hh b/ewoms/linear/femsparsematrixadapter.hh new file mode 100644 index 0000000000..aae62d8f00 --- /dev/null +++ b/ewoms/linear/femsparsematrixadapter.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: +/* + 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 . + + Consult the COPYING file in the top-level source directory of this + module for the precise wording of the license and the list of + copyright holders. +*/ +/*! + * \file + * \copydoc Ewoms::Linear::FemSparseMatrixAdapter + */ +#ifndef EWOMS_FEM_SPARSE_MATRIX_ADAPTER_HH +#define EWOMS_FEM_SPARSE_MATRIX_ADAPTER_HH + +// this code only works with dune-fem available +#if HAVE_DUNE_FEM + +// the following implementation of FemSparseMatrixAdapter only works for +// dune-fem version 2.7 or higher +#if DUNE_VERSION_NEWER(DUNE_FEM, 2, 7) +#include + +#if HAVE_PETSC +#include +#endif + +#include +#include + + +namespace Ewoms { +namespace Linear { + +/*! + * \ingroup Linear + * \brief A sparse matrix interface backend for linear operators from dune-fem. + * + * \note LinearOperators from dune-fem implement most methods needed for SparseMatrixAdapter + * and here we simply add a few forwarding methods. + */ +template +struct FemSparseMatrixAdapter : public LinearOperator +{ + typedef LinearOperator ParentType; + typedef typename LinearOperator :: MatrixType Matrix; + typedef typename ParentType :: MatrixBlockType MatrixBlock; + + typedef typename LinearOperator :: RangeFunctionType :: RangeFieldType Scalar; + + template + FemSparseMatrixAdapter( const Simulator& simulator ) + : LinearOperator("eWoms::Jacobian", simulator.model().space(), simulator.model().space() ) + {} + + void commit() + { + this->flushAssembly(); + } + + template< class LocalBlock > + void addToBlock ( const size_t row, const size_t col, const LocalBlock& block ) + { + this->addBlock( row, col, block ); + } + + void clearRow( const size_t row, const Scalar diag = 1.0 ) { this->unitRow( row ); } +}; + +template +using FemSparseRowMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::SparseRowLinearOperator< DiscreteFunction, DiscreteFunction > >; + +#if HAVE_PETSC +template +using FemPetscMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::PetscLinearOperator< DiscreteFunction, DiscreteFunction > >; +#endif + +#if HAVE_DUNE_ISTL +template +using FemISTLMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::ISTLLinearOperator< DiscreteFunction, DiscreteFunction > >; +#endif + +}} // namespace Linear, Ewoms + +#endif // DUNE_VERSION_NEWER(DUNE_FEM, 2, 7) +#endif // HAVE_DUNE_FEM +#endif