Improves exceptions and message and resort to OPM_THROW for flexible solvers.

This commit is contained in:
Markus Blatt 2020-03-25 21:09:32 +01:00
parent ff0d54d4ea
commit 74b958c258
5 changed files with 23 additions and 22 deletions

View File

@ -164,9 +164,7 @@ private:
linsolver_.reset(new Dune::UMFPack<MatrixType>(linearoperator_->getmat(), verbosity, dummy)); linsolver_.reset(new Dune::UMFPack<MatrixType>(linearoperator_->getmat(), verbosity, dummy));
#endif #endif
} else { } else {
std::string msg("Solver not known "); OPM_THROW(std::invalid_argument, "Properties: Solver " << solver_type << " not known.");
msg += solver_type;
throw std::runtime_error(msg);
} }
} }

View File

@ -25,6 +25,8 @@
#include <opm/simulators/linalg/FlexibleSolver.hpp> #include <opm/simulators/linalg/FlexibleSolver.hpp>
#include <opm/simulators/linalg/setupPropertyTree.hpp> #include <opm/simulators/linalg/setupPropertyTree.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <memory> #include <memory>
@ -182,7 +184,8 @@ public:
return this->getTrueImpesWeights(b, pressureIndex); return this->getTrueImpesWeights(b, pressureIndex);
}; };
}else{ }else{
throw std::runtime_error("no such weights implemented for cpr"); OPM_THROW(std::invalid_argument, "Weights type " << weightsType << "not implemented for cpr."
<< " Please use quasiimpes or trueimpes.");
} }
} }

View File

@ -26,6 +26,8 @@
#include <opm/simulators/linalg/getQuasiImpesWeights.hpp> #include <opm/simulators/linalg/getQuasiImpesWeights.hpp>
#include <opm/simulators/linalg/twolevelmethodcpr.hh> #include <opm/simulators/linalg/twolevelmethodcpr.hh>
#include <opm/common/ErrorMacros.hpp>
#include <dune/common/fmatrix.hh> #include <dune/common/fmatrix.hh>
#include <dune/istl/bcrsmatrix.hh> #include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/paamg/amg.hh> #include <dune/istl/paamg/amg.hh>
@ -104,9 +106,10 @@ public:
, prm_(prm) , prm_(prm)
{ {
if (prm.get<int>("verbosity", 0) > 10) { if (prm.get<int>("verbosity", 0) > 10) {
std::ofstream outfile(prm.get<std::string>("weights_filename", "impes_weights.txt")); std::string filename = prm.get<std::string>("weights_filename", "impes_weights.txt");
std::ofstream outfile(filename);
if (!outfile) { if (!outfile) {
throw std::runtime_error("Could not write weights"); OPM_THROW(std::ofstream::failure, "Could not write weights to file " << filename << ".");
} }
Dune::writeMatrixMarket(weights_, outfile); Dune::writeMatrixMarket(weights_, outfile);
} }
@ -133,10 +136,11 @@ public:
{ {
//Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>( //Opm::Amg::getQuasiImpesWeights<MatrixType, VectorType>(
// linearoperator.getmat(), prm.get<int>("pressure_var_index"), transpose)) // linearoperator.getmat(), prm.get<int>("pressure_var_index"), transpose))
if (prm.get<int>("verbosity", 0) > 10) { if (prm.get<int>("verbosity", 0) > 10 && comm.communicator().rank() == 0) {
std::ofstream outfile(prm.get<std::string>("weights_filename", "impes_weights.txt")); auto filename = prm.get<std::string>("weights_filename", "impes_weights.txt");
std::ofstream outfile(filename);
if (!outfile) { if (!outfile) {
throw std::runtime_error("Could not write weights"); OPM_THROW(std::ofstream::failure, "Could not write weights to file " << filename << ".");
} }
Dune::writeMatrixMarket(weights_, outfile); Dune::writeMatrixMarket(weights_, outfile);
} }

View File

@ -226,9 +226,7 @@ private:
auto sargs = amgSmootherArgs<Smoother>(prm); auto sargs = amgSmootherArgs<Smoother>(prm);
return std::make_shared<Dune::Amg::AMGCPR<O, V, Smoother, C>>(op, crit, sargs, comm); return std::make_shared<Dune::Amg::AMGCPR<O, V, Smoother, C>>(op, crit, sargs, comm);
} else { } else {
std::string msg("No such smoother: "); OPM_THROW(std::invalid_argument, "Properties: No smoother with name " << smoother <<".");
msg += smoother;
throw std::runtime_error(msg);
} }
}); });
doAddCreator("cpr", [](const O& op, const P& prm, const std::function<Vector()> weightsCalculator, const C& comm) { doAddCreator("cpr", [](const O& op, const P& prm, const std::function<Vector()> weightsCalculator, const C& comm) {
@ -312,9 +310,7 @@ private:
#endif #endif
return makeAmgPreconditioner<Smoother>(op, prm); return makeAmgPreconditioner<Smoother>(op, prm);
} else { } else {
std::string msg("No such smoother: "); OPM_THROW(std::invalid_argument, "Properties: No smoother with name " << smoother <<".");
msg += smoother;
throw std::runtime_error(msg);
} }
}); });
doAddCreator("kamg", [](const O& op, const P& prm, const std::function<Vector()>&) { doAddCreator("kamg", [](const O& op, const P& prm, const std::function<Vector()>&) {
@ -338,9 +334,7 @@ private:
using Smoother = SeqILUn<M, V, V>; using Smoother = SeqILUn<M, V, V>;
return makeAmgPreconditioner<Smoother>(op, prm, true); return makeAmgPreconditioner<Smoother>(op, prm, true);
} else { } else {
std::string msg("No such smoother: "); OPM_THROW(std::invalid_argument, "Properties: No smoother with name " << smoother <<".");
msg += smoother;
throw std::runtime_error(msg);
} }
}); });
doAddCreator("famg", [](const O& op, const P& prm, const std::function<Vector()>&) { doAddCreator("famg", [](const O& op, const P& prm, const std::function<Vector()>&) {
@ -387,7 +381,7 @@ private:
msg << prec.first << ' '; msg << prec.first << ' ';
} }
msg << std::endl; msg << std::endl;
throw std::runtime_error(msg.str()); OPM_THROW(std::invalid_argument, msg.str());
} }
return it->second(op, prm, weightsCalculator); return it->second(op, prm, weightsCalculator);
} }
@ -405,7 +399,7 @@ private:
msg << prec.first << ' '; msg << prec.first << ' ';
} }
msg << std::endl; msg << std::endl;
throw std::runtime_error(msg.str()); OPM_THROW(std::invalid_argument, msg.str());
} }
return it->second(op, prm, weightsCalculator, comm); return it->second(op, prm, weightsCalculator, comm);
} }

