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
25 changes: 12 additions & 13 deletions opm/input/eclipse/Generator/KeywordGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@
#include <string>

#include <fmt/format.h>
#include <fmt/std.h>

namespace {

void updateFile(const std::string& newContent, const std::string& filename)
void updateFile(const std::string& newContent, const std::filesystem::path& filename)
{
Opm::KeywordGenerator::ensurePath(filename);

std::ofstream { filename } << newContent;
}

void write_file(const std::string& content,
const std::string& file,
const bool verbose,
const std::string& desc)
void write_file(const std::string& content,
const std::filesystem::path& file,
const bool verbose,
const std::string& desc)
{
updateFile(content, file);

Expand All @@ -55,10 +56,10 @@ namespace {
}
}

void write_file(const std::stringstream& stream,
const std::string& file,
const bool verbose,
const std::string& desc)
void write_file(const std::stringstream& stream,
const std::filesystem::path& file,
const bool verbose,
const std::string& desc)
{
write_file(stream.str(), file, verbose, desc);
}
Expand Down Expand Up @@ -89,17 +90,15 @@ namespace Opm {
"namespace Opm::ParserKeywords {{\n\n", suffix);
}

void KeywordGenerator::ensurePath(const std::string& file_name)
void KeywordGenerator::ensurePath(const std::filesystem::path& file)
{
std::filesystem::path file(file_name);

if (!std::filesystem::is_directory(file.parent_path())) {
std::filesystem::create_directories(file.parent_path());
}
}

void KeywordGenerator::updateFile(const std::stringstream& newContent,
const std::string& filename)
const std::filesystem::path& filename)
{
::updateFile(newContent.str(), filename);
}
Expand Down
5 changes: 3 additions & 2 deletions opm/input/eclipse/Generator/KeywordGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef KEYWORD_GENERATOR_HPP
#define KEYWORD_GENERATOR_HPP

#include <filesystem>
#include <string>

