From d28b75174218381de9e050bd29013ee563055586 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 01/19] BlackoilModelParameters: optionally instantiate for float --- opm/simulators/flow/BlackoilModelParameters.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opm/simulators/flow/BlackoilModelParameters.cpp b/opm/simulators/flow/BlackoilModelParameters.cpp index 9cc190b82..e15343d5f 100644 --- a/opm/simulators/flow/BlackoilModelParameters.cpp +++ b/opm/simulators/flow/BlackoilModelParameters.cpp @@ -224,4 +224,8 @@ void BlackoilModelParameters::registerParameters() template struct BlackoilModelParameters; +#if FLOW_INSTANTIATE_FLOAT +template struct BlackoilModelParameters; +#endif + } // namespace Opm From 42b8545e51010712cd6c56e24d1a01d44e5a91a1 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Sat, 13 Apr 2024 15:18:32 +0200 Subject: [PATCH 02/19] MSWellhelpers: disable for float Scalar there is no UMFPack for floats --- opm/simulators/wells/MSWellHelpers.cpp | 47 +++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/opm/simulators/wells/MSWellHelpers.cpp b/opm/simulators/wells/MSWellHelpers.cpp index 919014c81..b49be1cb2 100644 --- a/opm/simulators/wells/MSWellHelpers.cpp +++ b/opm/simulators/wells/MSWellHelpers.cpp @@ -110,18 +110,21 @@ applyUMFPack(Dune::UMFPack& linsolver, // Object storing some statistics about the solving process Dune::InverseOperatorResult res; + if constexpr (std::is_same_v) { + OPM_THROW(std::runtime_error, "Cannot use applyUMFPack() with floats."); + } else { + // Solve + linsolver.apply(y, x, res); - // Solve - linsolver.apply(y, x, res); - - // Checking if there is any inf or nan in y - // it will be the solution before we find a way to catch the singularity of the matrix - for (std::size_t i_block = 0; i_block < y.size(); ++i_block) { - for (std::size_t i_elem = 0; i_elem < y[i_block].size(); ++i_elem) { - if (std::isinf(y[i_block][i_elem]) || std::isnan(y[i_block][i_elem]) ) { - const std::string msg{"nan or inf value found after UMFPack solve due to singular matrix"}; - OpmLog::debug(msg); - OPM_THROW_NOLOG(NumericalProblem, msg); + // Checking if there is any inf or nan in y + // it will be the solution before we find a way to catch the singularity of the matrix + for (std::size_t i_block = 0; i_block < y.size(); ++i_block) { + for (std::size_t i_elem = 0; i_elem < y[i_block].size(); ++i_elem) { + if (std::isinf(y[i_block][i_elem]) || std::isnan(y[i_block][i_elem]) ) { + const std::string msg{"nan or inf value found after UMFPack solve due to singular matrix"}; + OpmLog::debug(msg); + OPM_THROW_NOLOG(NumericalProblem, msg); + } } } } @@ -146,17 +149,21 @@ invertWithUMFPack(const int size, // Make a full block matrix. Dune::Matrix inv(size, size); - // Create inverse by passing basis vectors to the solver. - for (int ii = 0; ii < size; ++ii) { - for (int jj = 0; jj < bsize; ++jj) { - e[ii][jj] = 1.0; - auto col = applyUMFPack(linsolver, e); - for (int cc = 0; cc < size; ++cc) { - for (int dd = 0; dd < bsize; ++dd) { - inv[cc][ii][dd][jj] = col[cc][dd]; + if constexpr (std::is_same_v) { + OPM_THROW(std::runtime_error, "Cannot use invertWithUMFPack() with floats."); + } else { + // Create inverse by passing basis vectors to the solver. + for (int ii = 0; ii < size; ++ii) { + for (int jj = 0; jj < bsize; ++jj) { + e[ii][jj] = 1.0; + auto col = applyUMFPack(linsolver, e); + for (int cc = 0; cc < size; ++cc) { + for (int dd = 0; dd < bsize; ++dd) { + inv[cc][ii][dd][jj] = col[cc][dd]; + } } + e[ii][jj] = 0.0; } - e[ii][jj] = 0.0; } } From 39971162a3a04ac9946ce1174c847659a0faa07c Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 03/19] MSWellHelpers: optionally instantiate for float --- opm/simulators/wells/MSWellHelpers.cpp | 89 ++++++++++++++------------ 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/opm/simulators/wells/MSWellHelpers.cpp b/opm/simulators/wells/MSWellHelpers.cpp index b49be1cb2..0be7e0e69 100644 --- a/opm/simulators/wells/MSWellHelpers.cpp +++ b/opm/simulators/wells/MSWellHelpers.cpp @@ -306,52 +306,59 @@ ValueType emulsionViscosity(const ValueType& water_fraction, } } -template -using Vec = Dune::BlockVector>; -template -using Mat = Dune::BCRSMatrix>; +template +using Vec = Dune::BlockVector>; +template +using Mat = Dune::BCRSMatrix>; -#define INSTANCE_UMF(Dim) \ - template Vec applyUMFPack,Vec>(Dune::UMFPack>&, \ - Vec); \ - template Dune::Matrix::block_type> \ - invertWithUMFPack,Mat>(const int, const int, Dune::UMFPack>&); +#define INSTANTIATE_UMF(T,Dim) \ + template Vec applyUMFPack(Dune::UMFPack>&, \ + Vec); \ + template Dune::Matrix::block_type> \ + invertWithUMFPack,Mat>(const int, const int, \ + Dune::UMFPack>&); -INSTANCE_UMF(2) -INSTANCE_UMF(3) -INSTANCE_UMF(4) - -#define INSTANCE_IMPL(T,...) \ - template __VA_ARGS__ \ - frictionPressureLoss(const T, \ - const T, \ - const T, \ - const T, \ - const __VA_ARGS__&, \ - const __VA_ARGS__&, \ - const __VA_ARGS__&); \ - template __VA_ARGS__ \ - valveContrictionPressureLoss(const __VA_ARGS__& mass_rate, \ - const __VA_ARGS__& density, \ - const T, const T); \ - template __VA_ARGS__ \ +#define INSTANTIATE_IMPL(T,...) \ + template __VA_ARGS__ \ + frictionPressureLoss(const T, \ + const T, \ + const T, \ + const T, \ + const __VA_ARGS__&, \ + const __VA_ARGS__&, \ + const __VA_ARGS__&); \ + template __VA_ARGS__ \ + valveContrictionPressureLoss(const __VA_ARGS__& mass_rate, \ + const __VA_ARGS__& density, \ + const T, const T); \ + template __VA_ARGS__ \ velocityHead(const T, const __VA_ARGS__&, const __VA_ARGS__&); \ - template __VA_ARGS__ \ - emulsionViscosity<__VA_ARGS__,T>(const __VA_ARGS__&, \ - const __VA_ARGS__&, \ - const __VA_ARGS__&, \ - const __VA_ARGS__&, \ + template __VA_ARGS__ \ + emulsionViscosity<__VA_ARGS__,T>(const __VA_ARGS__&, \ + const __VA_ARGS__&, \ + const __VA_ARGS__&, \ + const __VA_ARGS__&, \ const SICD&); -#define INSTANCE_EVAL(Dim) \ - INSTANCE_IMPL(double, DenseAd::Evaluation) +#define INSTANTIATE_EVAL(T,Dim) \ + INSTANTIATE_IMPL(T, DenseAd::Evaluation) -INSTANCE_EVAL(3) -INSTANCE_EVAL(4) -INSTANCE_EVAL(5) -INSTANCE_EVAL(6) -INSTANCE_EVAL(7) -INSTANCE_EVAL(8) -INSTANCE_EVAL(9) +#define INSTANTIATE_TYPE(T) \ + INSTANTIATE_UMF(T,2) \ + INSTANTIATE_UMF(T,3) \ + INSTANTIATE_UMF(T,4) \ + INSTANTIATE_EVAL(T,3) \ + INSTANTIATE_EVAL(T,4) \ + INSTANTIATE_EVAL(T,5) \ + INSTANTIATE_EVAL(T,6) \ + INSTANTIATE_EVAL(T,7) \ + INSTANTIATE_EVAL(T,8) \ + INSTANTIATE_EVAL(T,9) + +INSTANTIATE_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } // namespace Opm::mswellhelpers From e4e6430644d55b1379b72ea139bb9ee270c9d4ec Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 04/19] MultisegmentWellSegments: optionally instantiate for float --- .../wells/MultisegmentWellSegments.cpp | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/opm/simulators/wells/MultisegmentWellSegments.cpp b/opm/simulators/wells/MultisegmentWellSegments.cpp index c38de130f..5f1ba95fa 100644 --- a/opm/simulators/wells/MultisegmentWellSegments.cpp +++ b/opm/simulators/wells/MultisegmentWellSegments.cpp @@ -987,39 +987,43 @@ mixtureDensityWithExponents(const AutoICD& aicd, const int seg) const return mixDens; } -#define INSTANCE(...) \ -template class MultisegmentWellSegments,__VA_ARGS__>; +template +using FS = BlackOilFluidSystem; -// One phase -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,5u>) +#define INSTANTIATE(T,...) \ + template class MultisegmentWellSegments,__VA_ARGS__>; -// Two phase -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,2u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,true,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<1u,0u,0u,0u,false,false,0u,0u,0u>) +#define INSTANTIATE_TYPE(T) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,5u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,2u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,true,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<1u,0u,0u,0u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,true,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,true,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,true,2u,0u>) \ + INSTANTIATE(T,BlackOilIndices<1u,0u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,1u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,1u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,1u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,false,1u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,1u,false,true,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<1u,0u,0u,0u,true,false,0u,0u>) -// Blackoil -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,true,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,true,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,true,2u,0u>) -INSTANCE(BlackOilIndices<1u,0u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,1u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,1u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,1u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,false,1u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,1u,false,true,0u,0u>) +INSTANTIATE_TYPE(double) -INSTANCE(BlackOilIndices<1u,0u,0u,0u,true,false,0u,0u>) +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } // namespace Opm From fa84eb65c7938b1188bb036d077bf8ca2ea530a4 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 16 Apr 2024 13:02:53 +0200 Subject: [PATCH 05/19] MultisegmentWellEquations: throw with float Scalar UMFPack cannot handle floats --- .../wells/MultisegmentWellEquations.cpp | 87 +++++++++++-------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/opm/simulators/wells/MultisegmentWellEquations.cpp b/opm/simulators/wells/MultisegmentWellEquations.cpp index 39ebe5c79..78448eb9a 100644 --- a/opm/simulators/wells/MultisegmentWellEquations.cpp +++ b/opm/simulators/wells/MultisegmentWellEquations.cpp @@ -20,11 +20,13 @@ */ #include -#include - #include + #include +#include +#include + #include #if COMPILE_BDA_BRIDGE @@ -167,7 +169,12 @@ void MultisegmentWellEquations::createSolver() return; } - duneDSolver_ = std::make_shared>(duneD_, 0); + if constexpr (std::is_same_v) { + OPM_THROW(std::runtime_error, "MultisegmentWell support requires UMFPACK, " + "and UMFPACK does not support float"); + } else { + duneDSolver_ = std::make_shared>(duneD_, 0); + } #else OPM_THROW(std::runtime_error, "MultisegmentWell support requires UMFPACK. " "Reconfigure opm-simulators with SuiteSparse/UMFPACK support and recompile."); @@ -225,46 +232,50 @@ extract(WellContributions& wellContribs) const } // duneD - Dune::UMFPack umfpackMatrix(duneD_, 0); - double* Dvals = umfpackMatrix.getInternalMatrix().getValues(); - auto* Dcols = umfpackMatrix.getInternalMatrix().getColStart(); - auto* Drows = umfpackMatrix.getInternalMatrix().getRowIndex(); + if constexpr (std::is_same_v) { + OPM_THROW(std::runtime_error, "Cannot use UMFPack with floats"); + } else { + Dune::UMFPack umfpackMatrix(duneD_, 0); + double* Dvals = umfpackMatrix.getInternalMatrix().getValues(); + auto* Dcols = umfpackMatrix.getInternalMatrix().getColStart(); + auto* Drows = umfpackMatrix.getInternalMatrix().getRowIndex(); - // duneB - std::vector Bcols; - std::vector Brows; - std::vector Bvals; - Bcols.reserve(BnumBlocks); - Brows.reserve(Mb+1); - Bvals.reserve(BnumBlocks * numEq * numWellEq); - Brows.emplace_back(0); - unsigned int sumBlocks = 0; - for (auto rowB = duneB_.begin(); rowB != duneB_.end(); ++rowB) { - int sizeRow = 0; - for (auto colB = rowB->begin(), endB = rowB->end(); colB != endB; ++colB) { - Bcols.emplace_back(colB.index()); - for (int i = 0; i < numWellEq; ++i) { - for (int j = 0; j < numEq; ++j) { - Bvals.emplace_back((*colB)[i][j]); + // duneB + std::vector Bcols; + std::vector Brows; + std::vector Bvals; + Bcols.reserve(BnumBlocks); + Brows.reserve(Mb+1); + Bvals.reserve(BnumBlocks * numEq * numWellEq); + Brows.emplace_back(0); + unsigned int sumBlocks = 0; + for (auto rowB = duneB_.begin(); rowB != duneB_.end(); ++rowB) { + int sizeRow = 0; + for (auto colB = rowB->begin(), endB = rowB->end(); colB != endB; ++colB) { + Bcols.emplace_back(colB.index()); + for (int i = 0; i < numWellEq; ++i) { + for (int j = 0; j < numEq; ++j) { + Bvals.emplace_back((*colB)[i][j]); + } } + sizeRow++; } - sizeRow++; + sumBlocks += sizeRow; + Brows.emplace_back(sumBlocks); } - sumBlocks += sizeRow; - Brows.emplace_back(sumBlocks); - } - wellContribs.addMultisegmentWellContribution(numEq, - numWellEq, - Mb, - Bvals, - Bcols, - Brows, - DnumBlocks, - Dvals, - Dcols, - Drows, - Cvals); + wellContribs.addMultisegmentWellContribution(numEq, + numWellEq, + Mb, + Bvals, + Bcols, + Brows, + DnumBlocks, + Dvals, + Dcols, + Drows, + Cvals); + } } #endif From 6f7660905e21f917e6d0b985729c88ba05bf578b Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 06/19] MultisegmentWellEquations: optionally instantiate for float --- .../wells/MultisegmentWellEquations.cpp | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/opm/simulators/wells/MultisegmentWellEquations.cpp b/opm/simulators/wells/MultisegmentWellEquations.cpp index 78448eb9a..596ca1277 100644 --- a/opm/simulators/wells/MultisegmentWellEquations.cpp +++ b/opm/simulators/wells/MultisegmentWellEquations.cpp @@ -397,27 +397,34 @@ extractCPRPressureMatrix(PressureMatrix& jacobian, } } -#define INSTANCE(numWellEq, numEq) \ -template class MultisegmentWellEquations; \ -template void MultisegmentWellEquations:: \ - extract(Linear::IstlSparseMatrixAdapter>&) const; \ -template void MultisegmentWellEquations:: \ - extractCPRPressureMatrix(Dune::BCRSMatrix>&, \ - const MultisegmentWellEquations::BVector&, \ - const int, \ - const bool, \ - const WellInterfaceGeneric&, \ - const int, \ - const WellState&) const; +#define INSTANTIATE(T, numWellEq, numEq) \ + template class MultisegmentWellEquations; \ + template void MultisegmentWellEquations:: \ + extract(Linear::IstlSparseMatrixAdapter>&) const; \ + template void MultisegmentWellEquations:: \ + extractCPRPressureMatrix(Dune::BCRSMatrix>&, \ + const MultisegmentWellEquations::BVector&, \ + const int, \ + const bool, \ + const WellInterfaceGeneric&, \ + const int, \ + const WellState&) const; -INSTANCE(2,1) -INSTANCE(2,2) -INSTANCE(2,6) -INSTANCE(3,2) -INSTANCE(3,3) -INSTANCE(3,4) -INSTANCE(4,3) -INSTANCE(4,4) -INSTANCE(4,5) +#define INSTANTIATE_TYPE(T) \ + INSTANTIATE(T,2,1) \ + INSTANTIATE(T,2,2) \ + INSTANTIATE(T,2,6) \ + INSTANTIATE(T,3,2) \ + INSTANTIATE(T,3,3) \ + INSTANTIATE(T,3,4) \ + INSTANTIATE(T,4,3) \ + INSTANTIATE(T,4,4) \ + INSTANTIATE(T,4,5) + +INSTANTIATE_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } From 6f040331421b9787333c8e01db2803a1630b9e19 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 07/19] MultisegmentWellEval: optionally instantiate for float --- opm/simulators/wells/MultisegmentWellEval.cpp | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/opm/simulators/wells/MultisegmentWellEval.cpp b/opm/simulators/wells/MultisegmentWellEval.cpp index ecfa1aa12..367a68a3e 100644 --- a/opm/simulators/wells/MultisegmentWellEval.cpp +++ b/opm/simulators/wells/MultisegmentWellEval.cpp @@ -577,38 +577,43 @@ getResidualMeasureValue(const WellState& well_state, return sum; } -#define INSTANCE(...) \ -template class MultisegmentWellEval,__VA_ARGS__>; +template +using FS = BlackOilFluidSystem; -// One phase -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,5u>) +#define INSTANTIATE(T,...) \ + template class MultisegmentWellEval,__VA_ARGS__>; -// Two phase -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,2u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,true,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<1u,0u,0u,0u,false,false,0u,0u,0u>) +#define INSTANTIATE_TYPE(T) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,5u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,2u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,true,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<1u,0u,0u,0u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,true,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,true,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,true,2u,0u>) \ + INSTANTIATE(T,BlackOilIndices<1u,0u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,1u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,1u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,1u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,false,1u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,1u,false,true,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<1u,0u,0u,0u,true,false,0u,0u>) -// Blackoil -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,true,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,true,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,true,2u,0u>) -INSTANCE(BlackOilIndices<1u,0u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,1u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,1u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,1u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,false,1u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,1u,false,true,0u,0u>) -INSTANCE(BlackOilIndices<1u,0u,0u,0u,true,false,0u,0u>) +INSTANTIATE_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } // namespace Opm From b507c75e7529b20d5d6eaa6f4b11a630c7022d51 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 16 Apr 2024 13:08:36 +0200 Subject: [PATCH 08/19] MultisegmentWellContribution: disable with float Scalars --- .../bda/MultisegmentWellContribution.cpp | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp b/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp index 9bef05439..5c18543e0 100644 --- a/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp +++ b/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp @@ -17,17 +17,17 @@ along with OPM. If not, see . */ - #include // CMake +#include + +#include #include + #if HAVE_UMFPACK #include #endif // HAVE_UMFPACK -#include - -namespace Opm -{ +namespace Opm { template MultisegmentWellContribution:: @@ -59,15 +59,21 @@ MultisegmentWellContribution(unsigned int dim_, unsigned int dim_wells_, z1.resize(Mb * dim_wells); z2.resize(Mb * dim_wells); - umfpack_di_symbolic(M, M, Dcols.data(), Drows.data(), Dvals.data(), &UMFPACK_Symbolic, nullptr, nullptr); - umfpack_di_numeric(Dcols.data(), Drows.data(), Dvals.data(), UMFPACK_Symbolic, &UMFPACK_Numeric, nullptr, nullptr); + if constexpr (std::is_same_v) { + OPM_THROW(std::runtime_error, "Cannot use multisegment wells with float"); + } else { + umfpack_di_symbolic(M, M, Dcols.data(), Drows.data(), Dvals.data(), &UMFPACK_Symbolic, nullptr, nullptr); + umfpack_di_numeric(Dcols.data(), Drows.data(), Dvals.data(), UMFPACK_Symbolic, &UMFPACK_Numeric, nullptr, nullptr); + } } template MultisegmentWellContribution::~MultisegmentWellContribution() { - umfpack_di_free_symbolic(&UMFPACK_Symbolic); - umfpack_di_free_numeric(&UMFPACK_Numeric); + if constexpr (std::is_same_v) { + umfpack_di_free_symbolic(&UMFPACK_Symbolic); + umfpack_di_free_numeric(&UMFPACK_Numeric); + } } // Apply the MultisegmentWellContribution, similar to MultisegmentWell::apply() @@ -98,7 +104,11 @@ void MultisegmentWellContribution::apply(Scalar* h_x, Scalar* h_y) // z2 = D^-1 * (B * x) // umfpack - umfpack_di_solve(UMFPACK_A, Dcols.data(), Drows.data(), Dvals.data(), z2.data(), z1.data(), UMFPACK_Numeric, nullptr, nullptr); + if constexpr (std::is_same_v) { + OPM_THROW(std::runtime_error, "Cannot use multisegment wells with float"); + } else { + umfpack_di_solve(UMFPACK_A, Dcols.data(), Drows.data(), Dvals.data(), z2.data(), z1.data(), UMFPACK_Numeric, nullptr, nullptr); + } // y -= (C^T * z2) // y -= (C^T * (D^-1 * (B * x))) From df0a9a405599bc233490808edff980de68d1d013 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 16 Apr 2024 13:08:56 +0200 Subject: [PATCH 09/19] MultisegmentWellContribution: optionally instantiate for float --- opm/simulators/linalg/bda/MultisegmentWellContribution.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp b/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp index 5c18543e0..1d4dfd109 100644 --- a/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp +++ b/opm/simulators/linalg/bda/MultisegmentWellContribution.cpp @@ -137,5 +137,9 @@ void MultisegmentWellContribution::setCudaStream(cudaStream_t stream_) template class MultisegmentWellContribution; +#if FLOW_INSTANTIATE_FLOAT +template class MultisegmentWellContribution; +#endif + } //namespace Opm From 9f5bad224c1aacf1510317772cefa41f740e3aaf Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 16 Apr 2024 13:13:36 +0200 Subject: [PATCH 10/19] openclKernels: optionally instantiate for float --- opencl-source-provider.cmake | 6 ++++++ opm/simulators/linalg/bda/opencl/openclKernels.cpp | 4 ++++ opm/simulators/linalg/bda/opencl/openclKernels.hpp | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/opencl-source-provider.cmake b/opencl-source-provider.cmake index 7581385b7..fae1f0b5f 100644 --- a/opencl-source-provider.cmake +++ b/opencl-source-provider.cmake @@ -35,6 +35,12 @@ foreach(CL ${CL_LIST}) file(READ "${CL}" CL_CONTENT) file(APPEND ${CL_SRC_FILE} "${CL_CONTENT}") file(APPEND ${CL_SRC_FILE} "\)\"; \n\n") + if(BUILD_FLOW_FLOAT_VARIANTS) + string(REPLACE double float CL_CONTENT "${CL_CONTENT}") + file(APPEND ${CL_SRC_FILE} "template<> const std::string OpenclKernels::${FNAME}_str = R\"\( \n") + file(APPEND ${CL_SRC_FILE} "${CL_CONTENT}") + file(APPEND ${CL_SRC_FILE} "\)\"; \n\n") + endif() if(DEBUG_OPENCL_KERNELS_INTEL) execute_process( diff --git a/opm/simulators/linalg/bda/opencl/openclKernels.cpp b/opm/simulators/linalg/bda/opencl/openclKernels.cpp index 7342a94cc..8b6e74ed4 100644 --- a/opm/simulators/linalg/bda/opencl/openclKernels.cpp +++ b/opm/simulators/linalg/bda/opencl/openclKernels.cpp @@ -561,4 +561,8 @@ void OpenclKernels::isaiU(cl::Buffer& diagIndex, cl::Buffer& colPointers template class OpenclKernels; +#if FLOW_INSTANTIATE_FLOAT +template class OpenclKernels; +#endif + } // namespace Opm::Accelerator diff --git a/opm/simulators/linalg/bda/opencl/openclKernels.hpp b/opm/simulators/linalg/bda/opencl/openclKernels.hpp index 18f898a07..0b3182faa 100644 --- a/opm/simulators/linalg/bda/opencl/openclKernels.hpp +++ b/opm/simulators/linalg/bda/opencl/openclKernels.hpp @@ -182,6 +182,10 @@ public: DECLARE_INSTANCE(double) +#if FLOW_INSTANTIATE_FLOAT +DECLARE_INSTANCE(float) +#endif + } // namespace Opm::Accelerator #endif From a7b99651c148b133bfc0da4eeebbf13e770bf838 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 16 Apr 2024 13:05:13 +0200 Subject: [PATCH 11/19] WellContributions: optionally instantiate for float cuWellContributions: optionally instantiate for float openclWellContributions: optionally instantiate for float rocsparseWellContributions: optionally instantiate for float these need to go in the same commit due to circular dependencies --- opm/simulators/linalg/bda/WellContributions.cpp | 4 ++++ opm/simulators/linalg/bda/cuda/cuWellContributions.cu | 4 ++++ opm/simulators/linalg/bda/opencl/openclWellContributions.cpp | 4 ++++ opm/simulators/linalg/bda/rocm/rocsparseWellContributions.cpp | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/opm/simulators/linalg/bda/WellContributions.cpp b/opm/simulators/linalg/bda/WellContributions.cpp index 1ed177eba..6d19f669a 100644 --- a/opm/simulators/linalg/bda/WellContributions.cpp +++ b/opm/simulators/linalg/bda/WellContributions.cpp @@ -184,4 +184,8 @@ addMultisegmentWellContribution(unsigned int dim_, template class WellContributions; +#if FLOW_INSTANTIATE_FLOAT +template class WellContributions; +#endif + } //namespace Opm diff --git a/opm/simulators/linalg/bda/cuda/cuWellContributions.cu b/opm/simulators/linalg/bda/cuda/cuWellContributions.cu index a0e846af4..e5cb109a1 100644 --- a/opm/simulators/linalg/bda/cuda/cuWellContributions.cu +++ b/opm/simulators/linalg/bda/cuda/cuWellContributions.cu @@ -262,5 +262,9 @@ void WellContributionsCuda::setCudaStream(cudaStream_t stream_) template class WellContributionsCuda; +#if FLOW_INSTANTIATE_FLOAT +template class WellContributionsCuda; +#endif + } //namespace Opm diff --git a/opm/simulators/linalg/bda/opencl/openclWellContributions.cpp b/opm/simulators/linalg/bda/opencl/openclWellContributions.cpp index 3be57e5f2..153f3e513 100644 --- a/opm/simulators/linalg/bda/opencl/openclWellContributions.cpp +++ b/opm/simulators/linalg/bda/opencl/openclWellContributions.cpp @@ -168,4 +168,8 @@ void WellContributionsOCL::APIalloc() template class WellContributionsOCL; +#if FLOW_INSTANTIATE_FLOAT +template class WellContributionsOCL; +#endif + } // namespace Opm diff --git a/opm/simulators/linalg/bda/rocm/rocsparseWellContributions.cpp b/opm/simulators/linalg/bda/rocm/rocsparseWellContributions.cpp index b8d992383..ffe105043 100644 --- a/opm/simulators/linalg/bda/rocm/rocsparseWellContributions.cpp +++ b/opm/simulators/linalg/bda/rocm/rocsparseWellContributions.cpp @@ -266,4 +266,8 @@ void WellContributionsRocsparse::APIalloc() template class WellContributionsRocsparse; +#if FLOW_INSTANTIATE_FLOAT +template class WellContributionsRocsparse; +#endif + } // namespace Opm From f6e0c03498a96389b12f251ff6be6c04ef8bacc2 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 12/19] StandardWellEquations: optionally instantiate for float --- .../wells/StandardWellEquations.cpp | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/opm/simulators/wells/StandardWellEquations.cpp b/opm/simulators/wells/StandardWellEquations.cpp index 9ead9bf35..314cc8ce6 100644 --- a/opm/simulators/wells/StandardWellEquations.cpp +++ b/opm/simulators/wells/StandardWellEquations.cpp @@ -404,24 +404,31 @@ sumDistributed(Parallel::Communication comm) wellhelpers::sumDistributedWellEntries(duneD_[0][0], resWell_[0], comm); } -#define INSTANCE(N) \ -template class StandardWellEquations; \ -template void StandardWellEquations:: \ - extract(Linear::IstlSparseMatrixAdapter>&) const; \ -template void StandardWellEquations:: \ - extractCPRPressureMatrix(Dune::BCRSMatrix>&, \ - const typename StandardWellEquations::BVector&, \ - const int, \ - const bool, \ - const WellInterfaceGeneric&, \ - const int, \ - const WellState&) const; +#define INSTANTIATE(T,N) \ + template class StandardWellEquations; \ + template void StandardWellEquations:: \ + extract(Linear::IstlSparseMatrixAdapter>&) const; \ + template void StandardWellEquations:: \ + extractCPRPressureMatrix(Dune::BCRSMatrix>&, \ + const typename StandardWellEquations::BVector&, \ + const int, \ + const bool, \ + const WellInterfaceGeneric&, \ + const int, \ + const WellState&) const; -INSTANCE(1) -INSTANCE(2) -INSTANCE(3) -INSTANCE(4) -INSTANCE(5) -INSTANCE(6) +#define INSTANTIATE_TYPE(T) \ + INSTANTIATE(T,1) \ + INSTANTIATE(T,2) \ + INSTANTIATE(T,3) \ + INSTANTIATE(T,4) \ + INSTANTIATE(T,5) \ + INSTANTIATE(T,6) + +INSTANTIATE_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } From 94e43f6ea912e0c479e1bf4028a32edbad9d5374 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 13/19] StandardWellEval: optionally instantiate for float --- opm/simulators/wells/StandardWellEval.cpp | 65 ++++++++++++----------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/opm/simulators/wells/StandardWellEval.cpp b/opm/simulators/wells/StandardWellEval.cpp index b7a945881..127e4438c 100644 --- a/opm/simulators/wells/StandardWellEval.cpp +++ b/opm/simulators/wells/StandardWellEval.cpp @@ -201,38 +201,43 @@ init(std::vector& perf_depth, this->linSys_.init(num_cells, numWellEq, baseif_.numPerfs(), baseif_.cells()); } -#define INSTANCE(...) \ -template class StandardWellEval,__VA_ARGS__>; +template +using FS = BlackOilFluidSystem; -// One phase -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) -INSTANCE(BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,5u>) +#define INSTANTIATE(T,...) \ + template class StandardWellEval,__VA_ARGS__>; -// Two phase -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,true,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,2u,0u,false,false,0u,2u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,true,0u,0u,0u>) -INSTANCE(BlackOilTwoPhaseIndices<1u,0u,0u,0u,false,false,0u,0u,0u>) -// Blackoil -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,true,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,0u,false,true,0u,0u>) -INSTANCE(BlackOilIndices<1u,0u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,1u,0u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,1u,0u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,1u,false,false,0u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,1u,false,false,1u,0u>) -INSTANCE(BlackOilIndices<0u,0u,0u,1u,false,true,0u,0u>) +#define INSTANTIATE_TYPE(T) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,5u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,1u,0u,false,true,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,2u,0u,false,false,0u,2u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<0u,0u,0u,1u,false,true,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilTwoPhaseIndices<1u,0u,0u,0u,false,false,0u,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,true,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,0u,false,true,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<1u,0u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,1u,0u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,1u,0u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,1u,false,false,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,1u,false,false,1u,0u>) \ + INSTANTIATE(T,BlackOilIndices<0u,0u,0u,1u,false,true,0u,0u>) \ + INSTANTIATE(T,BlackOilIndices<1u,0u,0u,0u,true,false,0u,0u>) -INSTANCE(BlackOilIndices<1u,0u,0u,0u,true,false,0u,0u>) +INSTANTIATE_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } From d244f4981338a9580bf565a46ab94a9ebe4ba963 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Sat, 13 Apr 2024 16:01:11 +0200 Subject: [PATCH 14/19] FlexibleSolver: throw if umfpack is requested with float Scalar --- opm/simulators/linalg/FlexibleSolver_impl.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/opm/simulators/linalg/FlexibleSolver_impl.hpp b/opm/simulators/linalg/FlexibleSolver_impl.hpp index b54ff651a..f79dc9a07 100644 --- a/opm/simulators/linalg/FlexibleSolver_impl.hpp +++ b/opm/simulators/linalg/FlexibleSolver_impl.hpp @@ -195,9 +195,13 @@ namespace Dune verbosity); #if HAVE_SUITESPARSE_UMFPACK } else if (solver_type == "umfpack") { + if constexpr (std::is_same_v) { + OPM_THROW(std::invalid_argument, "UMFPack cannot be used with floats"); + } else { using MatrixType = std::remove_const_tgetmat())>>; linsolver_ = std::make_shared>(linearoperator_for_solver_->getmat(), verbosity, false); direct_solver_ = true; + } #endif #if HAVE_CUDA } else if (solver_type == "cubicgstab") { @@ -227,8 +231,12 @@ namespace Dune recreateDirectSolver() { #if HAVE_SUITESPARSE_UMFPACK + if constexpr (std::is_same_v) { + OPM_THROW(std::invalid_argument, "UMFPack cannot be used with floats"); + } else { using MatrixType = std::remove_const_tgetmat())>>; linsolver_ = std::make_shared>(linearoperator_for_solver_->getmat(), 0, false); + } #else OPM_THROW(std::logic_error, "Direct solver specified, but the FlexibleSolver class was not compiled with SuiteSparse support."); #endif From 1cc27754d8f075e62e0223c7dff5862a81bbf491 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Sat, 13 Apr 2024 16:01:11 +0200 Subject: [PATCH 15/19] FlexibleSolver: optionally instantiate for float PreconditionerFactory: optionally instantiate for float these need to go in the same commit due to circular dependencies --- opm/simulators/linalg/FlexibleSolver1.cpp | 6 +- opm/simulators/linalg/FlexibleSolver2.cpp | 6 +- opm/simulators/linalg/FlexibleSolver3.cpp | 6 +- opm/simulators/linalg/FlexibleSolver4.cpp | 6 +- opm/simulators/linalg/FlexibleSolver5.cpp | 6 +- opm/simulators/linalg/FlexibleSolver6.cpp | 6 +- opm/simulators/linalg/FlexibleSolver_impl.hpp | 68 +++++------ .../linalg/PreconditionerFactory1.cpp | 6 +- .../linalg/PreconditionerFactory2.cpp | 6 +- .../linalg/PreconditionerFactory3.cpp | 6 +- .../linalg/PreconditionerFactory4.cpp | 6 +- .../linalg/PreconditionerFactory5.cpp | 6 +- .../linalg/PreconditionerFactory6.cpp | 7 +- .../linalg/PreconditionerFactory_impl.hpp | 109 +++++++++--------- 14 files changed, 150 insertions(+), 100 deletions(-) diff --git a/opm/simulators/linalg/FlexibleSolver1.cpp b/opm/simulators/linalg/FlexibleSolver1.cpp index 51e04c492..bdc100160 100644 --- a/opm/simulators/linalg/FlexibleSolver1.cpp +++ b/opm/simulators/linalg/FlexibleSolver1.cpp @@ -21,4 +21,8 @@ #include -INSTANTIATE_FLEXIBLESOLVER(1); +INSTANTIATE_FLEXIBLESOLVER(double,1) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_FLEXIBLESOLVER(float,1) +#endif diff --git a/opm/simulators/linalg/FlexibleSolver2.cpp b/opm/simulators/linalg/FlexibleSolver2.cpp index 00511eefd..a52943c8e 100644 --- a/opm/simulators/linalg/FlexibleSolver2.cpp +++ b/opm/simulators/linalg/FlexibleSolver2.cpp @@ -21,4 +21,8 @@ #include -INSTANTIATE_FLEXIBLESOLVER(2); +INSTANTIATE_FLEXIBLESOLVER(double,2) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_FLEXIBLESOLVER(float,2) +#endif diff --git a/opm/simulators/linalg/FlexibleSolver3.cpp b/opm/simulators/linalg/FlexibleSolver3.cpp index 5ccdd7749..458a9cfb2 100644 --- a/opm/simulators/linalg/FlexibleSolver3.cpp +++ b/opm/simulators/linalg/FlexibleSolver3.cpp @@ -21,4 +21,8 @@ #include -INSTANTIATE_FLEXIBLESOLVER(3); +INSTANTIATE_FLEXIBLESOLVER(double,3) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_FLEXIBLESOLVER(float,3) +#endif diff --git a/opm/simulators/linalg/FlexibleSolver4.cpp b/opm/simulators/linalg/FlexibleSolver4.cpp index 9aed1ae47..a86e13b3a 100644 --- a/opm/simulators/linalg/FlexibleSolver4.cpp +++ b/opm/simulators/linalg/FlexibleSolver4.cpp @@ -21,4 +21,8 @@ #include -INSTANTIATE_FLEXIBLESOLVER(4); +INSTANTIATE_FLEXIBLESOLVER(double,4) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_FLEXIBLESOLVER(float,4) +#endif diff --git a/opm/simulators/linalg/FlexibleSolver5.cpp b/opm/simulators/linalg/FlexibleSolver5.cpp index c8b80a95a..82b9037e8 100644 --- a/opm/simulators/linalg/FlexibleSolver5.cpp +++ b/opm/simulators/linalg/FlexibleSolver5.cpp @@ -21,4 +21,8 @@ #include -INSTANTIATE_FLEXIBLESOLVER(5); +INSTANTIATE_FLEXIBLESOLVER(double,5) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_FLEXIBLESOLVER(float,5) +#endif diff --git a/opm/simulators/linalg/FlexibleSolver6.cpp b/opm/simulators/linalg/FlexibleSolver6.cpp index cc2242baa..ce9c9094a 100644 --- a/opm/simulators/linalg/FlexibleSolver6.cpp +++ b/opm/simulators/linalg/FlexibleSolver6.cpp @@ -21,4 +21,8 @@ #include -INSTANTIATE_FLEXIBLESOLVER(6); +INSTANTIATE_FLEXIBLESOLVER(double,6) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_FLEXIBLESOLVER(float,6) +#endif diff --git a/opm/simulators/linalg/FlexibleSolver_impl.hpp b/opm/simulators/linalg/FlexibleSolver_impl.hpp index f79dc9a07..064c378d5 100644 --- a/opm/simulators/linalg/FlexibleSolver_impl.hpp +++ b/opm/simulators/linalg/FlexibleSolver_impl.hpp @@ -265,57 +265,57 @@ namespace Dune // Macros to simplify explicit instantiation of FlexibleSolver for various block sizes. // Vectors and matrices. -template -using BV = Dune::BlockVector>; -template -using OBM = Dune::BCRSMatrix>; +template +using BV = Dune::BlockVector>; +template +using OBM = Dune::BCRSMatrix>; // Sequential operators. -template -using SeqOpM = Dune::MatrixAdapter, BV, BV>; -template -using SeqOpW = Opm::WellModelMatrixAdapter, BV, BV, false>; +template +using SeqOpM = Dune::MatrixAdapter, BV, BV>; +template +using SeqOpW = Opm::WellModelMatrixAdapter, BV, BV, false>; #if HAVE_MPI // Parallel communicator and operators. using Comm = Dune::OwnerOverlapCopyCommunication; -template -using ParOpM = Opm::GhostLastMatrixAdapter, BV, BV, Comm>; -template -using ParOpW = Opm::WellModelGhostLastMatrixAdapter, BV, BV, true>; -template -using ParOpD = Dune::OverlappingSchwarzOperator, BV, BV, Comm>; +template +using ParOpM = Opm::GhostLastMatrixAdapter, BV, BV, Comm>; +template +using ParOpW = Opm::WellModelGhostLastMatrixAdapter, BV, BV, true>; +template +using ParOpD = Dune::OverlappingSchwarzOperator, BV, BV, Comm>; // Note: we must instantiate the constructor that is a template. // This is only needed in the parallel case, since otherwise the Comm type is // not a template argument but always SequentialInformation. -#define INSTANTIATE_FLEXIBLESOLVER_OP(Operator) \ -template class Dune::FlexibleSolver; \ -template Dune::FlexibleSolver::FlexibleSolver(Operator& op, \ - const Comm& comm, \ - const Opm::PropertyTree& prm, \ - const std::function& weightsCalculator, \ - std::size_t pressureIndex); -#define INSTANTIATE_FLEXIBLESOLVER(N) \ -INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpM); \ -INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpW); \ -INSTANTIATE_FLEXIBLESOLVER_OP(ParOpM); \ -INSTANTIATE_FLEXIBLESOLVER_OP(ParOpW); \ -INSTANTIATE_FLEXIBLESOLVER_OP(ParOpD); +#define INSTANTIATE_FLEXIBLESOLVER_OP(...) \ + template class Dune::FlexibleSolver<__VA_ARGS__>; \ + template Dune::FlexibleSolver<__VA_ARGS__>:: \ + FlexibleSolver(__VA_ARGS__& op, \ + const Comm& comm, \ + const Opm::PropertyTree& prm, \ + const std::function& weightsCalculator, \ + std::size_t pressureIndex); + +#define INSTANTIATE_FLEXIBLESOLVER(T,N) \ + INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpM); \ + INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpW); \ + INSTANTIATE_FLEXIBLESOLVER_OP(ParOpM); \ + INSTANTIATE_FLEXIBLESOLVER_OP(ParOpW); \ + INSTANTIATE_FLEXIBLESOLVER_OP(ParOpD); #else // HAVE_MPI -#define INSTANTIATE_FLEXIBLESOLVER_OP(Operator) \ -template class Dune::FlexibleSolver; +#define INSTANTIATE_FLEXIBLESOLVER_OP(...) \ + template class Dune::FlexibleSolver<__VA_ARGS__>; -#define INSTANTIATE_FLEXIBLESOLVER(N) \ -INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpM); \ -INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpW); +#define INSTANTIATE_FLEXIBLESOLVER(T,N) \ + INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpM); \ + INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpW); #endif // HAVE_MPI - - #endif // OPM_FLEXIBLE_SOLVER_IMPL_HEADER_INCLUDED diff --git a/opm/simulators/linalg/PreconditionerFactory1.cpp b/opm/simulators/linalg/PreconditionerFactory1.cpp index 3483ee1ff..bead94b5d 100644 --- a/opm/simulators/linalg/PreconditionerFactory1.cpp +++ b/opm/simulators/linalg/PreconditionerFactory1.cpp @@ -4,6 +4,10 @@ namespace Opm { -INSTANCE_PF(1) +INSTANTIATE_PF(double,1) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_PF(float,1) +#endif } diff --git a/opm/simulators/linalg/PreconditionerFactory2.cpp b/opm/simulators/linalg/PreconditionerFactory2.cpp index a8533bb09..0221c065b 100644 --- a/opm/simulators/linalg/PreconditionerFactory2.cpp +++ b/opm/simulators/linalg/PreconditionerFactory2.cpp @@ -4,6 +4,10 @@ namespace Opm { -INSTANCE_PF(2) +INSTANTIATE_PF(double,2) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_PF(float,2) +#endif } diff --git a/opm/simulators/linalg/PreconditionerFactory3.cpp b/opm/simulators/linalg/PreconditionerFactory3.cpp index f69d00638..35d23d766 100644 --- a/opm/simulators/linalg/PreconditionerFactory3.cpp +++ b/opm/simulators/linalg/PreconditionerFactory3.cpp @@ -4,6 +4,10 @@ namespace Opm { -INSTANCE_PF(3) +INSTANTIATE_PF(double,3) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_PF(float,3) +#endif } diff --git a/opm/simulators/linalg/PreconditionerFactory4.cpp b/opm/simulators/linalg/PreconditionerFactory4.cpp index 3e7765b0a..ae3ce9684 100644 --- a/opm/simulators/linalg/PreconditionerFactory4.cpp +++ b/opm/simulators/linalg/PreconditionerFactory4.cpp @@ -4,6 +4,10 @@ namespace Opm { -INSTANCE_PF(4) +INSTANTIATE_PF(double,4) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_PF(float,4) +#endif } diff --git a/opm/simulators/linalg/PreconditionerFactory5.cpp b/opm/simulators/linalg/PreconditionerFactory5.cpp index de59055fa..b37ced786 100644 --- a/opm/simulators/linalg/PreconditionerFactory5.cpp +++ b/opm/simulators/linalg/PreconditionerFactory5.cpp @@ -4,6 +4,10 @@ namespace Opm { -INSTANCE_PF(5) +INSTANTIATE_PF(double,5) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_PF(float,5) +#endif } diff --git a/opm/simulators/linalg/PreconditionerFactory6.cpp b/opm/simulators/linalg/PreconditionerFactory6.cpp index 1a028122e..ba0893a78 100644 --- a/opm/simulators/linalg/PreconditionerFactory6.cpp +++ b/opm/simulators/linalg/PreconditionerFactory6.cpp @@ -4,6 +4,11 @@ namespace Opm { -INSTANCE_PF(6) +INSTANTIATE_PF(double,6) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_PF(float,6) +#endif + } diff --git a/opm/simulators/linalg/PreconditionerFactory_impl.hpp b/opm/simulators/linalg/PreconditionerFactory_impl.hpp index 50d6713c8..7c3fe3b90 100644 --- a/opm/simulators/linalg/PreconditionerFactory_impl.hpp +++ b/opm/simulators/linalg/PreconditionerFactory_impl.hpp @@ -17,12 +17,14 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ + +#include + #include #include #include - #include #include #include @@ -44,8 +46,6 @@ #include #include -#include - // Include all cuistl/GPU preconditioners inside of this headerfile #include @@ -778,76 +778,77 @@ PreconditionerFactory::addCreator(const std::string& type, ParCr using CommSeq = Dune::Amg::SequentialInformation; -template -using OpFSeq = Dune::MatrixAdapter>, - Dune::BlockVector>, - Dune::BlockVector>>; -template -using OpBSeq = Dune::MatrixAdapter>, - Dune::BlockVector>, - Dune::BlockVector>>; +template +using OpFSeq = Dune::MatrixAdapter>, + Dune::BlockVector>, + Dune::BlockVector>>; +template +using OpBSeq = Dune::MatrixAdapter>, + Dune::BlockVector>, + Dune::BlockVector>>; -template -using OpW = WellModelMatrixAdapter>, - Dune::BlockVector>, - Dune::BlockVector>, +template +using OpW = WellModelMatrixAdapter>, + Dune::BlockVector>, + Dune::BlockVector>, overlap>; -template -using OpWG = WellModelGhostLastMatrixAdapter>, - Dune::BlockVector>, - Dune::BlockVector>, +template +using OpWG = WellModelGhostLastMatrixAdapter>, + Dune::BlockVector>, + Dune::BlockVector>, overlap>; #if HAVE_MPI using CommPar = Dune::OwnerOverlapCopyCommunication; -template -using OpFPar = Dune::OverlappingSchwarzOperator>, - Dune::BlockVector>, - Dune::BlockVector>, +template +using OpFPar = Dune::OverlappingSchwarzOperator>, + Dune::BlockVector>, + Dune::BlockVector>, CommPar>; -template -using OpBPar = Dune::OverlappingSchwarzOperator>, - Dune::BlockVector>, - Dune::BlockVector>, +template +using OpBPar = Dune::OverlappingSchwarzOperator>, + Dune::BlockVector>, + Dune::BlockVector>, CommPar>; -template -using OpGLFPar = Opm::GhostLastMatrixAdapter>, - Dune::BlockVector>, - Dune::BlockVector>, +template +using OpGLFPar = Opm::GhostLastMatrixAdapter>, + Dune::BlockVector>, + Dune::BlockVector>, CommPar>; -template -using OpGLBPar = Opm::GhostLastMatrixAdapter>, - Dune::BlockVector>, - Dune::BlockVector>, +template +using OpGLBPar = Opm::GhostLastMatrixAdapter>, + Dune::BlockVector>, + Dune::BlockVector>, CommPar>; -#define INSTANCE_PF_PAR(Dim) \ - template class PreconditionerFactory, CommPar>; \ - template class PreconditionerFactory, CommPar>; \ - template class PreconditionerFactory, CommPar>; \ - template class PreconditionerFactory,CommPar>; \ - template class PreconditionerFactory,CommPar>; \ - template class PreconditionerFactory, CommPar>; \ - template class PreconditionerFactory, CommPar>; \ - template class PreconditionerFactory,CommSeq>; \ - template class PreconditionerFactory,CommSeq>; +#define INSTANTIATE_PF_PAR(T,Dim) \ + template class PreconditionerFactory, CommPar>; \ + template class PreconditionerFactory, CommPar>; \ + template class PreconditionerFactory, CommPar>; \ + template class PreconditionerFactory, CommPar>; \ + template class PreconditionerFactory, CommPar>; \ + template class PreconditionerFactory, CommPar>; \ + template class PreconditionerFactory, CommPar>; \ + template class PreconditionerFactory, CommSeq>; \ + template class PreconditionerFactory, CommSeq>; #endif -#define INSTANCE_PF_SEQ(Dim) \ - template class PreconditionerFactory, CommSeq>; \ - template class PreconditionerFactory, CommSeq>; \ - template class PreconditionerFactory, CommSeq>; \ - template class PreconditionerFactory, CommSeq>; +#define INSTANTIATE_PF_SEQ(T,Dim) \ + template class PreconditionerFactory, CommSeq>; \ + template class PreconditionerFactory, CommSeq>; \ + template class PreconditionerFactory, CommSeq>; \ + template class PreconditionerFactory, CommSeq>; #if HAVE_MPI -#define INSTANCE_PF(Dim) \ - INSTANCE_PF_PAR(Dim) \ - INSTANCE_PF_SEQ(Dim) +#define INSTANTIATE_PF(T,Dim) \ + INSTANTIATE_PF_PAR(T,Dim) \ + INSTANTIATE_PF_SEQ(T,Dim) #else -#define INSTANCE_PF(Dim) INSTANCE_PF_SEQ(Dim) +#define INSTANTIATE_PF(T,Dim) INSTANTIATE_PF_SEQ(T,Dim) #endif + } // namespace Opm From 2245daa0c72b929ecd3c1937cbe93aa1c2b650bb Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 23:30:19 +0200 Subject: [PATCH 16/19] ISTLSolver: optionally instantiate for float --- opm/simulators/linalg/ISTLSolver.cpp | 33 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/opm/simulators/linalg/ISTLSolver.cpp b/opm/simulators/linalg/ISTLSolver.cpp index 312827360..4faa785e3 100644 --- a/opm/simulators/linalg/ISTLSolver.cpp +++ b/opm/simulators/linalg/ISTLSolver.cpp @@ -158,10 +158,10 @@ void FlexibleSolverInfo::create(const Matrix& matrix, } } -template -using BM = Dune::BCRSMatrix>; -template -using BV = Dune::BlockVector>; +template +using BM = Dune::BCRSMatrix>; +template +using BV = Dune::BlockVector>; #if HAVE_MPI using CommunicationType = Dune::OwnerOverlapCopyCommunication; @@ -169,16 +169,23 @@ using CommunicationType = Dune::OwnerOverlapCopyCommunication; using CommunicationType = Dune::Communication; #endif -#define INSTANCE_FLEX(Dim) \ - template void makeOverlapRowsInvalid>(BM&, const std::vector&); \ - template struct FlexibleSolverInfo,BV,CommunicationType>; +#define INSTANTIATE_FLEX(T,Dim) \ + template void makeOverlapRowsInvalid>(BM&, const std::vector&); \ + template struct FlexibleSolverInfo,BV,CommunicationType>; -INSTANCE_FLEX(1) -INSTANCE_FLEX(2) -INSTANCE_FLEX(3) -INSTANCE_FLEX(4) -INSTANCE_FLEX(5) -INSTANCE_FLEX(6) +#define INSTANTIATE_TYPE(T) \ + INSTANTIATE_FLEX(T,1) \ + INSTANTIATE_FLEX(T,2) \ + INSTANTIATE_FLEX(T,3) \ + INSTANTIATE_FLEX(T,4) \ + INSTANTIATE_FLEX(T,5) \ + INSTANTIATE_FLEX(T,6) + +INSTANTIATE_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } } From bff3dae23082106f2df7b013616846e3c12eecee Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 13:11:09 +0200 Subject: [PATCH 17/19] GenericTracerModel: optionally instantiate for float --- opm/simulators/flow/GenericTracerModel.cpp | 99 ++++++++++++++++------ 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/opm/simulators/flow/GenericTracerModel.cpp b/opm/simulators/flow/GenericTracerModel.cpp index f58ed53d3..9152348e6 100644 --- a/opm/simulators/flow/GenericTracerModel.cpp +++ b/opm/simulators/flow/GenericTracerModel.cpp @@ -37,42 +37,85 @@ namespace Opm { -template class GenericTracerModel>, - Dune::MultipleCodimMultipleGeomTypeMapper>>, - Opm::EcfvStencil>,false,false>, - BlackOilFluidSystem, - double>; +#define INSTANTIATE_TYPE(T) \ + template class GenericTracerModel>, \ + Dune::MultipleCodimMultipleGeomTypeMapper< \ + Dune::GridView< \ + Dune::DefaultLeafGridViewTraits>>, \ + EcfvStencil>, \ + false,false>, \ + BlackOilFluidSystem, \ + T>; + +INSTANTIATE_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif #if HAVE_DUNE_FEM #if DUNE_VERSION_GTE(DUNE_FEM, 2, 9) using GV = Dune::Fem::AdaptiveLeafGridPart; -template class GenericTracerModel, - EcfvStencil, - BlackOilFluidSystem, - double>; +#define INSTANTIATE_FEM_TYPE(T) \ +template class GenericTracerModel, \ + EcfvStencil, \ + BlackOilFluidSystem, \ + T>; #else -template class GenericTracerModel>>, - Dune::MultipleCodimMultipleGeomTypeMapper>>>, - EcfvStencil>>,false,false>, - BlackOilFluidSystem, - double>; -template class GenericTracerModel >, - Dune::MultipleCodimMultipleGeomTypeMapper< - Dune::Fem::GridPart2GridViewImpl< - Dune::Fem::AdaptiveLeafGridPart > >, - EcfvStencil >, - false, false>, - BlackOilFluidSystem, - double>; +#define INSTANTIATE_FEM_TYPE(T) \ + template class GenericTracerModel>>, \ + Dune::MultipleCodimMultipleGeomTypeMapper< \ + Dune::GridView< \ + Dune::Fem::GridPart2GridViewTraits< \ + Dune::Fem::AdaptiveLeafGridPart< \ + Dune::CpGrid, \ + Dune::PartitionIteratorType(4), false>>>>, \ + EcfvStencil>>, \ + false,false>, \ + BlackOilFluidSystem, \ + T>; \ + template class GenericTracerModel >, \ + Dune::MultipleCodimMultipleGeomTypeMapper< \ + Dune::Fem::GridPart2GridViewImpl< \ + Dune::Fem::AdaptiveLeafGridPart< \ + Dune::CpGrid, \ + Dune::PartitionIteratorType(4), false> > >, \ + EcfvStencil>,\ + false, false>, \ + BlackOilFluidSystem, \ + T>; #endif + +INSTANTIATE_FEM_TYPE(double) + +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_FEM_TYPE(float) +#endif + #endif // HAVE_DUNE_FEM } // namespace Opm From b16fd2f7248b6f21285feba2fac7a39c537f3b30 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 23:30:19 +0200 Subject: [PATCH 18/19] EquilibrationHelpers: optionally instantiate for float --- opm/simulators/flow/equil/EquilibrationHelpers.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opm/simulators/flow/equil/EquilibrationHelpers.cpp b/opm/simulators/flow/equil/EquilibrationHelpers.cpp index 37d6d06bf..4d743922b 100644 --- a/opm/simulators/flow/equil/EquilibrationHelpers.cpp +++ b/opm/simulators/flow/equil/EquilibrationHelpers.cpp @@ -55,5 +55,9 @@ template using FS = BlackOilFluidSystem; INSTANTIATE_TYPE(double) +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif + } // namespace Equil } // namespace Opm From 05d37bfbf6e24eea27cee367d60bdc9d83e62e42 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 12 Apr 2024 23:30:19 +0200 Subject: [PATCH 19/19] InitStateEquil: optionally instantiate for float --- opm/simulators/flow/equil/InitStateEquil.cpp | 59 ++++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/opm/simulators/flow/equil/InitStateEquil.cpp b/opm/simulators/flow/equil/InitStateEquil.cpp index cae9c56ab..418104b27 100644 --- a/opm/simulators/flow/equil/InitStateEquil.cpp +++ b/opm/simulators/flow/equil/InitStateEquil.cpp @@ -43,29 +43,33 @@ using MatLaw = EclMaterialLawManager>; namespace EQUIL { namespace DeckDependent { -#define INSTANTIATE_COMP(T, GridView, Mapper) \ - template class InitialStateComputer, \ - Dune::CpGrid, \ - GridView, \ - Mapper, \ +#define INSTANTIATE_COMP(T, GridView, Mapper) \ + template class InitialStateComputer, \ + Dune::CpGrid, \ + GridView, \ + Mapper, \ Dune::CartesianIndexMapper>; \ - template InitialStateComputer, \ - Dune::CpGrid, \ - GridView, \ - Mapper, \ - Dune::CartesianIndexMapper>::\ - InitialStateComputer(MatLaw&, \ - const EclipseState&, \ - const Dune::CpGrid&, \ - const GridView&, \ + template InitialStateComputer, \ + Dune::CpGrid, \ + GridView, \ + Mapper, \ + Dune::CartesianIndexMapper>:: \ + InitialStateComputer(MatLaw&, \ + const EclipseState&, \ + const Dune::CpGrid&, \ + const GridView&, \ const Dune::CartesianIndexMapper&, \ - const T, \ - const int, \ + const T, \ + const int, \ const bool); using GridView = Dune::GridView>; using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper; + INSTANTIATE_COMP(double, GridView, Mapper) +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_COMP(float, GridView, Mapper) +#endif #if HAVE_DUNE_FEM #if DUNE_VERSION_GTE(DUNE_FEM, 2, 9) @@ -83,23 +87,30 @@ using MapperFem = Dune::MultipleCodimMultipleGeomTypeMapper; INSTANTIATE_COMP(double, GridViewFem, MapperFem) +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_COMP(float, GridViewFem, MapperFem) +#endif + #endif // HAVE_DUNE_FEM } // namespace DeckDependent namespace Details { -#define INSTANTIATE_TYPE(T) \ - template class PressureTable,EquilReg>; \ - template void verticalExtent(const std::vector&, \ - const std::vector>&, \ - const Parallel::Communication&, \ - std::array&); \ - template class PhaseSaturations,BlackOilFluidSystem, \ - EquilReg,std::size_t>; \ +#define INSTANTIATE_TYPE(T) \ + template class PressureTable,EquilReg>; \ + template void verticalExtent(const std::vector&, \ + const std::vector>&, \ + const Parallel::Communication&, \ + std::array&); \ + template class PhaseSaturations,BlackOilFluidSystem, \ + EquilReg,std::size_t>; \ template std::pair cellZMinMax(const Dune::cpgrid::Entity<0>&); INSTANTIATE_TYPE(double) +#if FLOW_INSTANTIATE_FLOAT +INSTANTIATE_TYPE(float) +#endif } } // namespace EQUIL