Loading...
Searching...
No Matches
ExtraConvergenceOutputThread.hpp
/*
Copyright 2022 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EXTRA_CONVERGENCE_OUTPUT_THREAD_HPP
#define EXTRA_CONVERGENCE_OUTPUT_THREAD_HPP
#include <opm/simulators/timestepping/ConvergenceReport.hpp>
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <string_view>
#include <vector>
namespace Opm {
class ConvergenceOutputConfiguration;
} // namespace Opm
namespace Opm
{
class ConvergenceOutputThread;
class ConvergenceReportQueue
{
public:
struct OutputRequest
{
int reportStep{-1};
int currentStep{-1};
std::vector<ConvergenceReport> reports{};
};
void enqueue(std::vector<OutputRequest>&& requests);
void signalLastOutputRequest();
friend class ConvergenceOutputThread;
private:
std::mutex mtx_{};
std::condition_variable cv_{};
std::vector<OutputRequest> requests_{};
};
class ConvergenceOutputThread
{
public:
using ComponentToPhaseName = std::function<std::string_view(int)>;
using ConvertToTimeUnits = std::function<double(double)>;
explicit ConvergenceOutputThread(std::string_view outputDir,
std::string_view baseName,
ComponentToPhaseName getPhaseName,
ConvertToTimeUnits convertTime,
ConvergenceOutputConfiguration config,
ConvergenceReportQueue& queue);
ConvergenceOutputThread(const ConvergenceOutputThread& src) = delete;
ConvergenceOutputThread(ConvergenceOutputThread&& src);
ConvergenceOutputThread& operator=(const ConvergenceOutputThread& src) = delete;
ConvergenceOutputThread& operator=(ConvergenceOutputThread&& src) = delete;
~ConvergenceOutputThread();
void writeSynchronous(std::vector<ConvergenceReportQueue::OutputRequest>&& requests);
void writeASynchronous();
private:
class Impl;
std::unique_ptr<Impl> pImpl_;
};
} // namespace Opm
#endif // EXTRA_CONVERGENCE_OUTPUT_THREAD_HPP
Opm::ConvergenceOutputConfiguration
Parse comma separated option strings into a runtime configuration object for whether to output additi...
Definition ConvergenceOutputConfiguration.hpp:46
Opm::ConvergenceOutputThread::Impl
Definition ExtraConvergenceOutputThread.cpp:261
Opm::ConvergenceOutputThread
Encapsulating object for thread processing producer's convergence output requests.
Definition ExtraConvergenceOutputThread.hpp:105
Opm::ConvergenceOutputThread::ComponentToPhaseName
std::function< std::string_view(int)> ComponentToPhaseName
Protocol for converting a phase/component ID into a human readable phase/component name.
Definition ExtraConvergenceOutputThread.hpp:109
Opm::ConvergenceOutputThread::operator=
ConvergenceOutputThread & operator=(const ConvergenceOutputThread &src)=delete
Deleted assignment operator.
Opm::ConvergenceOutputThread::operator=
ConvergenceOutputThread & operator=(ConvergenceOutputThread &&src)=delete
Deleted move-assignment operator.
Opm::ConvergenceOutputThread::writeSynchronous
void writeSynchronous(std::vector< ConvergenceReportQueue::OutputRequest > &&requests)
Perform synchronous file output of a sequence of requests.
Definition ExtraConvergenceOutputThread.cpp:408
Opm::ConvergenceOutputThread::writeASynchronous
void writeASynchronous()
Output thread worker function.
Definition ExtraConvergenceOutputThread.cpp:413
Opm::ConvergenceOutputThread::~ConvergenceOutputThread
~ConvergenceOutputThread()
Destructor.
Opm::ConvergenceOutputThread::ConvertToTimeUnits
std::function< double(double)> ConvertToTimeUnits
Protocol for converting an SI elapsed time value into an equivalent time value in the run's output co...
Definition ExtraConvergenceOutputThread.hpp:115
Opm::ConvergenceOutputThread::ConvergenceOutputThread
ConvergenceOutputThread(const ConvergenceOutputThread &src)=delete
Deleted copy constructor.
Opm::ConvergenceOutputThread::ConvergenceOutputThread
ConvergenceOutputThread(std::string_view outputDir, std::string_view baseName, ComponentToPhaseName getPhaseName, ConvertToTimeUnits convertTime, ConvergenceOutputConfiguration config, ConvergenceReportQueue &queue)
Constructor.
Definition ExtraConvergenceOutputThread.cpp:386
Opm::ConvergenceReportQueue
Communication channel between thread creating output requests and consumer thread writing those reque...
Definition ExtraConvergenceOutputThread.hpp:56
Opm::ConvergenceReportQueue::enqueue
void enqueue(std::vector< OutputRequest > &&requests)
Push sequence of output requests, typically all substeps whether converged or not,...
Definition ExtraConvergenceOutputThread.cpp:357
Opm::ConvergenceReportQueue::signalLastOutputRequest
void signalLastOutputRequest()
Signal end of output request stream.
Definition ExtraConvergenceOutputThread.cpp:377
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::ConvergenceReportQueue::OutputRequest
Single output request.
Definition ExtraConvergenceOutputThread.hpp:63
Opm::ConvergenceReportQueue::OutputRequest::currentStep
int currentStep
Current timestep within reportStep.
Definition ExtraConvergenceOutputThread.hpp:69
Opm::ConvergenceReportQueue::OutputRequest::reportStep
int reportStep
Current report step.
Definition ExtraConvergenceOutputThread.hpp:65
Opm::ConvergenceReportQueue::OutputRequest::reports
std::vector< ConvergenceReport > reports
Convergence metrics for each non-linear ieration in the currentStep.
Definition ExtraConvergenceOutputThread.hpp:73