View File

@ -39,7 +39,8 @@ setupPropertyTree(const FlowLinearSolverParameters& p)
if (p.linear_solver_configuration_ == "file") { if (p.linear_solver_configuration_ == "file") {
#if BOOST_VERSION / 100 % 1000 > 48 #if BOOST_VERSION / 100 % 1000 > 48
if (p.linear_solver_configuration_json_file_ == "none"){ if (p.linear_solver_configuration_json_file_ == "none"){
throw std::runtime_error("No linear-solver-configuration-json-file given for linear-solver-configuration=file "); OPM_THROW(std::invalid_argument, p.linear_solver_configuration_ << "is not a valid setting for --linear-solver-configuration."
<< " Please use ilu0, cpr_trueimpes, or cpr_quasiimpes");
}else{ }else{
boost::property_tree::read_json(p.linear_solver_configuration_json_file_, prm); boost::property_tree::read_json(p.linear_solver_configuration_json_file_, prm);
} }
@ -78,7 +79,8 @@ setupPropertyTree(const FlowLinearSolverParameters& p)
} }
} else { } else {
if(p.linear_solver_configuration_ != "ilu0"){ if(p.linear_solver_configuration_ != "ilu0"){
throw std::runtime_error("Not a valid setting for linear_solver_configuration"); OPM_THROW(std::invalid_argument, p.linear_solver_configuration_ << "is not a valid setting for --linear-solver-configuration."
<< " Please use ilu0, cpr_trueimpes, or cpr_quasiimpes");
} }
prm.put("tol", p.linear_solver_reduction_); prm.put("tol", p.linear_solver_reduction_);
prm.put("maxiter", p.linear_solver_maxiter_); prm.put("maxiter", p.linear_solver_maxiter_);