Fixup of alternating records special case

This commit is contained in:
Joakim Hove
2020-01-06 13:38:10 +01:00
parent c2b4d30be5
commit 6f330a7482
9 changed files with 61 additions and 25 deletions

View File

@@ -19,6 +19,7 @@
#include <cctype>
#include <fstream>
#include <iterator>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
@@ -600,7 +601,10 @@ RawKeyword * newRawKeyword(const ParserKeyword& parserKeyword, const std::string
if( deck.hasKeyword(keyword_size.keyword ) ) {
const auto& sizeDefinitionKeyword = deck.getKeyword(keyword_size.keyword);
const auto& record = sizeDefinitionKeyword.getRecord(0);
const auto targetSize = record.getItem( keyword_size.item ).get< int >( 0 ) + keyword_size.shift;
auto targetSize = record.getItem( keyword_size.item ).get< int >( 0 ) + keyword_size.shift;
if (parserKeyword.isAlternatingKeyword())
targetSize *= std::distance( parserKeyword.begin(), parserKeyword.end() );
return new RawKeyword( keywordString,
parserState.current_path().string(),
parserState.line(),

View File

@@ -206,8 +206,6 @@ namespace Opm {
if (jsonConfig.has_item("alternating_records")) {
alternating_keyword = true;
if (!jsonConfig.has_item("num_tables") || jsonConfig.has_item("size"))
throw std::invalid_argument("alternating_records must have num_tables.");
const Json::JsonObject recordsConfig = jsonConfig.get_item("alternating_records");
parseRecords( recordsConfig );
}

View File

@@ -1,9 +1,10 @@
{
"name" : "PVTWSALT", "sections" : ["PROPS"], "num_tables" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
"name" : "PVTWSALT", "sections" : ["PROPS"], "size" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
[
{"name" : "REF_TEMP", "value_type" : "DOUBLE", "dimension" : "Temperature"}
{"name":"P_REF", "value_type" : "DOUBLE", "dimension":"Pressure"},
{"name":"SALT_CONCENTRATION_REF", "value_type" : "DOUBLE", "default" : 0.0,"dimension":"Density"}
],
[
{"name" : "table", "value_type" : "DOUBLE", "size_type" : "ALL", "dimension" : ["Pressure" , "1", "Viscosity"]}
[
{"name" : "table", "value_type" : "DOUBLE", "size_type" : "ALL", "dimension" : ["Density","1","1/Pressure","Viscosity", "1/Pressure"]}
]]
}

View File

@@ -1,9 +1,10 @@
{
"name" : "PVZG", "sections" : ["PROPS"], "num_tables" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
"name" : "PVZG", "sections" : ["PROPS"], "size" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
[
{"name" : "REF_TEMP", "value_type" : "DOUBLE", "dimension" : "Temperature"}
],
[
[
{"name" : "table", "value_type" : "DOUBLE", "size_type" : "ALL", "dimension" : ["Pressure" , "1", "Viscosity"]}
]]
}

View File

@@ -1,9 +1,9 @@
{
"name" : "STOG", "sections" : ["PROPS"], "num_tables" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
"name" : "STOG", "sections" : ["PROPS"], "size" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
[
{"name" : "REF_OIL_PHASE_PRESSURE", "value_type" : "DOUBLE", "dimension" : "Pressure"}
],
[
[
{"name" : "table", "value_type" : "DOUBLE", "size_type" : "ALL", "dimension" : ["Pressure" , "SurfaceTension"]}
]]
}

View File

@@ -1,9 +1,9 @@
{
"name" : "STOW", "sections" : ["PROPS"], "num_tables" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
"name" : "STOW", "sections" : ["PROPS"], "size" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
[
{"name" : "REF_OIL_PRESSURE", "value_type" : "DOUBLE", "dimension" : "Pressure"}
],
[
[
{"name" : "table", "value_type" : "DOUBLE", "size_type" : "ALL", "dimension" : ["Pressure" , "SurfaceTension"]}
]]
}

View File

@@ -1,9 +1,9 @@
{
"name" : "STWG", "sections" : ["PROPS"], "num_tables" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
"name" : "STWG", "sections" : ["PROPS"], "size" : {"keyword" : "TABDIMS" , "item" : "NTPVT"}, "alternating_records" : [
[
{"name" : "REF_OIL_PRESSURE", "value_type" : "DOUBLE", "dimension" : "Pressure"}
],
[
[
{"name" : "table", "value_type" : "DOUBLE", "size_type" : "ALL", "dimension" : ["Pressure" , "SurfaceTension"]}
]]
}

View File

@@ -1748,16 +1748,6 @@ BOOST_AUTO_TEST_CASE(ConstructFromJson_withAlternatingRecordswithItems) {
BOOST_CHECK_THROW( ParserKeyword kw( jsonObject ), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(ConstructFromJson_withAlternatingRecordsSizeWithoutBrackets) {
const std::string json_string = R"(
{"name" : "STOG", "sections" : ["PROPS"] , "size" : 6, "alternating_records" : [[
{"name" : "ref_oil_pressure", "value_type" : "DOUBLE"}], [
{"name" : "oil_phase_pressure" , "value_type" : "DOUBLE"},
{"name" : "surface_rension", "value_type" : "DOUBLE"}]]}
)";
Json::JsonObject jsonObject( json_string );
BOOST_CHECK_THROW( ParserKeyword kw( jsonObject ), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(GetAlternatingKeywordFromParser) {
Parser parser;

View File

@@ -1455,3 +1455,45 @@ WORKLIM
)";
Parser().parseString( input );
}
BOOST_AUTO_TEST_CASE(PVTWSALT) {
const std::string input = R"(
RUNSPEC
TABDIMS
1 2 /
PROPS
PVTWSALT
1000 0 /
1 2 3 4 5
6 7 8 9 10 /
2000 0.50 /
1.5 2.5 3.5 4.5 5.5
6.5 7.5 8.5 9.5 10.5/
-- S_g k_rg k_rog p_cog
SGOF
0.1 0.0 1.0 0.0
0.2 0.1 1.0 1.0
0.3 0.2 0.9 2.0
0.4 0.3 0.8 3.0
0.5 0.5 0.5 4.0
0.6 0.6 0.4 5.0
0.7 0.8 0.3 6.0
0.8 0.9 0.2 7.0
0.9 0.5 0.1 8.0
1.0 1.0 0.1 9.0 /;
)";
auto deck = Parser{}.parseString(input);
const auto& pvtwsalt = deck.getKeyword("PVTWSALT");
BOOST_CHECK_EQUAL(pvtwsalt.size(), 4);
const auto& sgof = deck.getKeyword("SGOF");
BOOST_CHECK_EQUAL(sgof.size(), 1);
}