Skip to content

Commit 76e4371

Browse files
author
Robert Kloefkorn
committed
Added FemSparseMatrixAdapter.
1 parent 063bbba commit 76e4371

File tree

2 files changed

+106
-35
lines changed

2 files changed

+106
-35
lines changed

ewoms/disc/common/fvbasediscretization.hh

+5-35
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@
7777
#include <dune/fem/function/blockvectorfunction.hh>
7878
#include <dune/fem/misc/capabilities.hh>
7979

80-
#if HAVE_PETSC
81-
#include <dune/fem/operator/linear/petscoperator.hh>
82-
#endif
83-
#include <dune/fem/operator/linear/istloperator.hh>
84-
#include <dune/fem/operator/linear/spoperator.hh>
80+
#include <ewoms/linear/femsparsematrixadapter.hh>
8581
#endif // endif HAVE_DUNE_FEM
8682

8783
#include <limits>
@@ -154,46 +150,20 @@ SET_PROP(FvBaseDiscretization, SparseMatrixAdapter)
154150
{
155151
private:
156152
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
157-
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
158153
// discrete function storing solution data
159154
typedef Dune::Fem::ISTLBlockVectorDiscreteFunction<DiscreteFunctionSpace> DiscreteFunction;
155+
public:
160156

161157
#if USE_DUNE_FEM_PETSC_SOLVERS
162158
#warning "Using Dune-Fem PETSc solvers"
163-
typedef Dune::Fem::PetscLinearOperator< DiscreteFunction, DiscreteFunction > LinearOperator;
159+
typedef FemPetscMatrixAdapter< DiscreteFunction > type;
164160
#elif USE_DUNE_FEM_VIENNACL_SOLVERS
165161
#warning "Using Dune-Fem ViennaCL solvers"
166-
typedef Dune::Fem::SparseRowLinearOperator < DiscreteFunction, DiscreteFunction > LinearOperator;
162+
typedef FemSparseRowMatrixAdapter< DiscreteFunction > type;
167163
#else
168164
#warning "Using Dune-Fem ISTL solvers"
169-
typedef Dune::Fem::ISTLLinearOperator < DiscreteFunction, DiscreteFunction > LinearOperator;
165+
typedef FemISTLMatrixAdapter< DiscreteFunction > type;
170166
#endif
171-
172-
struct FemMatrixBackend : public LinearOperator
173-
{
174-
typedef LinearOperator ParentType;
175-
typedef typename LinearOperator :: MatrixType Matrix;
176-
typedef typename ParentType :: MatrixBlockType MatrixBlock;
177-
template <class Simulator>
178-
FemMatrixBackend( const Simulator& simulator )
179-
: LinearOperator("eWoms::Jacobian", simulator.model().space(), simulator.model().space() )
180-
{}
181-
182-
void commit()
183-
{
184-
this->flushAssembly();
185-
}
186-
187-
template< class LocalBlock >
188-
void addToBlock ( const size_t row, const size_t col, const LocalBlock& block )
189-
{
190-
this->addBlock( row, col, block );
191-
}
192-
193-
void clearRow( const size_t row, const Scalar diag = 1.0 ) { this->unitRow( row ); }
194-
};
195-
public:
196-
typedef FemMatrixBackend type;
197167
};
198168
#else
199169
SET_PROP(FvBaseDiscretization, SparseMatrixAdapter)
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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

Comments
 (0)