changed interface to only have minimal overhead using true impes.

It gives overhead in constructor when linear system is created. No overhead if reuse is used.
This commit is contained in:
hnil
2019-08-21 22:22:02 +02:00
parent 2b147dd4f6
commit 141903a26d
6 changed files with 46 additions and 26 deletions
@@ -142,30 +142,32 @@ public:
assert(recreate_solver == false);
// Never recreate solver.
}
VectorType weights;
if( prm_.get<std::string>("preconditioner.type") == "cpr" ||
prm_.get<std::string>("preconditioner.type") == "cprt"
)
{
{
bool transpose = false;
if(prm_.get<std::string>("preconditioner.type") == "cprt"){
transpose = true;
}
if(prm_.get<std::string>("preconditioner.weight_type") == "quasiimpes") {
VectorType weights = Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>(
mat.istlMatrix(),
prm_.get<int>("preconditioner.pressure_var_index"), transpose);
prm_.put("preconditioner.weights",weights);
if( not( recreate_solver || !solver_) ){
// weighs will be created as default in the solver
weights = Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>(
mat.istlMatrix(),
prm_.get<int>("preconditioner.pressure_var_index"), transpose);
}
}else if(prm_.get<std::string>("preconditioner.weight_type") == "trueimpes" ){
VectorType weights =
weights =
this->getTrueImpesWeights(b, prm_.get<int>("preconditioner.pressure_var_index"));
prm_.put("preconditioner.weights",weights);
if( recreate_solver || !solver_){
// need weights for the constructor
prm_.put("preconditioner.weights",weights);
}
}else{
throw std::runtime_error("no such weights implemented for cpr");
}
}
}else{
}
@@ -181,7 +183,7 @@ public:
}
rhs_ = b;
} else {
solver_->preconditioner().update(prm_.get_child("preconditioner"));
solver_->preconditioner().update(weights, prm_.get_child("preconditioner"));
rhs_ = b;
}
}
@@ -63,9 +63,9 @@ public:
}
// The update() function does nothing for a wrapped preconditioner.
virtual void update(const boost::property_tree::ptree& pt) override
virtual void update(const X& w,const boost::property_tree::ptree& pt) override
{
orig_precond_.update(pt);
orig_precond_.update(w, pt);
}
private:
@@ -84,7 +84,13 @@ public:
: linear_operator_(linearoperator)
, finesmoother_(PrecFactory::create(linearoperator, prm.get_child("finesmoother")))
, comm_(nullptr)
, weights_(prm.get<VectorType>("weights"))
, weights_(
(prm.get<std::string>("weight_type") != "quasiimpes") ?
prm.get<VectorType>("weights") :
Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>(linearoperator.getmat(),
prm.get<int>("pressure_var_index"),
transpose)
)
, levelTransferPolicy_(dummy_comm_, weights_, prm.get<int>("pressure_var_index"))
, coarseSolverPolicy_(prm.get_child("coarsesolver"))
, twolevel_method_(linearoperator,
@@ -108,7 +114,13 @@ public:
: linear_operator_(linearoperator)
, finesmoother_(PrecFactory::create(linearoperator, prm.get_child("finesmoother"), comm))
, comm_(&comm)
, weights_(prm.get<VectorType>("weights"))
, weights_(
(prm.get<std::string>("weight_type") != "quasiimpes") ?
prm.get<VectorType>("weights") :
Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>(linearoperator.getmat(),
prm.get<int>("pressure_var_index"),
transpose)
)
, levelTransferPolicy_(*comm_, weights_, prm.get<int>("pressure_var_index"))
, coarseSolverPolicy_(prm.get_child("coarsesolver"))
, twolevel_method_(linearoperator,
@@ -145,11 +157,16 @@ public:
twolevel_method_.post(x);
}
virtual void update(const boost::property_tree::ptree& prm) override
virtual void update(const VectorType& weights, const boost::property_tree::ptree& /*prm*/) override
{
//Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>(
// linear_operator_.getmat(), prm_.get<int>("pressure_var_index"), transpose, weights_);
weights_ = prm.get<VectorType>("weights");
// if(prm.get<std::string>("weight_type") == "quasiimpes"){
// Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>(
// linear_operator_.getmat(), prm_.get<int>("pressure_var_index"), transpose, weights_);
// weights_ = prm.get<VectorType>("weights");
// }else{
weights_ = weights;
//}
updateImpl(comm_);
}
@@ -31,7 +31,7 @@ template <class X, class Y>
class PreconditionerWithUpdate : public Preconditioner<X, Y>
{
public:
virtual void update(const boost::property_tree::ptree& pt) = 0;
virtual void update(const X& w, const boost::property_tree::ptree& pt) = 0;
};
template <class OriginalPreconditioner>
@@ -69,7 +69,7 @@ public:
}
// The update() function does nothing for a wrapped preconditioner.
virtual void update(const boost::property_tree::ptree& pt) override
virtual void update(const X& /*w*/, const boost::property_tree::ptree& /*pt*/) override
{
}
@@ -85,7 +85,8 @@ namespace Amg
void updatePreconditioner()
{
pt::ptree prm;
linsolver_->preconditioner().update(prm);
X w;
linsolver_->preconditioner().update(w, prm);
}
private:
+2 -2
View File
@@ -299,7 +299,7 @@ namespace Dune
/**
* @brief Update the coarse solver and the hierarchies.
*/
virtual void update(const boost::property_tree::ptree& prm);
virtual void update(const X& w, const boost::property_tree::ptree& prm);
virtual void update();
/**
@@ -540,7 +540,7 @@ namespace Dune
}
template<class M, class X, class S, class PI, class A>
void AMGCPR<M,X,S,PI,A>::update(const boost::property_tree::ptree& prm)
void AMGCPR<M,X,S,PI,A>::update(const X& /*w*/, const boost::property_tree::ptree& /*prm*/)
{
update();
}