Loading...
Searching...
No Matches
ParallelOverlappingILU0.hpp
/*
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
#include <opm/common/TimingMacros.hpp>
#include <opm/simulators/linalg/MILU.hpp>
#include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
#include <dune/istl/paamg/smoother.hh>
#include <cstddef>
#include <vector>
#include <type_traits>
namespace Opm
{
//template<class M, class X, class Y, class C>
//class ParallelOverlappingILU0;
template<class Matrix, class Domain, class Range, class ParallelInfo>
class ParallelOverlappingILU0;
template<class F>
class ParallelOverlappingILU0Args
: public Dune::Amg::DefaultSmootherArgs<F>
{
public:
explicit ParallelOverlappingILU0Args(MILU_VARIANT milu = MILU_VARIANT::ILU )
: milu_(milu), n_(0)
{}
void setMilu(MILU_VARIANT milu)
{
milu_ = milu;
}
MILU_VARIANT getMilu() const
{
return milu_;
}
void setN(int n)
{
n_ = n;
}
int getN() const
{
return n_;
}
private:
MILU_VARIANT milu_;
int n_;
};
} // end namespace Opm
namespace Dune
{
namespace Amg
{
template<class M, class X, class Y, class C>
struct SmootherTraits<Opm::ParallelOverlappingILU0<M,X,Y,C> >
{
using Arguments = Opm::ParallelOverlappingILU0Args<typename M::field_type>;
};
template<class Matrix, class Domain, class Range, class ParallelInfo>
struct ConstructionTraits<Opm::ParallelOverlappingILU0<Matrix,Domain,Range,ParallelInfo> >
{
using T = Opm::ParallelOverlappingILU0<Matrix,Domain,Range,ParallelInfo>;
using Arguments = DefaultParallelConstructionArgs<T,ParallelInfo>;
using ParallelOverlappingILU0Pointer = std::shared_ptr<T>;
static inline ParallelOverlappingILU0Pointer construct(Arguments& args)
{
return ParallelOverlappingILU0Pointer(
new T(args.getMatrix(),
args.getComm(),
args.getArgs().getN(),
args.getArgs().relaxationFactor,
args.getArgs().getMilu()) );
}
};
} // end namespace Amg
} // end namespace Dune
namespace Opm
{
template<class Matrix, class Domain, class Range, class ParallelInfoT>
class ParallelOverlappingILU0
: public Dune::PreconditionerWithUpdate<Domain,Range>
{
using ParallelInfo = ParallelInfoT;
public:
using matrix_type = typename std::remove_const<Matrix>::type;
using domain_type = Domain;
using range_type = Range;
using field_type = typename Domain::field_type;
using block_type = typename matrix_type::block_type;
using size_type = typename matrix_type::size_type;
virtual bool hasPerfectUpdate() const override {
return true;
}
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() ];
}
void resize( const size_type nRows )
{
if( nRows_ != nRows )
{
nRows_ = nRows ;
rows_.resize( nRows_+1, size_type(-1) );
}
}
void reserveAdditional( const size_type nonZeros )
{
const size_type needed = values_.size() + nonZeros ;
if( values_.capacity() < needed )
{
const size_type estimate = needed * 1.1;
values_.reserve( estimate );
cols_.reserve( estimate );
}
}
void push_back( const block_type& value, const size_type index )
{
values_.push_back( value );
cols_.push_back( index );
}
void clear()
{
rows_.clear();
values_.clear();
cols_.clear();
nRows_= 0;
}
std::vector<size_type> rows_;
std::vector<block_type> values_;
std::vector<size_type> cols_;
size_type nRows_;
};
public:
Dune::SolverCategory::Category category() const override;
ParallelOverlappingILU0 (const Matrix& A,
const int n, const field_type w,
MILU_VARIANT milu, bool redblack = false,
bool reorder_sphere = true);
ParallelOverlappingILU0 (const Matrix& A,
const ParallelInfo& comm, const int n, const field_type w,
MILU_VARIANT milu, bool redblack = false,
bool reorder_sphere = true);
ParallelOverlappingILU0 (const Matrix& A,
const field_type w, MILU_VARIANT milu,
bool redblack = false,
bool reorder_sphere = true);
ParallelOverlappingILU0 (const Matrix& A,
const ParallelInfo& comm, const field_type w,
MILU_VARIANT milu, bool redblack = false,
bool reorder_sphere = true);
ParallelOverlappingILU0 (const Matrix& A,
const ParallelInfo& comm,
const field_type w, MILU_VARIANT milu,
size_type interiorSize, bool redblack = false,
bool reorder_sphere = true);
void pre (Domain&, Range&) override
{}
void apply (Domain& v, const Range& d) override;
template <class V>
void copyOwnerToAll( V& v ) const;
void post (Range&) override
{}
void update() override;
protected:
Range& reorderD(const Range& d);
Domain& reorderV(Domain& v);
void reorderBack(const Range& reorderedV, Range& v);
std::unique_ptr<Matrix> ILU_;
CRS lower_;
CRS upper_;
std::vector< block_type > inv_;
std::vector< std::size_t > ordering_;
Range reorderedD_;
Domain reorderedV_;
const ParallelInfo* comm_;
const field_type w_;
const bool relaxation_;
size_type interiorSize_;
const Matrix* A_;
int iluIteration_;
MILU_VARIANT milu_;
bool redBlack_;
bool reorderSphere_;
};
} // end namespace Opm
#endif
Dune::PreconditionerWithUpdate
Interface class adding the update() method to the preconditioner interface.
Definition PreconditionerWithUpdate.hpp:32
Opm::ParallelOverlappingILU0Args
Definition ParallelOverlappingILU0.hpp:42
Opm::ParallelOverlappingILU0
A two-step version of an overlapping Schwarz preconditioner using one step ILU0 as.
Definition ParallelOverlappingILU0.hpp:131
Opm::ParallelOverlappingILU0::ParallelOverlappingILU0
ParallelOverlappingILU0(const Matrix &A, const int n, const field_type w, MILU_VARIANT milu, bool redblack=false, bool reorder_sphere=true)
Constructor.
Definition ParallelOverlappingILU0_impl.hpp:233
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::ILU_
std::unique_ptr< Matrix > ILU_
Definition ParallelOverlappingILU0.hpp:335
Opm::ParallelOverlappingILU0::reorderV
Domain & reorderV(Domain &v)
Reorder V if needed and return a reference to it.
Definition ParallelOverlappingILU0_impl.hpp:590
Opm::ParallelOverlappingILU0::ParallelOverlappingILU0
ParallelOverlappingILU0(const Matrix &A, const ParallelInfo &comm, const int n, const field_type w, MILU_VARIANT milu, bool redblack=false, bool reorder_sphere=true)
Constructor gets all parameters to operate the prec.
Definition ParallelOverlappingILU0_impl.hpp:253
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::matrix_type
typename std::remove_const< Matrix >::type matrix_type
Definition ParallelOverlappingILU0.hpp:136
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::domain_type
Domain domain_type
Definition ParallelOverlappingILU0.hpp:138
Opm::ParallelOverlappingILU0::ParallelOverlappingILU0
ParallelOverlappingILU0(const Matrix &A, const ParallelInfo &comm, const field_type w, MILU_VARIANT milu, size_type interiorSize, bool redblack=false, bool reorder_sphere=true)
Constructor.
Definition ParallelOverlappingILU0_impl.hpp:301
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::ordering_
std::vector< std::size_t > ordering_
Definition ParallelOverlappingILU0.hpp:340
Opm::ParallelOverlappingILU0::ParallelOverlappingILU0
ParallelOverlappingILU0(const Matrix &A, const field_type w, MILU_VARIANT milu, bool redblack=false, bool reorder_sphere=true)
Constructor.
Definition ParallelOverlappingILU0_impl.hpp:273
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::reorderedV_
Domain reorderedV_
Definition ParallelOverlappingILU0.hpp:344
Opm::ParallelOverlappingILU0::post
void post(Range &) override
Clean up.
Definition ParallelOverlappingILU0.hpp:320
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::reorderedD_
Range reorderedD_
Definition ParallelOverlappingILU0.hpp:342
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::w_
const field_type w_
Definition ParallelOverlappingILU0.hpp:348
Opm::ParallelOverlappingILU0::reorderD
Range & reorderD(const Range &d)
Reorder D if needed and return a reference to it.
Definition ParallelOverlappingILU0_impl.hpp:566
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::range_type
Range range_type
Definition ParallelOverlappingILU0.hpp:140
Opm::ParallelOverlappingILU0::ParallelOverlappingILU0
ParallelOverlappingILU0(const Matrix &A, const ParallelInfo &comm, const field_type w, MILU_VARIANT milu, bool redblack=false, bool reorder_sphere=true)
Constructor.
Definition ParallelOverlappingILU0_impl.hpp:281
Opm::ParallelOverlappingILU0::apply
void apply(Domain &v, const Range &d) override
Apply the preconditoner.
Definition ParallelOverlappingILU0_impl.hpp:323
Opm::ParallelOverlappingILU0::pre
void pre(Domain &, Range &) override
Prepare the preconditioner.
Definition ParallelOverlappingILU0.hpp:302
Opm::ParallelOverlappingILU0< Matrix, Domain, Range, ParallelInfo >::field_type
typename Domain::field_type field_type
Definition ParallelOverlappingILU0.hpp:142
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::MILU_VARIANT
MILU_VARIANT
Definition MILU.hpp:34
Opm::MILU_VARIANT::ILU
@ ILU
Do not perform modified ILU.
Definition MILU.hpp:36