2015-11-18 03:50:12 -06:00
|
|
|
/*
|
|
|
|
Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services
|
|
|
|
Copyright 2015 Statoil AS
|
|
|
|
|
|
|
|
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 3 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/>.
|
|
|
|
*/
|
|
|
|
#ifndef OPM_PARALLELOVERLAPPINGILU0_HEADER_INCLUDED
|
|
|
|
#define OPM_PARALLELOVERLAPPINGILU0_HEADER_INCLUDED
|
|
|
|
|
2017-05-18 10:19:40 -05:00
|
|
|
#include <opm/common/Exceptions.hpp>
|
|
|
|
|
2018-01-22 10:23:22 -06:00
|
|
|
#include <dune/common/version.hh>
|
2015-11-18 03:50:12 -06:00
|
|
|
#include <dune/istl/preconditioner.hh>
|
|
|
|
#include <dune/istl/paamg/smoother.hh>
|
2017-05-29 11:34:55 -05:00
|
|
|
#include <dune/istl/paamg/pinfo.hh>
|
2015-11-18 03:50:12 -06:00
|
|
|
|
2017-10-11 09:32:34 -05:00
|
|
|
#include <type_traits>
|
|
|
|
|
2015-11-18 03:50:12 -06:00
|
|
|
namespace Opm
|
|
|
|
{
|
2015-12-01 07:47:28 -06:00
|
|
|
|
2017-05-18 10:19:40 -05:00
|
|
|
//template<class M, class X, class Y, class C>
|
|
|
|
//class ParallelOverlappingILU0;
|
2017-05-29 11:34:55 -05:00
|
|
|
template<class Matrix, class Domain, class Range, class ParallelInfo = Dune::Amg::SequentialInformation>
|
2015-11-18 03:50:12 -06:00
|
|
|
class ParallelOverlappingILU0;
|
2015-12-01 07:47:28 -06:00
|
|
|
|
|
|
|
} // end namespace Opm
|
|
|
|
|
2015-11-18 03:50:12 -06:00
|
|
|
namespace Dune
|
|
|
|
{
|
2015-12-01 07:47:28 -06:00
|
|
|
|
2015-11-18 03:50:12 -06:00
|
|
|
namespace Amg
|
|
|
|
{
|
|
|
|
|
2015-12-01 07:49:07 -06:00
|
|
|
/// \brief Tells AMG how to construct the Opm::ParallelOverlappingILU0 smoother
|
|
|
|
/// \tparam Matrix The type of the Matrix.
|
|
|
|
/// \tparam Domain The type of the Vector representing the domain.
|
|
|
|
/// \tparam Range The type of the Vector representing the range.
|
|
|
|
/// \tparam ParallelInfo The type of the parallel information object
|
|
|
|
/// used, e.g. Dune::OwnerOverlapCommunication
|
|
|
|
template<class Matrix, class Domain, class Range, class ParallelInfo>
|
|
|
|
struct ConstructionTraits<Opm::ParallelOverlappingILU0<Matrix,Domain,Range,ParallelInfo> >
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
2015-12-01 07:49:07 -06:00
|
|
|
typedef Dune::SeqILU0<Matrix,Domain,Range> T;
|
|
|
|
typedef DefaultParallelConstructionArgs<T,ParallelInfo> Arguments;
|
2015-11-18 03:50:12 -06:00
|
|
|
typedef ConstructionTraits<T> SeqConstructionTraits;
|
2015-12-01 07:49:07 -06:00
|
|
|
static inline Opm::ParallelOverlappingILU0<Matrix,Domain,Range,ParallelInfo>* construct(Arguments& args)
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
2015-12-01 07:49:07 -06:00
|
|
|
return new Opm::ParallelOverlappingILU0<Matrix,Domain,Range,ParallelInfo>(args.getMatrix(),
|
2015-11-18 03:50:12 -06:00
|
|
|
args.getComm(),
|
|
|
|
args.getArgs().relaxationFactor);
|
|
|
|
}
|
|
|
|
|
2015-12-01 07:49:07 -06:00
|
|
|
static inline void deconstruct(Opm::ParallelOverlappingILU0<Matrix,Domain,Range,ParallelInfo>* bp)
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
|
|
|
delete bp;
|
|
|
|
}
|
|
|
|
|
2015-12-01 07:48:35 -06:00
|
|
|
};
|
2015-11-18 03:50:12 -06:00
|
|
|
|
|
|
|
} // end namespace Amg
|
2015-12-01 07:47:28 -06:00
|
|
|
|
2017-05-18 10:19:40 -05:00
|
|
|
|
|
|
|
|
2015-11-18 03:50:12 -06:00
|
|
|
} // end namespace Dune
|
2015-12-01 07:47:28 -06:00
|
|
|
|
2015-11-18 03:50:12 -06:00
|
|
|
namespace Opm
|
|
|
|
{
|
2017-05-18 10:19:40 -05:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
//! compute ILU decomposition of A. A is overwritten by its decomposition
|
|
|
|
template<class M, class CRS, class InvVector>
|
|
|
|
void convertToCRS(const M& A, CRS& lower, CRS& upper, InvVector& inv )
|
|
|
|
{
|
2018-02-06 05:45:13 -06:00
|
|
|
// No need to do anything for 0 rows. Return to prevent indexing a
|
|
|
|
// a zero sized array.
|
|
|
|
if ( A.N() == 0 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-18 11:23:55 -05:00
|
|
|
typedef typename M :: size_type size_type;
|
|
|
|
|
2017-05-19 08:37:53 -05:00
|
|
|
lower.resize( A.N() );
|
|
|
|
upper.resize( A.N() );
|
2017-05-18 10:19:40 -05:00
|
|
|
inv.resize( A.N() );
|
|
|
|
|
2017-05-19 08:37:53 -05:00
|
|
|
lower.reserveAdditional( 2*A.N() );
|
|
|
|
|
2017-05-18 10:19:40 -05:00
|
|
|
// implement left looking variant with stored inverse
|
|
|
|
const auto endi = A.end();
|
|
|
|
size_type row = 0;
|
|
|
|
size_type colcount = 0;
|
|
|
|
lower.rows_[ 0 ] = colcount;
|
|
|
|
for (auto i=A.begin(); i!=endi; ++i, ++row)
|
|
|
|
{
|
2017-05-19 08:37:53 -05:00
|
|
|
const size_type iIndex = i.index();
|
|
|
|
lower.reserveAdditional( (*i).size() );
|
2017-05-18 10:19:40 -05:00
|
|
|
|
|
|
|
// eliminate entries left of diagonal; store L factor
|
|
|
|
for (auto j=(*i).begin(); j.index() < iIndex; ++j )
|
|
|
|
{
|
2017-05-19 08:37:53 -05:00
|
|
|
lower.push_back( (*j), j.index() );
|
2017-05-18 10:19:40 -05:00
|
|
|
++colcount;
|
|
|
|
}
|
|
|
|
lower.rows_[ iIndex+1 ] = colcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto rendi = A.beforeBegin();
|
|
|
|
row = 0;
|
|
|
|
colcount = 0;
|
|
|
|
upper.rows_[ 0 ] = colcount ;
|
2017-05-19 08:37:53 -05:00
|
|
|
|
|
|
|
upper.reserveAdditional( lower.nonZeros() + A.N() );
|
|
|
|
|
|
|
|
// NOTE: upper and inv store entries in reverse order, reverse here
|
|
|
|
// relative to ILU
|
2017-05-18 10:19:40 -05:00
|
|
|
for (auto i=A.beforeEnd(); i!=rendi; --i, ++ row )
|
|
|
|
{
|
|
|
|
const size_type iIndex = i.index();
|
2017-05-19 08:37:53 -05:00
|
|
|
upper.reserveAdditional( (*i).size() );
|
2017-05-18 10:19:40 -05:00
|
|
|
|
|
|
|
// store in reverse row order
|
|
|
|
// eliminate entries left of diagonal; store L factor
|
2017-06-14 04:09:26 -05:00
|
|
|
for (auto j=(*i).beforeEnd(); j.index()>=iIndex; --j )
|
2017-05-18 10:19:40 -05:00
|
|
|
{
|
|
|
|
const size_type jIndex = j.index();
|
|
|
|
if( j.index() == iIndex )
|
|
|
|
{
|
|
|
|
inv[ row ] = (*j);
|
2017-06-14 04:09:26 -05:00
|
|
|
break;
|
2017-05-18 10:19:40 -05:00
|
|
|
}
|
|
|
|
else if ( j.index() >= i.index() )
|
|
|
|
{
|
2017-05-19 08:37:53 -05:00
|
|
|
upper.push_back( (*j), jIndex );
|
2017-05-18 10:19:40 -05:00
|
|
|
++colcount ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
upper.rows_[ row+1 ] = colcount;
|
|
|
|
}
|
2017-05-19 08:37:53 -05:00
|
|
|
}
|
|
|
|
} // end namespace detail
|
2015-11-18 03:50:12 -06:00
|
|
|
|
2015-12-01 07:49:07 -06:00
|
|
|
/// \brief A two-step version of an overlapping Schwarz preconditioner using one step ILU0 as
|
|
|
|
///
|
|
|
|
/// This preconditioner differs from a ParallelRestrictedOverlappingSchwarz with
|
|
|
|
/// Dune:SeqILU0 in the follwing way:
|
|
|
|
/// During apply we make sure that the current residual is consistent (i.e.
|
|
|
|
/// each process knows the same value for each index. The we solve
|
|
|
|
/// Ly= d for y and make y consistent again. Last we solve Ux = y and
|
2015-12-01 08:13:22 -06:00
|
|
|
/// make sure that x is consistent.
|
2015-12-01 07:49:07 -06:00
|
|
|
/// In contrast for ParallelRestrictedOverlappingSchwarz we solve (LU)x = d for x
|
|
|
|
/// without forcing consistency between the two steps.
|
|
|
|
/// \tparam Matrix The type of the Matrix.
|
|
|
|
/// \tparam Domain The type of the Vector representing the domain.
|
|
|
|
/// \tparam Range The type of the Vector representing the range.
|
|
|
|
/// \tparam ParallelInfo The type of the parallel information object
|
|
|
|
/// used, e.g. Dune::OwnerOverlapCommunication
|
2017-05-18 10:19:40 -05:00
|
|
|
template<class Matrix, class Domain, class Range, class ParallelInfoT>
|
2015-12-01 07:49:07 -06:00
|
|
|
class ParallelOverlappingILU0
|
2017-05-18 10:19:40 -05:00
|
|
|
: public Dune::Preconditioner<Domain,Range>
|
|
|
|
{
|
2017-05-29 11:34:55 -05:00
|
|
|
typedef ParallelInfoT ParallelInfo;
|
2017-05-18 10:19:40 -05:00
|
|
|
|
2017-07-03 06:50:21 -05:00
|
|
|
|
2015-11-18 03:50:12 -06:00
|
|
|
public:
|
|
|
|
//! \brief The matrix type the preconditioner is for.
|
2017-10-05 04:32:34 -05:00
|
|
|
typedef typename std::remove_const<Matrix>::type matrix_type;
|
2015-11-18 03:50:12 -06:00
|
|
|
//! \brief The domain type of the preconditioner.
|
2015-12-01 07:49:07 -06:00
|
|
|
typedef Domain domain_type;
|
2015-11-18 03:50:12 -06:00
|
|
|
//! \brief The range type of the preconditioner.
|
2015-12-01 07:49:07 -06:00
|
|
|
typedef Range range_type;
|
2015-11-18 03:50:12 -06:00
|
|
|
//! \brief The field type of the preconditioner.
|
2015-12-01 07:49:07 -06:00
|
|
|
typedef typename Domain::field_type field_type;
|
2015-11-18 03:50:12 -06:00
|
|
|
|
2017-05-18 10:19:40 -05:00
|
|
|
typedef typename matrix_type::block_type block_type;
|
|
|
|
typedef typename matrix_type::size_type size_type;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct CRS
|
|
|
|
{
|
|
|
|
CRS() : nRows_( 0 ) {}
|
|
|
|
|
|
|
|
size_type rows() const { return nRows_; }
|
|
|
|
|
|
|
|
size_type nonZeros() const
|
|
|
|
{
|
|
|
|
assert( rows_[ rows() ] != size_type(-1) );
|
|
|
|
return rows_[ rows() ];
|
|
|
|
}
|
|
|
|
|
2017-05-19 08:37:53 -05:00
|
|
|
void resize( const size_type nRows )
|
2017-05-18 10:19:40 -05:00
|
|
|
{
|
|
|
|
if( nRows_ != nRows )
|
|
|
|
{
|
|
|
|
nRows_ = nRows ;
|
|
|
|
rows_.resize( nRows_+1, size_type(-1) );
|
|
|
|
}
|
2017-05-19 08:37:53 -05:00
|
|
|
}
|
2017-05-18 10:19:40 -05:00
|
|
|
|
2017-05-19 08:37:53 -05:00
|
|
|
void reserveAdditional( const size_type nonZeros )
|
|
|
|
{
|
|
|
|
const size_type needed = values_.size() + nonZeros ;
|
|
|
|
if( values_.capacity() < needed )
|
2017-05-18 10:19:40 -05:00
|
|
|
{
|
2017-05-19 08:37:53 -05:00
|
|
|
const size_type estimate = needed * 1.1;
|
|
|
|
values_.reserve( estimate );
|
|
|
|
cols_.reserve( estimate );
|
2017-05-18 10:19:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 08:37:53 -05:00
|
|
|
void push_back( const block_type& value, const size_type index )
|
|
|
|
{
|
|
|
|
values_.push_back( value );
|
|
|
|
cols_.push_back( index );
|
|
|
|
}
|
|
|
|
|
2017-05-18 10:19:40 -05:00
|
|
|
std::vector< size_type > rows_;
|
|
|
|
std::vector< block_type > values_;
|
|
|
|
std::vector< size_type > cols_;
|
|
|
|
size_type nRows_;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2018-01-22 10:23:22 -06:00
|
|
|
#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6)
|
|
|
|
Dune::SolverCategory::Category category() const override
|
|
|
|
{
|
|
|
|
return std::is_same<ParallelInfoT, Dune::Amg::SequentialInformation>::value ?
|
|
|
|
Dune::SolverCategory::sequential : Dune::SolverCategory::overlapping;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2015-11-18 03:50:12 -06:00
|
|
|
// define the category
|
|
|
|
enum {
|
|
|
|
//! \brief The category the preconditioner is part of.
|
2017-05-29 11:34:55 -05:00
|
|
|
category = std::is_same<ParallelInfoT, Dune::Amg::SequentialInformation>::value ?
|
2017-05-18 10:19:40 -05:00
|
|
|
Dune::SolverCategory::sequential : Dune::SolverCategory::overlapping
|
2015-11-18 03:50:12 -06:00
|
|
|
};
|
2018-01-22 10:23:22 -06:00
|
|
|
#endif
|
2015-11-18 03:50:12 -06:00
|
|
|
|
|
|
|
/*! \brief Constructor.
|
|
|
|
|
|
|
|
Constructor gets all parameters to operate the prec.
|
|
|
|
\param A The matrix to operate on.
|
2017-05-19 08:37:53 -05:00
|
|
|
\param n ILU fill in level (for testing). This does not work in parallel.
|
2015-11-18 03:50:12 -06:00
|
|
|
\param w The relaxation factor.
|
|
|
|
*/
|
2017-07-03 06:50:21 -05:00
|
|
|
template<class BlockType, class Alloc>
|
|
|
|
ParallelOverlappingILU0 (const Dune::BCRSMatrix<BlockType,Alloc>& A,
|
|
|
|
const int n, const field_type w )
|
2017-05-18 10:19:40 -05:00
|
|
|
: lower_(),
|
|
|
|
upper_(),
|
|
|
|
inv_(),
|
|
|
|
comm_(nullptr), w_(w),
|
|
|
|
relaxation_( std::abs( w - 1.0 ) > 1e-15 )
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
2017-07-03 02:17:37 -05:00
|
|
|
// BlockMatrix is a Subclass of FieldMatrix that just adds
|
|
|
|
// methods. Therefore this cast should be safe.
|
2018-02-01 01:50:16 -06:00
|
|
|
init( reinterpret_cast<const Matrix&>(A), n );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Constructor gets all parameters to operate the prec.
|
|
|
|
\param A The matrix to operate on.
|
|
|
|
\param comm communication object, e.g. Dune::OwnerOverlapCopyCommunication
|
|
|
|
\param n ILU fill in level (for testing). This does not work in parallel.
|
|
|
|
\param w The relaxation factor.
|
|
|
|
*/
|
|
|
|
template<class BlockType, class Alloc>
|
|
|
|
ParallelOverlappingILU0 (const Dune::BCRSMatrix<BlockType,Alloc>& A,
|
|
|
|
const ParallelInfo& comm, const int n, const field_type w )
|
|
|
|
: lower_(),
|
|
|
|
upper_(),
|
|
|
|
inv_(),
|
|
|
|
comm_(&comm), w_(w),
|
|
|
|
relaxation_( std::abs( w - 1.0 ) > 1e-15 )
|
|
|
|
{
|
|
|
|
// BlockMatrix is a Subclass of FieldMatrix that just adds
|
|
|
|
// methods. Therefore this cast should be safe.
|
2017-07-03 02:17:37 -05:00
|
|
|
init( reinterpret_cast<const Matrix&>(A), n );
|
2017-05-18 10:19:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Constructor.
|
|
|
|
|
|
|
|
Constructor gets all parameters to operate the prec.
|
|
|
|
\param A The matrix to operate on.
|
|
|
|
\param w The relaxation factor.
|
|
|
|
*/
|
2017-07-03 06:50:21 -05:00
|
|
|
template<class BlockType, class Alloc>
|
|
|
|
ParallelOverlappingILU0 (const Dune::BCRSMatrix<BlockType,Alloc>& A,
|
|
|
|
const field_type w)
|
2017-05-18 10:19:40 -05:00
|
|
|
: ParallelOverlappingILU0( A, 0, w )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-19 08:37:53 -05:00
|
|
|
/*! \brief Constructor.
|
|
|
|
|
|
|
|
Constructor gets all parameters to operate the prec.
|
|
|
|
\param A The matrix to operate on.
|
|
|
|
\param comm communication object, e.g. Dune::OwnerOverlapCopyCommunication
|
|
|
|
\param w The relaxation factor.
|
|
|
|
*/
|
2017-07-03 06:50:21 -05:00
|
|
|
template<class BlockType, class Alloc>
|
|
|
|
ParallelOverlappingILU0 (const Dune::BCRSMatrix<BlockType,Alloc>& A,
|
|
|
|
const ParallelInfo& comm, const field_type w)
|
2017-05-18 10:19:40 -05:00
|
|
|
: lower_(),
|
|
|
|
upper_(),
|
|
|
|
inv_(),
|
|
|
|
comm_(&comm), w_(w),
|
|
|
|
relaxation_( std::abs( w - 1.0 ) > 1e-15 )
|
|
|
|
{
|
2017-07-03 02:17:37 -05:00
|
|
|
// BlockMatrix is a Subclass of FieldMatrix that just adds
|
|
|
|
// methods. Therefore this cast should be safe.
|
|
|
|
init( reinterpret_cast<const Matrix&>(A), 0 );
|
2015-11-18 03:50:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Prepare the preconditioner.
|
|
|
|
|
|
|
|
\copydoc Preconditioner::pre(X&,Y&)
|
|
|
|
*/
|
2015-12-01 07:49:07 -06:00
|
|
|
virtual void pre (Domain& x, Range& b)
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
|
|
|
DUNE_UNUSED_PARAMETER(x);
|
|
|
|
DUNE_UNUSED_PARAMETER(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Apply the preconditoner.
|
|
|
|
|
|
|
|
\copydoc Preconditioner::apply(X&,const Y&)
|
|
|
|
*/
|
2015-12-01 07:49:07 -06:00
|
|
|
virtual void apply (Domain& v, const Range& d)
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
2015-12-01 07:49:07 -06:00
|
|
|
Range& md = const_cast<Range&>(d);
|
2017-05-18 10:19:40 -05:00
|
|
|
copyOwnerToAll( md );
|
|
|
|
|
|
|
|
// iterator types
|
|
|
|
typedef typename Range ::block_type dblock;
|
|
|
|
typedef typename Domain::block_type vblock;
|
|
|
|
|
|
|
|
const size_type iEnd = lower_.rows();
|
|
|
|
const size_type lastRow = iEnd - 1;
|
|
|
|
if( iEnd != upper_.rows() )
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
2017-05-18 10:19:40 -05:00
|
|
|
std::abort();
|
|
|
|
// OPM_THROW(std::logic_error,"ILU: lower and upper rows must be the same");
|
2015-11-18 03:50:12 -06:00
|
|
|
}
|
2017-05-18 10:19:40 -05:00
|
|
|
|
|
|
|
// lower triangular solve
|
|
|
|
for( size_type i=0; i<iEnd; ++ i )
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
2017-05-18 10:19:40 -05:00
|
|
|
dblock rhs( d[ i ] );
|
|
|
|
const size_type rowI = lower_.rows_[ i ];
|
|
|
|
const size_type rowINext = lower_.rows_[ i+1 ];
|
|
|
|
|
|
|
|
for( size_type col = rowI; col < rowINext; ++ col )
|
|
|
|
{
|
|
|
|
lower_.values_[ col ].mmv( v[ lower_.cols_[ col ] ], rhs );
|
|
|
|
}
|
|
|
|
|
|
|
|
v[ i ] = rhs; // Lii = I
|
|
|
|
}
|
|
|
|
|
|
|
|
copyOwnerToAll( v );
|
|
|
|
|
|
|
|
for( size_type i=0; i<iEnd; ++ i )
|
|
|
|
{
|
|
|
|
vblock& vBlock = v[ lastRow - i ];
|
|
|
|
vblock rhs ( vBlock );
|
|
|
|
const size_type rowI = upper_.rows_[ i ];
|
|
|
|
const size_type rowINext = upper_.rows_[ i+1 ];
|
|
|
|
|
|
|
|
for( size_type col = rowI; col < rowINext; ++ col )
|
2015-12-02 04:29:38 -06:00
|
|
|
{
|
2017-05-18 10:19:40 -05:00
|
|
|
upper_.values_[ col ].mmv( v[ upper_.cols_[ col ] ], rhs );
|
2015-12-02 04:29:38 -06:00
|
|
|
}
|
2017-05-18 10:19:40 -05:00
|
|
|
|
|
|
|
// apply inverse and store result
|
|
|
|
inv_[ i ].mv( rhs, vBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
copyOwnerToAll( v );
|
|
|
|
|
|
|
|
if( relaxation_ ) {
|
|
|
|
v *= w_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class V>
|
|
|
|
void copyOwnerToAll( V& v ) const
|
|
|
|
{
|
|
|
|
if( comm_ ) {
|
|
|
|
comm_->copyOwnerToAll(v, v);
|
2015-11-18 03:50:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Clean up.
|
|
|
|
|
|
|
|
\copydoc Preconditioner::post(X&)
|
|
|
|
*/
|
2015-12-01 07:49:07 -06:00
|
|
|
virtual void post (Range& x)
|
2015-11-18 03:50:12 -06:00
|
|
|
{
|
|
|
|
DUNE_UNUSED_PARAMETER(x);
|
|
|
|
}
|
|
|
|
|
2017-05-18 10:19:40 -05:00
|
|
|
protected:
|
|
|
|
void init( const Matrix& A, const int iluIteration )
|
|
|
|
{
|
|
|
|
int ilu_setup_successful = 1;
|
|
|
|
std::string message;
|
|
|
|
const int rank = ( comm_ ) ? comm_->communicator().rank() : 0;
|
|
|
|
|
|
|
|
std::unique_ptr< Matrix > ILU;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( iluIteration == 0 ) {
|
|
|
|
// create ILU-0 decomposition
|
|
|
|
ILU.reset( new Matrix( A ) );
|
|
|
|
bilu0_decomposition( *ILU );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// create ILU-n decomposition
|
|
|
|
ILU.reset( new Matrix( A.N(), A.M(), Matrix::row_wise) );
|
|
|
|
bilu_decomposition( A, iluIteration, *ILU );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( Dune::MatrixBlockError error )
|
|
|
|
{
|
|
|
|
message = error.what();
|
|
|
|
std::cerr<<"Exception occured on process " << rank << " during " <<
|
|
|
|
"setup of ILU0 preconditioner with message: " <<
|
|
|
|
message<<std::endl;
|
|
|
|
ilu_setup_successful = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether there was a problem on some process
|
|
|
|
if ( comm_ && comm_->communicator().min(ilu_setup_successful) == 0 )
|
|
|
|
{
|
|
|
|
throw Dune::MatrixBlockError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// store ILU in simple CRS format
|
|
|
|
detail::convertToCRS( *ILU, lower_, upper_, inv_ );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-11-18 03:50:12 -06:00
|
|
|
//! \brief The ILU0 decomposition of the matrix.
|
2017-05-18 10:19:40 -05:00
|
|
|
CRS lower_;
|
|
|
|
CRS upper_;
|
|
|
|
std::vector< block_type > inv_;
|
|
|
|
|
|
|
|
const ParallelInfo* comm_;
|
2015-11-18 03:50:12 -06:00
|
|
|
//! \brief The relaxation factor to use.
|
2017-05-18 10:19:40 -05:00
|
|
|
const field_type w_;
|
|
|
|
const bool relaxation_;
|
2015-11-18 03:50:12 -06:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Opm
|
|
|
|
#endif
|