|
| 1 | +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | +// vi: set et ts=4 sw=4 sts=4: |
| 3 | +/* |
| 4 | + This file is part of the Open Porous Media project (OPM). |
| 5 | +
|
| 6 | + OPM is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation, either version 2 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + OPM is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with OPM. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +
|
| 19 | + Consult the COPYING file in the top-level source directory of this |
| 20 | + module for the precise wording of the license and the list of |
| 21 | + copyright holders. |
| 22 | +*/ |
| 23 | +/*! |
| 24 | + * \file |
| 25 | + * \copydoc Ewoms::Linear::FemSparseMatrixAdapter |
| 26 | + */ |
| 27 | +#ifndef EWOMS_FEM_SPARSE_MATRIX_ADAPTER_HH |
| 28 | +#define EWOMS_FEM_SPARSE_MATRIX_ADAPTER_HH |
| 29 | + |
| 30 | +// this code only works with dune-fem available |
| 31 | +#if HAVE_DUNE_FEM |
| 32 | + |
| 33 | +// the following implementation of FemSparseMatrixAdapter only works for |
| 34 | +// dune-fem version 2.7 or higher |
| 35 | +#if DUNE_VERSION_NEWER(DUNE_FEM, 2, 7) |
| 36 | +#include <dune/fem/function/blockvectorfunction.hh> |
| 37 | + |
| 38 | +#if HAVE_PETSC |
| 39 | +#include <dune/fem/operator/linear/petscoperator.hh> |
| 40 | +#endif |
| 41 | + |
| 42 | +#include <dune/fem/operator/linear/istloperator.hh> |
| 43 | +#include <dune/fem/operator/linear/spoperator.hh> |
| 44 | + |
| 45 | + |
| 46 | +namespace Ewoms { |
| 47 | +namespace Linear { |
| 48 | + |
| 49 | +/*! |
| 50 | + * \ingroup Linear |
| 51 | + * \brief A sparse matrix interface backend for linear operators from dune-fem. |
| 52 | + * |
| 53 | + * \note LinearOperators from dune-fem implement most methods needed for SparseMatrixAdapter |
| 54 | + * and here we simply add a few forwarding methods. |
| 55 | + */ |
| 56 | +template <class LinearOperator> |
| 57 | +struct FemSparseMatrixAdapter : public LinearOperator |
| 58 | +{ |
| 59 | + typedef LinearOperator ParentType; |
| 60 | + typedef typename LinearOperator :: MatrixType Matrix; |
| 61 | + typedef typename ParentType :: MatrixBlockType MatrixBlock; |
| 62 | + |
| 63 | + typedef typename LinearOperator :: RangeFunctionType :: RangeFieldType Scalar; |
| 64 | + |
| 65 | + template <class Simulator> |
| 66 | + FemSparseMatrixAdapter( const Simulator& simulator ) |
| 67 | + : LinearOperator("eWoms::Jacobian", simulator.model().space(), simulator.model().space() ) |
| 68 | + {} |
| 69 | + |
| 70 | + void commit() |
| 71 | + { |
| 72 | + this->flushAssembly(); |
| 73 | + } |
| 74 | + |
| 75 | + template< class LocalBlock > |
| 76 | + void addToBlock ( const size_t row, const size_t col, const LocalBlock& block ) |
| 77 | + { |
| 78 | + this->addBlock( row, col, block ); |
| 79 | + } |
| 80 | + |
| 81 | + void clearRow( const size_t row, const Scalar diag = 1.0 ) { this->unitRow( row ); } |
| 82 | +}; |
| 83 | + |
| 84 | +template <class DiscreteFunction> |
| 85 | +using FemSparseRowMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::SparseRowLinearOperator< DiscreteFunction, DiscreteFunction > >; |
| 86 | + |
| 87 | +#if HAVE_PETSC |
| 88 | +template <class DiscreteFunction> |
| 89 | +using FemPetscMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::PetscLinearOperator< DiscreteFunction, DiscreteFunction > >; |
| 90 | +#endif |
| 91 | + |
| 92 | +#if HAVE_DUNE_ISTL |
| 93 | +template <class DiscreteFunction> |
| 94 | +using FemISTLMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::ISTLLinearOperator< DiscreteFunction, DiscreteFunction > >; |
| 95 | +#endif |
| 96 | + |
| 97 | +}} // namespace Linear, Ewoms |
| 98 | + |
| 99 | +#endif // DUNE_VERSION_NEWER(DUNE_FEM, 2, 7) |
| 100 | +#endif // HAVE_DUNE_FEM |
| 101 | +#endif |
0 commit comments