Use shared_ptr to signal lifetime requirement
The code is now allowed to use C++11, where shared_ptr is available in the standard. To specify that the parser object must be present for the output writer in its entire lifetime, we require to be passed a shared_ptr. (This can be faked for local storage anyway).
This commit is contained in:
parent
cd3e047957
commit
568e597561
@ -45,7 +45,7 @@ private:
|
||||
|
||||
/// Psuedo-constructor, can appear in template
|
||||
template <typename Format> unique_ptr <OutputWriter>
|
||||
create (const ParameterGroup& params, const EclipseGridParser& parser) {
|
||||
create (const ParameterGroup& params, std::shared_ptr <EclipseGridParser> parser) {
|
||||
return unique_ptr <OutputWriter> (new Format (params, parser));
|
||||
}
|
||||
|
||||
@ -55,9 +55,9 @@ create (const ParameterGroup& params, const EclipseGridParser& parser) {
|
||||
///
|
||||
/// If you want to add more possible writer formats, just add them
|
||||
/// to the list below!
|
||||
typedef map <const char*,
|
||||
unique_ptr <OutputWriter> (*)(const ParameterGroup&,
|
||||
const EclipseGridParser&)> map_t;
|
||||
typedef map <const char*, unique_ptr <OutputWriter> (*)(
|
||||
const ParameterGroup&,
|
||||
std::shared_ptr <EclipseGridParser>)> map_t;
|
||||
map_t FORMATS = {
|
||||
{ "output_ecl", &create <EclipseWriter> },
|
||||
};
|
||||
@ -66,7 +66,7 @@ map_t FORMATS = {
|
||||
|
||||
unique_ptr <OutputWriter>
|
||||
OutputWriter::create (const ParameterGroup& params,
|
||||
const EclipseGridParser& parser) {
|
||||
std::shared_ptr<EclipseGridParser> parser) {
|
||||
// allocate a list which will be filled with writers. this list
|
||||
// is initially empty (no output).
|
||||
MultiWriter::ptr_t list (new MultiWriter::writers_t ());
|
||||
|
@ -41,7 +41,8 @@ class WellState;
|
||||
* \example
|
||||
* \code{.cpp}
|
||||
* ParameterGroup params (argc, argv, false);
|
||||
* EclipseGridParser parser (params.get <string> ("deck_filename");
|
||||
* auto parser = std::make_shared <EclipseGridParser> (
|
||||
* params.get <string> ("deck_filename"));
|
||||
*
|
||||
* std::unique_ptr <OutputWriter> writer =
|
||||
* OutputWriter::create (params, parser);
|
||||
@ -87,7 +88,7 @@ public:
|
||||
*/
|
||||
static std::unique_ptr <OutputWriter>
|
||||
create (const parameter::ParameterGroup& params,
|
||||
const EclipseGridParser& parser);
|
||||
std::shared_ptr <EclipseGridParser> parser);
|
||||
};
|
||||
|
||||
} // namespace Opm
|
||||
|
@ -677,30 +677,30 @@ using namespace Opm::internal;
|
||||
|
||||
void EclipseWriter::writeInit(const SimulatorTimer &timer) {
|
||||
/* Grid files */
|
||||
EclipseGrid ecl_grid = EclipseGrid::make (eclipseParser_);
|
||||
EclipseGrid ecl_grid = EclipseGrid::make (*parser_);
|
||||
ecl_grid.write (outputDir_, baseName_, timer);
|
||||
|
||||
EclipseInit fortio = EclipseInit::make (outputDir_, baseName_, timer);
|
||||
fortio.writeHeader (ecl_grid,
|
||||
timer,
|
||||
eclipseParser_,
|
||||
*parser_,
|
||||
uses_);
|
||||
|
||||
fortio.writeKeyword<double> ("PERMX", eclipseParser_);
|
||||
fortio.writeKeyword<double> ("PERMY", eclipseParser_);
|
||||
fortio.writeKeyword<double> ("PERMZ", eclipseParser_);
|
||||
fortio.writeKeyword<double> ("PERMX", *parser_);
|
||||
fortio.writeKeyword<double> ("PERMY", *parser_);
|
||||
fortio.writeKeyword<double> ("PERMZ", *parser_);
|
||||
|
||||
/* Summary files */
|
||||
sum_ = std::move (std::unique_ptr <EclipseSummary> (
|
||||
new EclipseSummary (outputDir_,
|
||||
baseName_,
|
||||
timer,
|
||||
eclipseParser_)));
|
||||
*parser_)));
|
||||
|
||||
// TODO: Only create report variables that are requested with keywords
|
||||
// (e.g. "WOPR") in the input files, and only for those wells that are
|
||||
// mentioned in those keywords
|
||||
const int numWells = eclipseParser_.getWELSPECS().welspecs.size();
|
||||
const int numWells = parser_->getWELSPECS().welspecs.size();
|
||||
for (int phaseCounter = 0;
|
||||
phaseCounter != BlackoilPhases::MaxNumPhases;
|
||||
++phaseCounter) {
|
||||
@ -718,7 +718,7 @@ void EclipseWriter::writeInit(const SimulatorTimer &timer) {
|
||||
// W{O,G,W}{I,P}R
|
||||
sum_->add (std::unique_ptr <EclipseWellReport> (
|
||||
new EclipseWellRate (*sum_,
|
||||
eclipseParser_,
|
||||
*parser_,
|
||||
whichWell,
|
||||
uses_,
|
||||
phase,
|
||||
@ -726,7 +726,7 @@ void EclipseWriter::writeInit(const SimulatorTimer &timer) {
|
||||
// W{O,G,W}{I,P}T
|
||||
sum_->add (std::unique_ptr <EclipseWellReport> (
|
||||
new EclipseWellTotal (*sum_,
|
||||
eclipseParser_,
|
||||
*parser_,
|
||||
whichWell,
|
||||
uses_,
|
||||
phase,
|
||||
@ -755,7 +755,7 @@ void EclipseWriter::writeTimeStep(
|
||||
timer);
|
||||
rst.writeHeader (timer,
|
||||
uses_,
|
||||
eclipseParser_,
|
||||
*parser_,
|
||||
pas.size ());
|
||||
EclipseSolution sol (rst);
|
||||
|
||||
@ -800,9 +800,9 @@ void EclipseWriter::writeTimeStep(
|
||||
|
||||
EclipseWriter::EclipseWriter (
|
||||
const ParameterGroup& params,
|
||||
const EclipseGridParser& parser)
|
||||
: eclipseParser_ (parser)
|
||||
, uses_ (phaseUsageFromDeck (parser)) {
|
||||
std::shared_ptr <EclipseGridParser> parser)
|
||||
: parser_ (parser)
|
||||
, uses_ (phaseUsageFromDeck (*parser)) {
|
||||
|
||||
// get the base name from the name of the deck
|
||||
using boost::filesystem::path;
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
* binary files using ERT.
|
||||
*/
|
||||
EclipseWriter(const parameter::ParameterGroup& params,
|
||||
const EclipseGridParser& eclipseParser);
|
||||
std::shared_ptr <EclipseGridParser> parser);
|
||||
|
||||
/*!
|
||||
* \brief Write the static eclipse data (grid, PVT curves, etc) to disk
|
||||
@ -78,7 +78,7 @@ public:
|
||||
const WellState& wellState);
|
||||
|
||||
private:
|
||||
const EclipseGridParser& eclipseParser_;
|
||||
std::shared_ptr <EclipseGridParser> parser_;
|
||||
std::string outputDir_;
|
||||
std::string baseName_;
|
||||
PhaseUsage uses_; // active phases in the input deck
|
||||
|
Loading…
Reference in New Issue
Block a user