From 427eac5132b22b2035e35191c01fc476b4f22f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Fri, 19 Jun 2020 16:37:43 +0200 Subject: [PATCH] Use macro for instantiations, and clean up includes. --- opm/simulators/linalg/FlexibleSolver.hpp | 6 +--- opm/simulators/linalg/FlexibleSolver1.cpp | 34 +------------------ opm/simulators/linalg/FlexibleSolver2.cpp | 34 +------------------ opm/simulators/linalg/FlexibleSolver3.cpp | 34 +------------------ opm/simulators/linalg/FlexibleSolver4.cpp | 34 +------------------ opm/simulators/linalg/FlexibleSolver_impl.hpp | 34 +++++++++++++++++++ tests/test_flexiblesolver.cpp | 4 +++ 7 files changed, 43 insertions(+), 137 deletions(-) diff --git a/opm/simulators/linalg/FlexibleSolver.hpp b/opm/simulators/linalg/FlexibleSolver.hpp index 5c2c68a53..826611302 100644 --- a/opm/simulators/linalg/FlexibleSolver.hpp +++ b/opm/simulators/linalg/FlexibleSolver.hpp @@ -24,11 +24,7 @@ #include -#include -#include -#include -#include -#include +#include #include #include diff --git a/opm/simulators/linalg/FlexibleSolver1.cpp b/opm/simulators/linalg/FlexibleSolver1.cpp index 8ca3b5c05..51e04c492 100644 --- a/opm/simulators/linalg/FlexibleSolver1.cpp +++ b/opm/simulators/linalg/FlexibleSolver1.cpp @@ -20,37 +20,5 @@ #include "config.h" #include -#include -#include -#include -#include -#include -#include -#include - -// Explicit instantiations of FlexibleSolver - -template -using BV = Dune::BlockVector>; -template -using BM = Dune::BCRSMatrix>; -template -using OBM = Dune::BCRSMatrix>; - -// Variants using Dune::FieldMatrix blocks. -template class Dune::FlexibleSolver, BV<1>>; - -// Variants using Opm::MatrixBlock blocks. -template class Dune::FlexibleSolver, BV<1>>; - -#if HAVE_MPI - -using Comm = Dune::OwnerOverlapCopyCommunication; - -template Dune::FlexibleSolver, BV<1>>::FlexibleSolver(const MatrixType& matrix, - const Comm& comm, - const boost::property_tree::ptree& prm, - const std::function()>& weightsCalculator); - -#endif // HAVE_MPI +INSTANTIATE_FLEXIBLESOLVER(1); diff --git a/opm/simulators/linalg/FlexibleSolver2.cpp b/opm/simulators/linalg/FlexibleSolver2.cpp index bed962a65..00511eefd 100644 --- a/opm/simulators/linalg/FlexibleSolver2.cpp +++ b/opm/simulators/linalg/FlexibleSolver2.cpp @@ -20,37 +20,5 @@ #include "config.h" #include -#include -#include -#include -#include -#include -#include -#include - -// Explicit instantiations of FlexibleSolver - -template -using BV = Dune::BlockVector>; -template -using BM = Dune::BCRSMatrix>; -template -using OBM = Dune::BCRSMatrix>; - -// Variants using Dune::FieldMatrix blocks. -template class Dune::FlexibleSolver, BV<2>>; - -// Variants using Opm::MatrixBlock blocks. -template class Dune::FlexibleSolver, BV<2>>; - -#if HAVE_MPI - -using Comm = Dune::OwnerOverlapCopyCommunication; - -template Dune::FlexibleSolver, BV<2>>::FlexibleSolver(const MatrixType& matrix, - const Comm& comm, - const boost::property_tree::ptree& prm, - const std::function()>& weightsCalculator); - -#endif // HAVE_MPI +INSTANTIATE_FLEXIBLESOLVER(2); diff --git a/opm/simulators/linalg/FlexibleSolver3.cpp b/opm/simulators/linalg/FlexibleSolver3.cpp index 8e5a37c7c..5ccdd7749 100644 --- a/opm/simulators/linalg/FlexibleSolver3.cpp +++ b/opm/simulators/linalg/FlexibleSolver3.cpp @@ -20,37 +20,5 @@ #include "config.h" #include -#include -#include -#include -#include -#include -#include -#include - -// Explicit instantiations of FlexibleSolver - -template -using BV = Dune::BlockVector>; -template -using BM = Dune::BCRSMatrix>; -template -using OBM = Dune::BCRSMatrix>; - -// Variants using Dune::FieldMatrix blocks. -template class Dune::FlexibleSolver, BV<3>>; - -// Variants using Opm::MatrixBlock blocks. -template class Dune::FlexibleSolver, BV<3>>; - -#if HAVE_MPI - -using Comm = Dune::OwnerOverlapCopyCommunication; - -template Dune::FlexibleSolver, BV<3>>::FlexibleSolver(const MatrixType& matrix, - const Comm& comm, - const boost::property_tree::ptree& prm, - const std::function()>& weightsCalculator); - -#endif // HAVE_MPI +INSTANTIATE_FLEXIBLESOLVER(3); diff --git a/opm/simulators/linalg/FlexibleSolver4.cpp b/opm/simulators/linalg/FlexibleSolver4.cpp index 4d32cc34e..9aed1ae47 100644 --- a/opm/simulators/linalg/FlexibleSolver4.cpp +++ b/opm/simulators/linalg/FlexibleSolver4.cpp @@ -20,37 +20,5 @@ #include "config.h" #include -#include -#include -#include -#include -#include -#include -#include - -// Explicit instantiations of FlexibleSolver - -template -using BV = Dune::BlockVector>; -template -using BM = Dune::BCRSMatrix>; -template -using OBM = Dune::BCRSMatrix>; - -// Variants using Dune::FieldMatrix blocks. -template class Dune::FlexibleSolver, BV<4>>; - -// Variants using Opm::MatrixBlock blocks. -template class Dune::FlexibleSolver, BV<4>>; - -#if HAVE_MPI - -using Comm = Dune::OwnerOverlapCopyCommunication; - -template Dune::FlexibleSolver, BV<4>>::FlexibleSolver(const MatrixType& matrix, - const Comm& comm, - const boost::property_tree::ptree& prm, - const std::function()>& weightsCalculator); - -#endif // HAVE_MPI +INSTANTIATE_FLEXIBLESOLVER(4); diff --git a/opm/simulators/linalg/FlexibleSolver_impl.hpp b/opm/simulators/linalg/FlexibleSolver_impl.hpp index 9d770c407..8394bd055 100644 --- a/opm/simulators/linalg/FlexibleSolver_impl.hpp +++ b/opm/simulators/linalg/FlexibleSolver_impl.hpp @@ -188,4 +188,38 @@ namespace Dune } // namespace Dune + +// Macros to simplify explicit instantiation of FlexibleSolver for various block sizes. + +template +using BV = Dune::BlockVector>; +template +using BM = Dune::BCRSMatrix>; +template +using OBM = Dune::BCRSMatrix>; + +// INSTANTIATE_CONSTRUCTOR instantiates the constructor that is a template, +// this is only needed in the MPI case, since otherwise the Comm type is +// not a template argument but always SequentialInformation. +#if HAVE_MPI +using Comm = Dune::OwnerOverlapCopyCommunication; +#define INSTANTIATE_FLEXIBLESOLVER_CONSTRUCTOR(n) \ +template Dune::FlexibleSolver, BV>::FlexibleSolver(const MatrixType& matrix, \ + const Comm& comm, \ + const boost::property_tree::ptree& prm, \ + const std::function()>& weightsCalculator); +#else +#define INSTANTIATE_FLEXIBLESOLVER_CONSTRUCTOR(n) +#endif + +// INSTANTIATE instantiates the class including any templated constructors if necessary. +#define INSTANTIATE_FLEXIBLESOLVER(n) \ +/* Variants using Dune::FieldMatrix blocks. */ \ +template class Dune::FlexibleSolver, BV>; \ +/* Variants using Opm::MatrixBlock blocks. */ \ +template class Dune::FlexibleSolver, BV>; \ +INSTANTIATE_FLEXIBLESOLVER_CONSTRUCTOR(n) + + + #endif // OPM_FLEXIBLE_SOLVER_IMPL_HEADER_INCLUDED diff --git a/tests/test_flexiblesolver.cpp b/tests/test_flexiblesolver.cpp index 615ffa9dd..215795daf 100644 --- a/tests/test_flexiblesolver.cpp +++ b/tests/test_flexiblesolver.cpp @@ -31,6 +31,10 @@ #include #include +#include +#include +#include + #include #include #include