Skip to content

Commit

Permalink
Added FemSparseMatrixAdapter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Kloefkorn committed May 28, 2019
1 parent 063bbba commit 76e4371
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 35 deletions.
40 changes: 5 additions & 35 deletions ewoms/disc/common/fvbasediscretization.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@
#include <dune/fem/function/blockvectorfunction.hh>
#include <dune/fem/misc/capabilities.hh>

#if HAVE_PETSC
#include <dune/fem/operator/linear/petscoperator.hh>
#endif
#include <dune/fem/operator/linear/istloperator.hh>
#include <dune/fem/operator/linear/spoperator.hh>
#include <ewoms/linear/femsparsematrixadapter.hh>
#endif // endif HAVE_DUNE_FEM

#include <limits>
Expand Down Expand Up @@ -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<DiscreteFunctionSpace> 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 <class Simulator>
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)
Expand Down
101 changes: 101 additions & 0 deletions ewoms/linear/femsparsematrixadapter.hh
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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 <dune/fem/function/blockvectorfunction.hh>

#if HAVE_PETSC
#include <dune/fem/operator/linear/petscoperator.hh>
#endif

#include <dune/fem/operator/linear/istloperator.hh>
#include <dune/fem/operator/linear/spoperator.hh>


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 <class LinearOperator>
struct FemSparseMatrixAdapter : public LinearOperator
{
typedef LinearOperator ParentType;
typedef typename LinearOperator :: MatrixType Matrix;
typedef typename ParentType :: MatrixBlockType MatrixBlock;

typedef typename LinearOperator :: RangeFunctionType :: RangeFieldType Scalar;

template <class Simulator>
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 <class DiscreteFunction>
using FemSparseRowMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::SparseRowLinearOperator< DiscreteFunction, DiscreteFunction > >;

#if HAVE_PETSC
template <class DiscreteFunction>
using FemPetscMatrixAdapter = FemSparseMatrixAdapter< Dune::Fem::PetscLinearOperator< DiscreteFunction, DiscreteFunction > >;
#endif

#if HAVE_DUNE_ISTL
template <class DiscreteFunction>
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

0 comments on commit 76e4371

Please sign in to comment.