From fa84eb65c7938b1188bb036d077bf8ca2ea530a4 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 16 Apr 2024 13:02:53 +0200 Subject: [PATCH] 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