Added possibility to set tolerance for linear solvers.

This commit is contained in:
Xavier Raynaud 2012-06-06 15:14:46 +02:00
parent d1a4fa6dcd
commit c81a840382
9 changed files with 94 additions and 5 deletions

View File

@ -93,6 +93,15 @@ namespace Opm
return solver_->solve(size, nonzeros, ia, ja, sa, rhs, solution);
}
void LinearSolverFactory::setTolerance(const double tol)
{
solver_->setTolerance(tol);
}
double LinearSolverFactory::getTolerance() const
{
return solver_->getTolerance();
}

View File

@ -75,6 +75,17 @@ namespace Opm
const double* sa,
const double* rhs,
double* solution) const;
/// Set tolerance for the linear solver.
/// \param[in] tol tolerance value
/// Not used for LinearSolverFactory
virtual void setTolerance(const double tol);
/// Get tolerance for the linear solver.
/// \param[out] tolerance value
/// Not used for LinearSolverFactory. Returns -1.
virtual double getTolerance() const;
private:
std::tr1::shared_ptr<LinearSolverInterface> solver_;
};

View File

@ -71,6 +71,14 @@ namespace Opm
const double* rhs,
double* solution) const = 0;
/// Set tolerance for the linear solver.
/// \param[in] tol tolerance value
virtual void setTolerance(const double tol) = 0;
/// Get tolerance for the linear solver.
/// \param[out] tolerance value
virtual double getTolerance() const = 0;
};

View File

@ -172,6 +172,17 @@ namespace Opm
return res;
}
void LinearSolverIstl::setTolerance(const double tol)
{
linsolver_residual_tolerance_ = tol;
}
double LinearSolverIstl::getTolerance() const
{
return linsolver_residual_tolerance_;
}
namespace
{

View File

@ -71,6 +71,15 @@ namespace Opm
const double* sa,
const double* rhs,
double* solution) const;
/// Set tolerance for the residual in dune istl linear solver.
/// \param[in] tol tolerance value
virtual void setTolerance(const double tol);
/// Get tolerance ofthe linear solver.
/// \param[out] tolerance value
virtual double getTolerance() const;
private:
double linsolver_residual_tolerance_;
int linsolver_verbosity_;

View File

@ -60,5 +60,15 @@ namespace Opm
return rep;
}
void LinearSolverUmfpack::setTolerance(const double /*tol*/)
{
}
double LinearSolverUmfpack::getTolerance() const
{
return -1.;
}
} // namespace Opm

View File

@ -56,6 +56,18 @@ namespace Opm
const double* sa,
const double* rhs,
double* solution) const;
/// Set tolerance for the linear solver.
/// \param[in] tol tolerance value
/// Not used for UMFPACK solver.
virtual void setTolerance(const double /*tol*/);
/// Get tolerance for the linear solver.
/// \param[out] tolerance value
/// Not used for UMFPACK solver. Returns -1.
virtual double getTolerance() const;
};

View File

@ -40,12 +40,12 @@ namespace Opm
/// and N == g.number_of_cells.
/// \param[in] gravity Gravity vector. If nonzero, the array should
/// have D elements.
/// \param[in] wells The wells argument. Will be used in solution,
/// \param[in] wells The wells argument. Will be used in solution,
/// is ignored if NULL
IncompTpfa::IncompTpfa(const UnstructuredGrid& g,
const double* permeability,
const double* gravity,
const LinearSolverInterface& linsolver,
LinearSolverInterface& linsolver,
const struct Wells* wells)
: grid_(g),
linsolver_(linsolver),
@ -294,6 +294,16 @@ namespace Opm
}
void IncompTpfa::setTolerance(const double tol)
{
linsolver_.setTolerance(tol);
}
double IncompTpfa::getTolerance() const {
return linsolver_.getTolerance();
}
void IncompTpfa::computeFaceFlux(const std::vector<double>& totmob,
const std::vector<double>& omega,
const std::vector<double>& src,
@ -327,7 +337,7 @@ namespace Opm
if (! wdp.empty()) { F.wdp = &wdp[0]; }
ifs_tpfa_assemble(gg, &F, &trans_[0], &gpress_omegaweighted_[0], h_);
faceflux.resize(grid_.number_of_faces);
ifs_tpfa_solution soln = { NULL, NULL, NULL, NULL };

View File

@ -56,7 +56,7 @@ namespace Opm
IncompTpfa(const UnstructuredGrid& g,
const double* permeability,
const double* gravity,
const LinearSolverInterface& linsolver,
LinearSolverInterface& linsolver,
const struct Wells* wells = 0);
/// Destructor.
@ -155,9 +155,18 @@ namespace Opm
/// Expose read-only reference to internal half-transmissibility.
const ::std::vector<double>& getHalfTrans() const { return htrans_; }
/// Set tolerance for the linear solver.
/// \param[in] tol tolerance value
void setTolerance(const double tol);
/// Get tolerance of the linear solver.
/// \param[out] tolerance value
double getTolerance() const;
private:
const UnstructuredGrid& grid_;
const LinearSolverInterface& linsolver_;
LinearSolverInterface& linsolver_;
::std::vector<double> htrans_;
::std::vector<double> trans_ ;
::std::vector<double> gpress_;