From 0ce761c5e6f8596d290196da5b0bb59d1bf8ff48 Mon Sep 17 00:00:00 2001 From: Lisa Julia Nebel Date: Tue, 12 Nov 2024 15:10:47 +0100 Subject: [PATCH] Make wellhelpers::sumDistributedWellEntries work with other matrices than Dune::DynamicMatrix and add specialization for FieldMatrix, FieldMatrix and FieldMatrix as well as FieldMatrix, FieldMatrix and FieldMatrix Make wellhelpers::sumDistributedWellEntries work with other matrices than Dune::DynamicMatrix and add specialization for FieldMatrix, FieldMatrix and FieldMatrix as well as FieldMatrix, FieldMatrix and FieldMatrix --- opm/simulators/wells/WellHelpers.cpp | 58 ++++++++++++++++------------ opm/simulators/wells/WellHelpers.hpp | 6 +-- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/opm/simulators/wells/WellHelpers.cpp b/opm/simulators/wells/WellHelpers.cpp index 6cb1cabd4..8b4de0dde 100644 --- a/opm/simulators/wells/WellHelpers.cpp +++ b/opm/simulators/wells/WellHelpers.cpp @@ -133,9 +133,9 @@ Scalar computeHydrostaticCorrection(const Scalar well_ref_depth, const Scalar vf return dp; } -template -void sumDistributedWellEntries(Dune::DynamicMatrix& mat, - Dune::DynamicVector& vec, +template +void sumDistributedWellEntries(MatrixType& mat, + VectorType& vec, const Comm& comm) { // DynamicMatrix does not use one contiguous array for storing the data @@ -145,7 +145,7 @@ void sumDistributedWellEntries(Dune::DynamicMatrix& mat, { return; } - std::vector allEntries; + std::vector allEntries; allEntries.reserve(mat.N()*mat.M()+vec.size()); for(const auto& row: mat) { @@ -154,7 +154,7 @@ void sumDistributedWellEntries(Dune::DynamicMatrix& mat, allEntries.insert(allEntries.end(), vec.begin(), vec.end()); comm.sum(allEntries.data(), allEntries.size()); auto pos = allEntries.begin(); - auto cols = mat.cols(); + auto cols = mat.mat_cols(); for(auto&& row: mat) { std::copy(pos, pos + cols, &(row[0])); @@ -223,28 +223,36 @@ template using DMatrix = Dune::DynamicMatrix; using Comm = Parallel::Communication; -#define INSTANTIATE(T,Dim) \ - template void ParallelStandardWellB:: \ - mv(const Vec&,DynVec&) const; \ - template void ParallelStandardWellB:: \ +#define INSTANTIATE(T,Dim) \ + template void ParallelStandardWellB:: \ + mv(const Vec&,DynVec&) const; \ + template void ParallelStandardWellB:: \ mmv(const Vec&,DynVec&) const; -#define INSTANTIATE_TYPE(T) \ - template class ParallelStandardWellB; \ - template void sumDistributedWellEntries(Dune::DynamicMatrix& mat, \ - Dune::DynamicVector& vec, \ - const Comm& comm); \ - template DMatrix transposeDenseDynMatrix(const DMatrix&); \ - template T computeHydrostaticCorrection(const T, \ - const T, \ - const T, \ - const T); \ - INSTANTIATE(T,1) \ - INSTANTIATE(T,2) \ - INSTANTIATE(T,3) \ - INSTANTIATE(T,4) \ - INSTANTIATE(T,5) \ - INSTANTIATE(T,6) +#define INSTANTIATE_WE(T,Dim) \ + template void sumDistributedWellEntries(Dune::FieldMatrix& mat, \ + Dune::FieldVector& vec, \ + const Comm& comm); + +#define INSTANTIATE_TYPE(T) \ + template class ParallelStandardWellB; \ + template void sumDistributedWellEntries(Dune::DynamicMatrix& mat, \ + Dune::DynamicVector& vec, \ + const Comm& comm); \ + template DMatrix transposeDenseDynMatrix(const DMatrix&); \ + template T computeHydrostaticCorrection(const T, \ + const T, \ + const T, \ + const T); \ + INSTANTIATE(T,1) \ + INSTANTIATE(T,2) \ + INSTANTIATE(T,3) \ + INSTANTIATE(T,4) \ + INSTANTIATE(T,5) \ + INSTANTIATE(T,6) \ + INSTANTIATE_WE(T,2) \ + INSTANTIATE_WE(T,3) \ + INSTANTIATE_WE(T,4) INSTANTIATE_TYPE(double) diff --git a/opm/simulators/wells/WellHelpers.hpp b/opm/simulators/wells/WellHelpers.hpp index 6e86c06b1..0066b4a0b 100644 --- a/opm/simulators/wells/WellHelpers.hpp +++ b/opm/simulators/wells/WellHelpers.hpp @@ -76,9 +76,9 @@ Scalar computeHydrostaticCorrection(const Scalar well_ref_depth, const Scalar gravity); /// \brief Sums entries of the diagonal Matrix for distributed wells -template -void sumDistributedWellEntries(Dune::DynamicMatrix& mat, - Dune::DynamicVector& vec, +template +void sumDistributedWellEntries(MatrixType& mat, + VectorType& vec, const Comm& comm);