From a950a5c7328988b17ee37e70060468e755547474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 13 Apr 2012 14:09:20 +0200 Subject: [PATCH 1/5] well_controls_append(): Use C comment delimiters in C. --- opm/core/utility/newwells.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/core/utility/newwells.c b/opm/core/utility/newwells.c index aed506b93..bac7cc259 100644 --- a/opm/core/utility/newwells.c +++ b/opm/core/utility/newwells.c @@ -408,7 +408,7 @@ well_controls_append(enum control_type type , ctrl->num += 1; - // TODO: Review this: + /* TODO: Review this: */ ctrl->current = 0; } From 709b8c0b8200763feb5b5174a7052cef50040cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 13 Apr 2012 15:37:11 +0200 Subject: [PATCH 2/5] Work around mismatch between our HAVE_BOOST and what dune-istl expects. In our config.h, HAVE_BOOST is defined (empty). In dune-istl it is expected to be defined to 0 or 1. --- opm/core/linalg/LinearSolverIstl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opm/core/linalg/LinearSolverIstl.cpp b/opm/core/linalg/LinearSolverIstl.cpp index 969d83c78..33f06b190 100644 --- a/opm/core/linalg/LinearSolverIstl.cpp +++ b/opm/core/linalg/LinearSolverIstl.cpp @@ -24,9 +24,13 @@ #include +// Work around the fact that istl headers expect +// HAVE_BOOST to be 1, and not just defined. +#undef HAVE_BOOST +#define HAVE_BOOST 1 // TODO: clean up includes. -#define DUNE_DEPRECATED +#include #include #include #include From 588060d1e6868ddcfcfd9109ab56d018ca36be95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 13 Apr 2012 15:46:15 +0200 Subject: [PATCH 3/5] Use C comments in C code. --- opm/core/utility/newwells.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/core/utility/newwells.c b/opm/core/utility/newwells.c index aed506b93..bac7cc259 100644 --- a/opm/core/utility/newwells.c +++ b/opm/core/utility/newwells.c @@ -408,7 +408,7 @@ well_controls_append(enum control_type type , ctrl->num += 1; - // TODO: Review this: + /* TODO: Review this: */ ctrl->current = 0; } From 8c5816586228e58f95eb0cc0cb2e66e877141240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 13 Apr 2012 16:33:51 +0200 Subject: [PATCH 4/5] Added LinearSolverFactory class. --- opm/core/linalg/LinearSolverFactory.cpp | 100 ++++++++++++++++++++++++ opm/core/linalg/LinearSolverFactory.hpp | 86 ++++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 opm/core/linalg/LinearSolverFactory.cpp create mode 100644 opm/core/linalg/LinearSolverFactory.hpp diff --git a/opm/core/linalg/LinearSolverFactory.cpp b/opm/core/linalg/LinearSolverFactory.cpp new file mode 100644 index 000000000..07b4a6cf1 --- /dev/null +++ b/opm/core/linalg/LinearSolverFactory.cpp @@ -0,0 +1,100 @@ +/* + Copyright 2012 SINTEF ICT, Applied Mathematics. + + 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 . +*/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#if HAVE_SUITESPARSE_UMFPACK_H +#include +#endif + +#if HAVE_DUNE_ISTL +#include +#endif + +#include +#include +#include + + +namespace Opm +{ + + LinearSolverFactory::LinearSolverFactory() + { +#if HAVE_SUITESPARSE_UMFPACK_H + solver_.reset(new LinearSolverUmfpack); +#elif HAVE_DUNE_ISTL + solver_.reset(new LinearSolverIstl); +#else + THROW("No linear solver available, you must have UMFPACK or dune-istl installed to use LinearSolverFactory."); +#endif + } + + + + + LinearSolverFactory::LinearSolverFactory(const parameter::ParameterGroup& param) + { + const std::string ls = param.getDefault("linsolver", "umfpack"); + if (ls == "umfpack") { +#if HAVE_SUITESPARSE_UMFPACK_H + solver_.reset(new LinearSolverUmfpack); +#else + THROW("Linear solver " << ls <<" is not available."); +#endif + } else if (ls == "istl") { +#if HAVE_DUNE_ISTL + solver_.reset(new LinearSolverIstl(param)); +#else + THROW("Linear solver " << ls <<" is not available."); +#endif + } + } + + + + + LinearSolverFactory::~LinearSolverFactory() + { + } + + + + + LinearSolverInterface::LinearSolverReport + LinearSolverFactory::solve(const int size, + const int nonzeros, + const int* ia, + const int* ja, + const double* sa, + const double* rhs, + double* solution) const + { + return solver_->solve(size, nonzeros, ia, ja, sa, rhs, solution); + } + + + + +} // namespace Opm + diff --git a/opm/core/linalg/LinearSolverFactory.hpp b/opm/core/linalg/LinearSolverFactory.hpp new file mode 100644 index 000000000..ad5377cf3 --- /dev/null +++ b/opm/core/linalg/LinearSolverFactory.hpp @@ -0,0 +1,86 @@ +/* + Copyright 2012 SINTEF ICT, Applied Mathematics. + + 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 . +*/ + +#ifndef OPM_LINEARSOLVERFACTORY_HEADER_INCLUDED +#define OPM_LINEARSOLVERFACTORY_HEADER_INCLUDED + + +#include +#include + +namespace Opm +{ + + namespace parameter { class ParameterGroup; } + + + /// Concrete class encapsulating any available linear solver. + /// For the moment, this means UMFPACK and dune-istl. + /// Since both are optional dependencies, either or both + /// may be unavailable, depending on configuration. + class LinearSolverFactory : public LinearSolverInterface + { + public: + /// Default constructor. + LinearSolverFactory(); + + /// Construct from parameters. + /// The accepted parameters are (default) (allowed values): + /// linsolver ("umfpack") ("umfpack", "istl") + /// For the umfpack solver to be available, this class must be + /// compiled with UMFPACK support, as indicated by the + /// variable HAVE_SUITESPARSE_UMFPACK_H in config.h. + /// For the istl solver to be available, this class must be + /// compiled with dune-istl support, as indicated by the + /// variable HAVE_DUNE_ISTL in config.h. + /// Any further parameters are passed on to the constructors + /// of the actual solver used, see LinearSolverUmfpack + /// and LinearSolverIstl for details. + LinearSolverFactory(const parameter::ParameterGroup& param); + + /// Destructor. + virtual ~LinearSolverFactory(); + + using LinearSolverInterface::solve; + + /// Solve a linear system, with a matrix given in compressed sparse row format. + /// \param[in] size # of rows in matrix + /// \param[in] nonzeros # of nonzeros elements in matrix + /// \param[in] ia array of length (size + 1) containing start and end indices for each row + /// \param[in] ja array of length nonzeros containing column numbers for the nonzero elements + /// \param[in] sa array of length nonzeros containing the values of the nonzero elements + /// \param[in] rhs array of length size containing the right hand side + /// \param[inout] solution array of length size to which the solution will be written, may also be used + /// as initial guess by iterative solvers. + virtual LinearSolverReport solve(const int size, + const int nonzeros, + const int* ia, + const int* ja, + const double* sa, + const double* rhs, + double* solution) const; + private: + std::tr1::shared_ptr solver_; + }; + + +} // namespace Opm + + +#endif // OPM_LINEARSOLVERFACTORY_HEADER_INCLUDED From 231333984469ab9caea6753d535769c55445a980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 13 Apr 2012 16:36:51 +0200 Subject: [PATCH 5/5] Fix bug: mistakenly swapped macros. --- opm/core/linalg/LinearSolverFactory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/core/linalg/LinearSolverFactory.cpp b/opm/core/linalg/LinearSolverFactory.cpp index 07b4a6cf1..9ba1e1388 100644 --- a/opm/core/linalg/LinearSolverFactory.cpp +++ b/opm/core/linalg/LinearSolverFactory.cpp @@ -24,11 +24,11 @@ #include #if HAVE_SUITESPARSE_UMFPACK_H -#include +#include #endif #if HAVE_DUNE_ISTL -#include +#include #endif #include