namespace Opm {
Expand All @@ -33,12 +34,12 @@ namespace Opm {
public:
explicit KeywordGenerator(bool verbose);

static void ensurePath(const std::string& file_name);
static void ensurePath(const std::filesystem::path& file);
static std::string endTest();
static std::string startTest(const std::string& test_name);
static std::string headerHeader(const std::string&);
static void updateFile(const std::stringstream& newContent,
const std::string& filename);
const std::filesystem::path& filename);

void updateBuiltInHeader(const KeywordLoader& loader,
const std::string& headerBuildPath,
Expand Down
12 changes: 7 additions & 5 deletions opm/input/eclipse/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ bool parseState( ParserState& parserState, const Parser& parser, ErrorGuard& err
return parse(deck, context).getInputGrid();
}

Deck Parser::parseFile(const std::string& dataFileName,
Deck Parser::parseFile(const std::filesystem::path& dataFileName,
const ParseContext& parseContext,
ErrorGuard& errors,
const std::vector<Ecl::SectionType>& sections) const
Expand Down Expand Up @@ -1728,8 +1728,10 @@ bool parseState( ParserState& parserState, const Parser& parser, ErrorGuard& err
2. The relative/abolute status of the path is retained.
*/

// has_root_directory() is the portable spelling of the former leading-'/' test;
// is_absolute() implies it but would not keep a rooted path without a root name.
std::string data_file;
if (dataFileName[0] == '/')
if (dataFileName.has_root_directory())
data_file = std::filesystem::canonical(dataFileName).generic_string();
else
data_file = std::filesystem::proximate(std::filesystem::canonical(dataFileName)).generic_string();
Expand All @@ -1753,20 +1755,20 @@ bool parseState( ParserState& parserState, const Parser& parser, ErrorGuard& err
return std::move( parserState.deck );
}

Deck Parser::parseFile(const std::string& dataFileName,
Deck Parser::parseFile(const std::filesystem::path& dataFileName,
const ParseContext& parseContext) const {
ErrorGuard errors;
return this->parseFile(dataFileName, parseContext, errors, {});
}

Deck Parser::parseFile(const std::string& dataFileName,
Deck Parser::parseFile(const std::filesystem::path& dataFileName,
const ParseContext& parseContext,
const std::vector<Opm::Ecl::SectionType>& sections) const {
ErrorGuard errors;
return this->parseFile(dataFileName, parseContext, errors, sections);
}

Deck Parser::parseFile(const std::string& dataFileName) const {
Deck Parser::parseFile(const std::filesystem::path& dataFileName) const {
ErrorGuard errors;
return this->parseFile(dataFileName, ParseContext(), errors);
}
Expand Down
8 changes: 4 additions & 4 deletions opm/input/eclipse/Parser/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ namespace Opm {
static std::string stripComments(const std::string& inputString);

/// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned.
Deck parseFile(const std::string &dataFile,
Deck parseFile(const std::filesystem::path& dataFile,
const ParseContext&,
ErrorGuard& errors,
const std::vector<Opm::Ecl::SectionType>& sections = {}) const;

Deck parseFile(const std::string&,
Deck parseFile(const std::filesystem::path&,
const ParseContext&) const;

Deck parseFile(const std::string&,
Deck parseFile(const std::filesystem::path&,
const ParseContext&,
const std::vector<Opm::Ecl::SectionType>& sections
) const;

Deck parseFile(const std::string& datafile) const;
Deck parseFile(const std::filesystem::path& datafile) const;

Deck parseString(const std::string &data,
const ParseContext&,
Expand Down
7 changes: 4 additions & 3 deletions opm/io/eclipse/EGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
#include <string>

#include <fmt/format.h>
#include <fmt/std.h>

namespace Opm::EclIO {

using NNCentry = std::tuple<int, int, int, int, int, int, float>;

EGrid::EGrid(const std::string& filename, const std::string& grid_name)
EGrid::EGrid(const std::filesystem::path& filename, const std::string& grid_name)
: EclFile(filename), inputFileName { filename }, m_grid_name {grid_name}
{
initFileName = inputFileName.parent_path() / inputFileName.stem();
Expand Down Expand Up @@ -259,7 +260,7 @@ void EGrid::load_nnc_data()
nnc2_array = getImpl(nnc2_array_index, Opm::EclIO::INTE, inte_array, "inte");

if ((std::filesystem::exists(initFileName)) && (nnc1_array.size() > 0)){
Opm::EclIO::EInit init(initFileName.generic_string());
Opm::EclIO::EInit init(initFileName);

auto init_dims = init.grid_dimension(m_grid_name);
int init_nactive = init.activeCells(m_grid_name);
Expand Down Expand Up @@ -540,7 +541,7 @@ std::vector<float> EGrid:: get_zcorn_from_disk(int layer, bool bottom)
fileH.open(inputFileName, std::ios::in | std::ios::binary);

if (!fileH)
throw std::runtime_error("Can not open EGrid file" + this->inputFilename);
throw std::runtime_error(fmt::format("Can not open EGrid file {}", this->inputFilename));

std::string arrName(8,' ');
eclArrType arrType;
Expand Down
2 changes: 1 addition & 1 deletion opm/io/eclipse/EGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Opm { namespace EclIO {
class EGrid : public EclFile
{
public:
explicit EGrid(const std::string& filename, const std::string& grid_name = "global");
explicit EGrid(const std::filesystem::path& filename, const std::string& grid_name = "global");

int global_index(int i, int j, int k) const;
int active_index(int i, int j, int k) const;
Expand Down
2 changes: 1 addition & 1 deletion opm/io/eclipse/EInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Opm::EclIO {

EInit::EInit(const std::string &filename) : EclFile(filename)
EInit::EInit(const std::filesystem::path &filename) : EclFile(filename)
{
std::string lgrname;

Expand Down
2 changes: 1 addition & 1 deletion opm/io/eclipse/EInit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Opm { namespace EclIO {
class EInit : public EclFile
{
public:
explicit EInit(const std::string& filename);
explicit EInit(const std::filesystem::path& filename);

const std::vector<std::string>& list_of_lgrs() const { return lgr_names; }

Expand Down
2 changes: 1 addition & 1 deletion opm/io/eclipse/ERft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace Opm::EclIO {

ERft::ERft(const std::string &filename) : EclFile(filename)
ERft::ERft(const std::filesystem::path& filename) : EclFile(filename)
{
loadData();
std::vector<int> first;
Expand Down
3 changes: 2 additions & 1 deletion opm/io/eclipse/ERft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <ctime>
#include <map>
#include <set>
#include <filesystem>
#include <string>
#include <tuple>
#include <utility>
Expand All @@ -34,7 +35,7 @@ namespace Opm { namespace EclIO {
class ERft : public EclFile
{
public:
explicit ERft(const std::string &filename);
explicit ERft(const std::filesystem::path& filename);

using RftDate = std::tuple<int,int,int>;
template <typename T>
Expand Down
10 changes: 6 additions & 4 deletions opm/io/eclipse/ERsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#include <algorithm>
#include <chrono>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <string>

#include <fmt/format.h>
#include <fmt/std.h>

namespace Opm {
namespace EclIO {
Expand All @@ -41,11 +43,11 @@ constexpr std::size_t num_columns = 10;
constexpr std::size_t column_width = 13;


std::deque<std::string> load(const std::string& fname) {
std::deque<std::string> load(const std::filesystem::path& fname) {
std::deque<std::string> lines;
std::ifstream is(fname.c_str());
std::ifstream is(fname);
if (!is.good())
throw std::invalid_argument("Can not open: " + fname + " for reading");
throw std::invalid_argument(fmt::format("Can not open: {} for reading", fname));

std::string line;
while(std::getline(is, line)) {
Expand Down Expand Up @@ -277,7 +279,7 @@ bool ERsm::has(const std::string& key) const {
return this->vectors.count(key) == 1;
}

ERsm::ERsm(const std::string& fname) {
ERsm::ERsm(const std::filesystem::path& fname) {
auto lines = load(fname);
std::size_t vector_length = 0;
while (!lines.empty())
Expand Down
3 changes: 2 additions & 1 deletion opm/io/eclipse/ERsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define OPM_IO_ERSM_HPP

#include <deque>
#include <filesystem>
#include <string>
#include <unordered_map>
#include <variant>
Expand Down Expand Up @@ -56,7 +57,7 @@ struct Vector{


public:
explicit ERsm(const std::string& fname);
explicit ERsm(const std::filesystem::path& fname);

const std::vector<TimeStampUTC>& dates() const;
const std::vector<double>& days() const;
Expand Down
2 changes: 1 addition & 1 deletion opm/io/eclipse/ERst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace {

namespace Opm::EclIO {

ERst::ERst(const std::string& filename)
ERst::ERst(const std::filesystem::path& filename)
: EclFile(filename)
{
if (this->hasKey("SEQNUM")) {
Expand Down
3 changes: 2 additions & 1 deletion opm/io/eclipse/ERst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cstddef>
#include <ios>
#include <map>
#include <filesystem>
#include <string>
#include <unordered_map>
#include <vector>
Expand All @@ -37,7 +38,7 @@ namespace Opm { namespace EclIO {
class ERst : public EclFile
{
public:
explicit ERst(const std::string& filename);
explicit ERst(const std::filesystem::path& filename);

bool hasReportStepNumber(int number) const;
bool hasArray(const std::string& name, int number) const;
Expand Down
13 changes: 7 additions & 6 deletions opm/io/eclipse/ESmry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <vector>

#include <fmt/format.h>
#include <fmt/std.h>

/*

Expand Down Expand Up @@ -120,7 +121,7 @@ bool is_well_completion(const std::string& keyword)

namespace Opm::EclIO {

ESmry::ESmry(const std::string &filename, bool loadBaseRunData) :
ESmry::ESmry(const std::filesystem::path &filename, bool loadBaseRunData) :
inputFileName { filename },
summaryNodes { }
{
Expand Down Expand Up @@ -163,7 +164,7 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData) :

// Read data from the summary into local data members.
{
smspecList.emplace_back(smspec_file.string());
smspecList.emplace_back(smspec_file);

auto arrays = smspecList.back().getList();
std::vector<int> vectIndices;
Expand Down Expand Up @@ -272,7 +273,7 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData) :
if ((rstRootN.string() != "") && (loadBaseRunData)) {

if (! std::filesystem::exists(pathRstFile))
OPM_THROW(std::runtime_error, "path to restart file not found, '" + pathRstFile.string() + "'");
OPM_THROW(std::runtime_error, fmt::format("path to restart file not found, {}", pathRstFile));

auto abs_rst_file = std::filesystem::canonical(pathRstFile) / rstRootN;
std::filesystem::path rel_path;
Expand Down Expand Up @@ -310,7 +311,7 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData) :
baseRunFmt = true;
}

smspecList.emplace_back(EclFile(rstFile.string()));
smspecList.emplace_back(EclFile(rstFile));

auto arrays = smspecList.back().getList();
std::vector<int> vectIndices;
Expand Down Expand Up @@ -1091,7 +1092,7 @@ bool ESmry::make_esmry_file()
std::filesystem::path smryDataFile = path / rootName;
smryDataFile.replace_extension(".ESMRY");

if (Opm::EclIO::fileExists(smryDataFile.generic_string()))
if (Opm::EclIO::fileExists(smryDataFile))
{
return false;

Expand Down Expand Up @@ -1131,7 +1132,7 @@ bool ESmry::make_esmry_file()
std::ranges::transform(keyword, std::back_inserter(units),
[this](const auto& key) { return kwunits.at(key); });

Opm::EclIO::EclOutput outFile(smryDataFile.generic_string(), false, std::ios::out);
Opm::EclIO::EclOutput outFile(smryDataFile, false, std::ios::out);

outFile.write<int>("START", start_date_vect);

Expand Down
2 changes: 1 addition & 1 deletion opm/io/eclipse/ESmry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ESmry
public:

// input is smspec (or fsmspec file)
explicit ESmry(const std::string& filename, bool loadBaseRunData=false);
explicit ESmry(const std::filesystem::path& filename, bool loadBaseRunData=false);

int numberOfVectors() const { return nVect; }

Expand Down
Loading