Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions opm/io/eclipse/OutputStream.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (c) 2019 Equinor ASA
Copyright (c) 2026 OPM-OP AS

This file is part of the Open Porous Media project (OPM).

Expand Down Expand Up @@ -683,6 +684,28 @@ namespace {
};
}

std::vector<int>
makeRuntimeiDate(const SummarySpecification::StartTime start)
{
const auto timepoint = std::chrono::system_clock::to_time_t(start);
const auto tm = *std::gmtime(&timepoint);

// { Day, Month, Year, Hour, Minute, Seconds }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is incorrect. Also, please extract a helper function to form the tm object so that we may reuse the logic in both makeStartDate() and makeRuntimeiDate().


return {
tm.tm_year + 1900,

// 1..12 1..32
tm.tm_mon + 1, tm.tm_mday,

// 0..23 0..59
tm.tm_hour, tm.tm_min,

// 0..59
std::min(tm.tm_sec, 59)
};
}

std::vector<int>
makeDimens(const int nparam,
const std::array<int, 3>& cartDims,
Expand Down Expand Up @@ -713,12 +736,14 @@ SummarySpecification(const ResultSet& rset,
const UnitConvention uconv,
const std::array<int,3>& cartDims,
const RestartSpecification& restart,
const StartTime start)
: unit_ (unitConvention(uconv))
, restartStep_(makeRestartStep(restart))
, cartDims_ (cartDims)
, startDate_ (start)
, restart_ (restartRoot(restart))
const StartTime start,
const StartTime computeStart)
: unit_ (unitConvention(uconv))
, restartStep_ (makeRestartStep(restart))
, cartDims_ (cartDims)
, startDate_ (start)
, computeStart_ (computeStart)
, restart_ (restartRoot(restart))
{
const auto fname = outputFileName(rset, FileExtension::smspec(fmt.set));

Expand Down Expand Up @@ -755,7 +780,9 @@ operator=(SummarySpecification&& rhs)

void
Opm::EclIO::OutputStream::
SummarySpecification::write(const Parameters& params)
SummarySpecification::write(const Parameters& params,
const bool simulationFinished, const int currentStep,
const int basic)
{
this->rewindStream();

Expand All @@ -778,6 +805,21 @@ SummarySpecification::write(const Parameters& params)

smspec.write("STARTDAT", makeStartDate(this->startDate_));

// Create and write RUNTIMEI
std::vector<int> runtimei(50, 0);
runtimei[0] = simulationFinished ? 2 : 1;
runtimei[1] = (this->restartStep_ == -1)? 1 : this->restartStep_+1;
runtimei[2] = currentStep + 1;
const auto computeStart = makeRuntimeiDate(this->computeStart_);
std::copy(computeStart.begin(), computeStart.end(), runtimei.begin()+3);

using std::chrono::system_clock;
const auto now = makeRuntimeiDate(Opm::TimeService::now());
std::copy(now.begin(), now.end(), runtimei.begin()+9);
runtimei[34] = basic;

smspec.write("RUNTIMEI", runtimei);
Comment on lines +808 to +821
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a helper function for this so that we don't have to have this amount of local state and logic directly in the body of the write() function. E.g.,

smspec.write("STARTDAT", makeStartDate(this->startDate_));

smspec.write("RUNTIMEI", makeRuntimeI(...));

this->flushStream();


this->flushStream();
}

Expand Down
15 changes: 13 additions & 2 deletions opm/io/eclipse/OutputStream.hpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please tag each parameter as [in], [out], or [inout] as appropriate in the new Doxygen function description.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (c) 2019 Equinor ASA
Copyroght (c) 2026 OPM-OP AS

This file is part of the Open Porous Media project (OPM).

Expand Down Expand Up @@ -414,7 +415,8 @@ namespace Opm { namespace EclIO { namespace OutputStream {
const UnitConvention uconv,
const std::array<int,3>& cartDims,
const RestartSpecification& restart,
const StartTime start);
const StartTime start,
const StartTime computeStart);

~SummarySpecification();

Expand All @@ -424,13 +426,22 @@ namespace Opm { namespace EclIO { namespace OutputStream {
SummarySpecification& operator=(const SummarySpecification& rhs) = delete;
SummarySpecification& operator=(SummarySpecification&& rhs);

void write(const Parameters& params);
/// \brief wirte SMSPEC file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit: "wirte" ➡️ "Write" (with upper case "W").

///
/// \param simulationFinished whether the simulation has finished (i.e.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upper case "W" in "Whether".

/// this is the last written for it)
/// \param currentStep Index of the current report step
/// \param basic The value assigned to BASIC in RPRTRST
void write(const Parameters& params, const bool simulationFinished,
const int currentStep, const int basic);

private:
int unit_;
int restartStep_;
std::array<int,3> cartDims_;
StartTime startDate_;
/// \brief When the simulation started
StartTime computeStart_;
std::vector<PaddedOutputString<8>> restart_;

/// Summary specification (SMSPEC) file output stream.
Expand Down
22 changes: 16 additions & 6 deletions opm/output/eclipse/Summary.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
Copyright 2021 Equinor ASA.
Copyright 2019 Equinor ASA.
Copyright 2016 Statoil ASA.
Copyright 2016-2021 Equinor ASA.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only add new copyright statements here. Don't change the original ones.

Copyright 2026 OPM-OP AS.

This file is part of the Open Porous Media project (OPM).

Expand Down Expand Up @@ -4950,13 +4949,16 @@ class SMSpecStreamDeferredCreation
{
return std::make_unique<Spec>(rset, fmt, this->uconv(),
this->cartDims_, this->restart_,
this->start_);
this->start_,
this->computeStart_);
}

private:
Opm::UnitSystem::UnitType utype_;
std::array<int,3> cartDims_;
Spec::StartTime start_;
/// \brief Time when the simulation started.
Spec::StartTime computeStart_;
Spec::RestartSpecification restart_{};

Spec::UnitConvention uconv() const;
Expand All @@ -4970,6 +4972,8 @@ SMSpecStreamDeferredCreation(const Opm::InitConfig& initcfg,
: utype_ (utype)
, cartDims_(grid.getNXYZ())
, start_ (Opm::TimeService::from_time_t(start))
// This is not exactly when the simulation started, but should make the tools happy enough.
, computeStart_(Opm::TimeService::now())
{
if (initcfg.restartRequested()) {
this->restart_.root = initcfg.getRestartRootNameInput();
Expand Down Expand Up @@ -5278,10 +5282,16 @@ void Opm::out::Summary::SummaryImplementation::write(const bool is_final_summary
return;
}

const auto& last = this->lastUnwritten();

this->createSMSpecIfNecessary();

if (this->prevReportStepID_ < this->lastUnwritten().seq) {
this->smspec_->write(this->outputParameters_.summarySpecification());
if (this->prevReportStepID_ < last.seq) {
Comment on lines 5284 to +5289
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better written as

this->createSMSpecIfNecessary();

if (const auto lastSeq = this->lastUnWritten().seq;
    this->prevReportStepID_ < lastSeq)
{
    // ...
}

That way we won't have to introduce the otherwise unused last object.

this->smspec_->write(this->outputParameters_.summarySpecification(),
// pass additional parameters for RUNTIMEI keyword
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is meaningless. Please remove it.

is_final_summary, last.seq,
sched_.get()[last.seq].get<RSTConfig>().get()
.basic.value_or(0));
}

for (auto i = 0*this->numUnwritten_; i < this->numUnwritten_; ++i) {
Expand Down
Loading