Refactor common code into a function

This commit is contained in:
Roland Kaufmann 2013-11-22 09:32:50 +01:00
parent e57d1697c2
commit 24b6bd8254

View File

@ -265,6 +265,29 @@ private:
}
};
/// Get dimensions of the grid from the parse of the input file
std::vector <int> parserDim (const EclipseGridParser& parser) {
std::vector<int> dim(/* n = */ 3);
// dimensions explicitly given
if (parser.hasField("SPECGRID")) {
dim = parser.getSPECGRID ().dimensions;
}
// dimensions implicitly given by number of deltas
else if (parser.hasField("DXV")) {
assert(parser.hasField("DYV"));
assert(parser.hasField("DZV"));
dim[0] = parser.getFloatingPointValue("DXV").size();
dim[1] = parser.getFloatingPointValue("DYV").size();
dim[2] = parser.getFloatingPointValue("DZV").size();
}
else {
OPM_THROW(std::runtime_error,
"Only decks featureing either the SPECGRID or the D[XYZ]V keywords "
"are currently supported");
}
return dim;
}
/// Convert OPM phase usage to ERT bitmask
static int phaseMask (const PhaseUsage uses) {
return (uses.phase_used [BlackoilPhases::Liquid] ? ECL_OIL_PHASE : 0)
@ -290,21 +313,7 @@ struct EclipseRestart : public EclipseHandle <ecl_rst_file_type> {
const PhaseUsage uses,
const EclipseGridParser parser,
const int num_active_cells) {
std::vector<int> dim(/*n=*/3);
if (parser.hasField("SPECGRID"))
dim = parser.getSPECGRID ().dimensions;
else if (parser.hasField("DXV")) {
assert(parser.hasField("DYV"));
assert(parser.hasField("DZV"));
dim[0] = parser.getFloatingPointValue("DXV").size();
dim[1] = parser.getFloatingPointValue("DYV").size();
dim[2] = parser.getFloatingPointValue("DZV").size();
}
else
OPM_THROW(std::runtime_error,
"Only decks featureing either the SPECGRID or the D[XYZ]V keywords "
"are currently supported");
const std::vector <int> dim = parserDim (parser);
ecl_rst_file_fwrite_header (*this,
stepNum (timer),
current (timer),
@ -610,21 +619,7 @@ private:
boost::filesystem::path casePath (outputDir);
casePath /= boost::to_upper_copy (baseName);
std::vector<int> dim(/*n=*/3);
if (parser.hasField("SPECGRID"))
dim = parser.getSPECGRID ().dimensions;
else if (parser.hasField("DXV")) {
assert(parser.hasField("DYV"));
assert(parser.hasField("DZV"));
dim[0] = parser.getFloatingPointValue("DXV").size();
dim[1] = parser.getFloatingPointValue("DYV").size();
dim[2] = parser.getFloatingPointValue("DZV").size();
}
else
OPM_THROW(std::runtime_error,
"Only decks featureing either the SPECGRID or the D[XYZ]V keywords "
"are currently supported");
const std::vector <int> dim = parserDim (parser);
return ecl_sum_alloc_writer (casePath.string ().c_str (),
false, /* formatted */
true, /* unified */