convert the EclipseGridInspector to opm-parser
that one is completely unused in opm-core (*booo*!), but used quite a bit in dune-cornerpoint and dune-porsol, so let's keep it for now...
This commit is contained in:
parent
a97db3f157
commit
a313dd86d6
@ -38,8 +38,9 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include <opm/core/io/eclipse/EclipseGridInspector.hpp>
|
||||
#include <opm/core/io/eclipse/EclipseGridParser.hpp>
|
||||
#include <opm/core/io/eclipse/SpecialEclipseFields.hpp>
|
||||
#include <opm/core/utility/ErrorMacros.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <stdexcept>
|
||||
#include <numeric>
|
||||
#include <cmath>
|
||||
@ -51,27 +52,42 @@
|
||||
namespace Opm
|
||||
{
|
||||
|
||||
EclipseGridInspector::EclipseGridInspector(const EclipseGridParser& parser)
|
||||
: parser_(parser)
|
||||
EclipseGridInspector::EclipseGridInspector(const EclipseGridParser& oldParser)
|
||||
{
|
||||
std::vector<std::string> keywords;
|
||||
keywords.push_back("COORD");
|
||||
keywords.push_back("ZCORN");
|
||||
Opm::ParserConstPtr parser(new Opm::Parser());
|
||||
newParserDeck_ = parser->parseFile(oldParser.deckFileName());
|
||||
|
||||
if (!parser_.hasFields(keywords)) {
|
||||
OPM_THROW(std::runtime_error, "Needed field is missing in file");
|
||||
init_();
|
||||
}
|
||||
|
||||
|
||||
EclipseGridInspector::EclipseGridInspector(Opm::DeckConstPtr newParserDeck)
|
||||
: newParserDeck_(newParserDeck)
|
||||
{
|
||||
init_();
|
||||
}
|
||||
|
||||
void EclipseGridInspector::init_()
|
||||
{
|
||||
if (!newParserDeck_->hasKeyword("COORD")) {
|
||||
OPM_THROW(std::runtime_error, "Needed field \"COORD\" is missing in file");
|
||||
}
|
||||
if (!newParserDeck_->hasKeyword("ZCORN")) {
|
||||
OPM_THROW(std::runtime_error, "Needed field \"ZCORN\" is missing in file");
|
||||
}
|
||||
|
||||
if (parser_.hasField("SPECGRID")) {
|
||||
const SPECGRID& sgr = parser.getSPECGRID();
|
||||
logical_gridsize_[0] = sgr.dimensions[0];
|
||||
logical_gridsize_[1] = sgr.dimensions[1];
|
||||
logical_gridsize_[2] = sgr.dimensions[2];
|
||||
} else if (parser_.hasField("DIMENS")) {
|
||||
const std::vector<int>& dim = parser.getIntegerValue("DIMENS");
|
||||
logical_gridsize_[0] = dim[0];
|
||||
logical_gridsize_[1] = dim[1];
|
||||
logical_gridsize_[2] = dim[2];
|
||||
if (newParserDeck_->hasKeyword("SPECGRID")) {
|
||||
Opm::DeckRecordConstPtr specgridRecord =
|
||||
newParserDeck_->getKeyword("SPECGRID")->getRecord(0);
|
||||
logical_gridsize_[0] = specgridRecord->getItem("NX")->getInt(0);
|
||||
logical_gridsize_[1] = specgridRecord->getItem("NY")->getInt(0);
|
||||
logical_gridsize_[2] = specgridRecord->getItem("NZ")->getInt(0);
|
||||
} else if (newParserDeck_->hasKeyword("DIMENS")) {
|
||||
Opm::DeckRecordConstPtr dimensRecord =
|
||||
newParserDeck_->getKeyword("DIMENS")->getRecord(0);
|
||||
logical_gridsize_[0] = dimensRecord->getItem("NX")->getInt(0);
|
||||
logical_gridsize_[1] = dimensRecord->getItem("NY")->getInt(0);
|
||||
logical_gridsize_[2] = dimensRecord->getItem("NZ")->getInt(0);
|
||||
} else {
|
||||
OPM_THROW(std::runtime_error, "Found neither SPECGRID nor DIMENS in file. At least one is needed.");
|
||||
}
|
||||
@ -90,12 +106,14 @@ EclipseGridInspector::EclipseGridInspector(const EclipseGridParser& parser)
|
||||
std::pair<double,double> EclipseGridInspector::cellDips(int i, int j, int k) const
|
||||
{
|
||||
checkLogicalCoords(i, j, k);
|
||||
const std::vector<double>& pillc = parser_.getFloatingPointValue("COORD");
|
||||
const std::vector<double>& pillc =
|
||||
newParserDeck_->getKeyword("COORD")->getSIDoubleData();
|
||||
int num_pillars = (logical_gridsize_[0] + 1)*(logical_gridsize_[1] + 1);
|
||||
if (6*num_pillars != int(pillc.size())) {
|
||||
throw std::runtime_error("Wrong size of COORD field.");
|
||||
}
|
||||
const std::vector<double>& z = parser_.getFloatingPointValue("ZCORN");
|
||||
const std::vector<double>& z =
|
||||
newParserDeck_->getKeyword("ZCORN")->getSIDoubleData();
|
||||
int num_cells = logical_gridsize_[0]*logical_gridsize_[1]*logical_gridsize_[2];
|
||||
if (8*num_cells != int(z.size())) {
|
||||
throw std::runtime_error("Wrong size of ZCORN field");
|
||||
@ -198,12 +216,14 @@ double EclipseGridInspector::cellVolumeVerticalPillars(int i, int j, int k) cons
|
||||
{
|
||||
// Checking parameters and obtaining values from parser.
|
||||
checkLogicalCoords(i, j, k);
|
||||
const std::vector<double>& pillc = parser_.getFloatingPointValue("COORD");
|
||||
const std::vector<double>& pillc =
|
||||
newParserDeck_->getKeyword("COORD")->getSIDoubleData();
|
||||
int num_pillars = (logical_gridsize_[0] + 1)*(logical_gridsize_[1] + 1);
|
||||
if (6*num_pillars != int(pillc.size())) {
|
||||
throw std::runtime_error("Wrong size of COORD field.");
|
||||
}
|
||||
const std::vector<double>& z = parser_.getFloatingPointValue("ZCORN");
|
||||
const std::vector<double>& z =
|
||||
newParserDeck_->getKeyword("ZCORN")->getSIDoubleData();
|
||||
int num_cells = logical_gridsize_[0]*logical_gridsize_[1]*logical_gridsize_[2];
|
||||
if (8*num_cells != int(z.size())) {
|
||||
throw std::runtime_error("Wrong size of ZCORN field");
|
||||
@ -261,12 +281,12 @@ void EclipseGridInspector::checkLogicalCoords(int i, int j, int k) const
|
||||
|
||||
std::array<double, 6> EclipseGridInspector::getGridLimits() const
|
||||
{
|
||||
if (! (parser_.hasField("COORD") && parser_.hasField("ZCORN") && parser_.hasField("SPECGRID")) ) {
|
||||
if (! (newParserDeck_->hasKeyword("COORD") && newParserDeck_->hasKeyword("ZCORN") && newParserDeck_->hasKeyword("SPECGRID")) ) {
|
||||
throw std::runtime_error("EclipseGridInspector: Grid does not have SPECGRID, COORD, and ZCORN, can't find dimensions.");
|
||||
}
|
||||
|
||||
std::vector<double> coord = parser_.getFloatingPointValue("COORD");
|
||||
std::vector<double> zcorn = parser_.getFloatingPointValue("ZCORN");
|
||||
std::vector<double> coord = newParserDeck_->getKeyword("COORD")->getSIDoubleData();
|
||||
std::vector<double> zcorn = newParserDeck_->getKeyword("ZCORN")->getSIDoubleData();
|
||||
|
||||
double xmin = +DBL_MAX;
|
||||
double xmax = -DBL_MAX;
|
||||
@ -315,7 +335,7 @@ std::array<int, 3> EclipseGridInspector::gridSize() const
|
||||
std::array<double, 8> EclipseGridInspector::cellZvals(int i, int j, int k) const
|
||||
{
|
||||
// Get the zcorn field.
|
||||
const std::vector<double>& z = parser_.getFloatingPointValue("ZCORN");
|
||||
const std::vector<double>& z = newParserDeck_->getKeyword("ZCORN")->getSIDoubleData();
|
||||
int num_cells = logical_gridsize_[0]*logical_gridsize_[1]*logical_gridsize_[2];
|
||||
if (8*num_cells != int(z.size())) {
|
||||
throw std::runtime_error("Wrong size of ZCORN field");
|
||||
|
@ -38,6 +38,9 @@
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
#include <opm/core/io/eclipse/EclipseGridParser.hpp>
|
||||
#include <opm/core/io/eclipse/SpecialEclipseFields.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
@ -52,9 +55,6 @@ namespace Opm
|
||||
@author Atgeirr F. Rasmussen <atgeirr@sintef.no>
|
||||
@date 2008/06/02 09:46:08
|
||||
*/
|
||||
|
||||
class EclipseGridParser;
|
||||
|
||||
class EclipseGridInspector
|
||||
{
|
||||
public:
|
||||
@ -62,6 +62,10 @@ public:
|
||||
/// The parser must already have read an Eclipse file.
|
||||
EclipseGridInspector(const EclipseGridParser& parser);
|
||||
|
||||
/// Constructor taking a parser as argument.
|
||||
/// The parser must already have read an Eclipse file.
|
||||
EclipseGridInspector(Opm::DeckConstPtr newParserDeck);
|
||||
|
||||
/// Assuming that the pillars are vertical, compute the
|
||||
/// volume of the cell given by logical coordinates (i, j, k).
|
||||
double cellVolumeVerticalPillars(int i, int j, int k) const;
|
||||
@ -94,8 +98,9 @@ public:
|
||||
std::array<double, 8> cellZvals(int i, int j, int k) const;
|
||||
|
||||
private:
|
||||
const EclipseGridParser& parser_;
|
||||
Opm::DeckConstPtr newParserDeck_;
|
||||
int logical_gridsize_[3];
|
||||
void init_();
|
||||
void checkLogicalCoords(int i, int j, int k) const;
|
||||
};
|
||||
|
||||
|
@ -221,7 +221,8 @@ EclipseGridParser::EclipseGridParser(const string& filename, bool convert_to_SI)
|
||||
// Store directory of filename
|
||||
boost::filesystem::path p(filename);
|
||||
directory_ = p.parent_path().string();
|
||||
ifstream is(filename.c_str());
|
||||
deckFileName_ = p.string();
|
||||
ifstream is(deckFileName_.c_str());
|
||||
if (!is) {
|
||||
cerr << "Unable to open file " << filename << endl;
|
||||
throw exception();
|
||||
|
@ -98,6 +98,11 @@ namespace Opm
|
||||
static FieldType classifyKeyword(const std::string& keyword);
|
||||
static bool readKeyword(std::istream& is, std::string& keyword);
|
||||
|
||||
// temporary measure to get the file name passed to the
|
||||
// constuctor above
|
||||
const std::string &deckFileName() const
|
||||
{ return deckFileName_; };
|
||||
|
||||
|
||||
/// Read the given stream, overwriting any previous data. Unless
|
||||
/// the second argument 'convert_to_SI' is false, all fields will
|
||||
@ -259,7 +264,7 @@ private:
|
||||
void readImpl(std::istream& is);
|
||||
void getNumericErtFields(const std::string& filename);
|
||||
|
||||
|
||||
std::string deckFileName_;
|
||||
std::string directory_;
|
||||
std::map<std::string, std::vector<int> > integer_field_map_;
|
||||
std::map<std::string, std::vector<double> > floating_field_map_;
|
||||
|
Loading…
Reference in New Issue
Block a user