move output error log to LogOutputHelper

This commit is contained in:
Arne Morten Kvarving 2023-08-04 12:37:48 +02:00
parent e2d4bae78d
commit b0f1e5d3f5
3 changed files with 78 additions and 58 deletions

View File

@ -1053,44 +1053,6 @@ isOutputCreationDirective_(const std::string& keyword)
|| (keyword == "SAVE") || (keyword == "SFREQ"); // Not really supported
}
namespace {
template <typename IndexVector, typename IJKString>
void logUniqueFailedCells(const std::string& messageTag,
std::string_view prefix,
const std::size_t maxNumCellsFaillog,
IndexVector&& cells,
IJKString&& ijkString)
{
if (cells.empty()) {
return;
}
std::sort(cells.begin(), cells.end());
auto u = std::unique(cells.begin(), cells.end());
const auto numFailed = static_cast<std::size_t>
(std::distance(cells.begin(), u));
std::ostringstream errlog;
errlog << prefix << " failed for " << numFailed << " cell"
<< ((numFailed != std::size_t{1}) ? "s" : "")
<< " [" << ijkString(cells[0]);
const auto maxElems = std::min(maxNumCellsFaillog, numFailed);
for (auto i = 1 + 0*maxElems; i < maxElems; ++i) {
errlog << ", " << ijkString(cells[i]);
}
if (numFailed > maxNumCellsFaillog) {
errlog << ", ...";
}
errlog << ']';
OpmLog::warning(messageTag, errlog.str());
}
} // Namespace anonymous
template<class FluidSystem,class Scalar>
void EclGenericOutputBlackoilModule<FluidSystem,Scalar>::
outputErrorLog(const Parallel::Communication& comm) const
@ -1105,26 +1067,8 @@ outputErrorLog(const Parallel::Communication& comm) const
return;
}
auto ijkString = [this](const std::size_t globalIndex)
{
const auto ijk = this->eclState_.gridDims().getIJK(globalIndex);
return fmt::format("({},{},{})", ijk[0] + 1, ijk[1] + 1, ijk[2] + 1);
};
const auto maxNumCellsFaillog = static_cast<std::size_t>(20);
logUniqueFailedCells("Bubble point numerical problem",
"Finding the bubble point pressure",
maxNumCellsFaillog,
std::get<0>(std::move(globalFailedCellsPbub)),
ijkString);
logUniqueFailedCells("Dew point numerical problem",
"Finding the dew point pressure",
maxNumCellsFaillog,
std::get<0>(std::move(globalFailedCellsPdew)),
ijkString);
logOutput_.error(std::get<0>(globalFailedCellsPbub),
std::get<0>(globalFailedCellsPdew));
}
template<class FluidSystem,class Scalar>

View File

@ -29,11 +29,55 @@
#include <opm/simulators/utils/PressureAverage.hpp>
#include <fmt/format.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <vector>
namespace {
template <typename IJKString>
void logUniqueFailedCells(const std::string& messageTag,
std::string_view prefix,
const std::size_t maxNumCellsFaillog,
const std::vector<int>& cells,
IJKString&& ijkString)
{
if (cells.empty()) {
return;
}
std::vector<int> sorted(cells);
std::sort(sorted.begin(), sorted.end());
auto u = std::unique(sorted.begin(), sorted.end());
const auto numFailed = static_cast<std::size_t>
(std::distance(sorted.begin(), u));
std::ostringstream errlog;
errlog << prefix << " failed for " << numFailed << " cell"
<< ((numFailed != std::size_t{1}) ? "s" : "")
<< " [" << ijkString(cells[0]);
const auto maxElems = std::min(maxNumCellsFaillog, numFailed);
for (auto i = 1 + 0*maxElems; i < maxElems; ++i) {
errlog << ", " << ijkString(cells[i]);
}
if (numFailed > maxNumCellsFaillog) {
errlog << ", ...";
}
errlog << ']';
Opm::OpmLog::warning(messageTag, errlog.str());
}
} // Namespace anonymous
namespace Opm {
template<class Scalar>
@ -185,6 +229,33 @@ cumulative(const std::size_t reportStepNum,
}
}
template<class Scalar>
void LogOutputHelper<Scalar>::
error(const std::vector<int>& failedCellsPbub,
const std::vector<int>& failedCellsPdew) const
{
auto ijkString = [this](const std::size_t globalIndex)
{
const auto ijk = this->eclState_.gridDims().getIJK(globalIndex);
return fmt::format("({},{},{})", ijk[0] + 1, ijk[1] + 1, ijk[2] + 1);
};
constexpr auto maxNumCellsFaillog = static_cast<std::size_t>(20);
logUniqueFailedCells("Bubble point numerical problem",
"Finding the bubble point pressure",
maxNumCellsFaillog,
failedCellsPbub,
ijkString);
logUniqueFailedCells("Dew point numerical problem",
"Finding the dew point pressure",
maxNumCellsFaillog,
failedCellsPdew,
ijkString);
}
template<class Scalar>
void LogOutputHelper<Scalar>::
fip(const Inplace& inplace,

View File

@ -28,6 +28,7 @@
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
namespace Opm {
@ -47,6 +48,10 @@ public:
void cumulative(const std::size_t reportStepNum,
std::function<bool(const std::string&)> isDefunct) const;
//! \brief Write error report to output.
void error(const std::vector<int>& failedCellsPbub,
const std::vector<int>& failedCellsPdew) const;
//! \brief Write fluid-in-place reports to output.
void fip(const Inplace& inplace,
const Inplace& initialInplace) const;