From 30a1a0b26e9cc0ba0446d767ab3897af6452e3e2 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 22 May 2019 07:13:06 +0200 Subject: [PATCH 1/7] Improve error message for invalid json --- src/opm/json/JsonObject.cpp | 45 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/opm/json/JsonObject.cpp b/src/opm/json/JsonObject.cpp index 764d58128..67cd6e9bd 100644 --- a/src/opm/json/JsonObject.cpp +++ b/src/opm/json/JsonObject.cpp @@ -32,8 +32,8 @@ namespace Json { void JsonObject::initialize(const std::string& inline_json) { - root = cJSON_Parse( inline_json.c_str() ); - if (!root) + this->root = cJSON_Parse( inline_json.c_str() ); + if (!this->root) throw std::invalid_argument("Parsing json input failed"); owner = true; } @@ -54,7 +54,12 @@ namespace Json { if (stream) { std::string content_from_file( (std::istreambuf_iterator(stream)), (std::istreambuf_iterator())); - initialize( content_from_file ); + + this->root = cJSON_Parse( content_from_file.c_str() ); + if (!this->root) + throw std::invalid_argument("Parsing json file: " + jsonFile.string() + " failed "); + + this->owner = true; } else throw std::invalid_argument("Loading json from file: " + jsonFile.string() + " failed."); } @@ -63,20 +68,20 @@ namespace Json { JsonObject::JsonObject( cJSON * object ) { - root = object; + this->root = object; owner = false; } JsonObject::~JsonObject() { - if (owner && root) - cJSON_Delete(root); + if (owner && this->root) + cJSON_Delete(this->root); } bool JsonObject::has_item( const std::string& key) const { - cJSON * object = cJSON_GetObjectItem( root , key.c_str() ); + cJSON * object = cJSON_GetObjectItem( this->root , key.c_str() ); if (object) return true; else @@ -85,14 +90,14 @@ namespace Json { bool JsonObject::is_array( ) const { - if (root->type == cJSON_Array) + if (this->root->type == cJSON_Array) return true; else return false; } bool JsonObject::is_number( ) const { - if (root->type == cJSON_Number) + if (this->root->type == cJSON_Number) return true; else return false; @@ -100,14 +105,14 @@ namespace Json { bool JsonObject::is_string( ) const { - if (root->type == cJSON_String) + if (this->root->type == cJSON_String) return true; else return false; } bool JsonObject::is_object( ) const { - if (root->type == cJSON_Object) + if (this->root->type == cJSON_Object) return true; else return false; @@ -115,14 +120,14 @@ namespace Json { size_t JsonObject::size() const { - int int_size = cJSON_GetArraySize( root ); + int int_size = cJSON_GetArraySize( this->root ); return (size_t) int_size; } JsonObject JsonObject::get_array_item( size_t index ) const { if (is_array()) { - cJSON * new_c_ptr = cJSON_GetArrayItem( root , index ); + cJSON * new_c_ptr = cJSON_GetArrayItem( this->root , index ); if (new_c_ptr) return JsonObject( new_c_ptr ); else @@ -133,7 +138,7 @@ namespace Json { JsonObject JsonObject::get_item(const std::string& key) const { - cJSON * c_ptr = cJSON_GetObjectItem( root , key.c_str() ); + cJSON * c_ptr = cJSON_GetObjectItem( this->root , key.c_str() ); if (c_ptr) return JsonObject( c_ptr ); else @@ -149,7 +154,7 @@ namespace Json { std::string JsonObject::as_string() const { if (is_string()) - return root->valuestring; + return this->root->valuestring; else throw std::invalid_argument("Object is not a string object"); } @@ -162,8 +167,8 @@ namespace Json { int JsonObject::as_int() const { - if (root->type == cJSON_Number) - return root->valueint; + if (this->root->type == cJSON_Number) + return this->root->valueint; else throw std::invalid_argument("Object is not a number object."); } @@ -176,8 +181,8 @@ namespace Json { double JsonObject::as_double() const { - if (root->type == cJSON_Number) - return root->valuedouble; + if (this->root->type == cJSON_Number) + return this->root->valuedouble; else throw std::invalid_argument("Object is not a number object."); } @@ -194,7 +199,7 @@ namespace Json { std::string JsonObject::to_string() const { - char * c_str = cJSON_Print( root ); + char * c_str = cJSON_Print( this->root ); std::string s(c_str); free( c_str ); From 76acb98c67ac6b9acdec3de88ea5ce61a77d8619 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 22 May 2019 06:14:31 +0200 Subject: [PATCH 2/7] Add keyword GPMAINT --- .../eclipse/share/keywords/000_Eclipse100/G/GPMAINT | 9 +++++++++ src/opm/parser/eclipse/share/keywords/keyword_list.cmake | 1 + 2 files changed, 10 insertions(+) create mode 100644 src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GPMAINT diff --git a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GPMAINT b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GPMAINT new file mode 100644 index 000000000..22241c715 --- /dev/null +++ b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GPMAINT @@ -0,0 +1,9 @@ +{"name" : "GPMAINT" , "sections" : ["SCHEDULE"], "items" : [ + {"name" : "GROUP" , "value_type" : "STRING" }, + {"name" : "FLOW_TARGET" , "value_type" : "STRING"}, + {"name" : "REGION" , "value_type" : "INT"}, + {"name" : "FIP_FAMILY" , "value_type" : "STRING"}, + {"name" : "PRESSURE_TARGET" , "value_type" : "DOUBLE" , "dimension" : "Pressure"}, + {"name" : "PROP_CONSTANT" , "value_type" : "DOUBLE" , "dimension" : "ReservoirVolume/Time*Pressure"}, + {"name" : "TIME_CONSTANT" , "value_type" : "DOUBLE" , "dimension" : "Time"} +]} diff --git a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake index a6851f2bb..c239a33ea 100644 --- a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake +++ b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake @@ -119,6 +119,7 @@ set( keywords 000_Eclipse100/G/GLIFTOPT 000_Eclipse100/G/GMWSET 000_Eclipse100/G/GNETINJE + 000_Eclipse100/G/GPMAINT 000_Eclipse100/G/GRAVITY 000_Eclipse100/G/GRID 000_Eclipse100/G/GRIDFILE From cd55d69ef79c70045586211666f836f7b46dab20 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 22 May 2019 06:21:32 +0200 Subject: [PATCH 3/7] Add keyword GCONSUMP --- .../parser/eclipse/share/keywords/000_Eclipse100/G/GCONSUMP | 6 ++++++ src/opm/parser/eclipse/share/keywords/keyword_list.cmake | 1 + 2 files changed, 7 insertions(+) create mode 100644 src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSUMP diff --git a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSUMP b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSUMP new file mode 100644 index 000000000..238c562cd --- /dev/null +++ b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSUMP @@ -0,0 +1,6 @@ +{"name" : "GCONSUMP" , "sections" : ["SCHEDULE"], "items" : [ + {"name" : "GROUP" , "value_type" : "STRING" }, + {"name" : "GAS_CONSUMP_RATE" , "value_type" : "UDA", "dimension": "GasSurfaceVolume/Time"}, + {"name" : "GAS_IMPORT_RATE" , "value_type" : "UDA", "dimension": "GasSurfaceVolume/Time"}, + {"name" : "NETWORK_NODE" , "value_type" : "STRING"} +]} diff --git a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake index c239a33ea..9f4900393 100644 --- a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake +++ b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake @@ -112,6 +112,7 @@ set( keywords 000_Eclipse100/G/GAS 000_Eclipse100/G/GCONINJE 000_Eclipse100/G/GCONPROD + 000_Eclipse100/G/GCONSUMP 000_Eclipse100/G/GDFILE 000_Eclipse100/G/GDORIENT 000_Eclipse100/G/GECON From 5a31ae874b6a25d0cefe0beedef8a4cbbd58b2c2 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 22 May 2019 06:39:52 +0200 Subject: [PATCH 4/7] Add keyword GUIDERAT --- .../share/keywords/000_Eclipse100/G/GUIDERAT | 14 ++++++++++++++ .../eclipse/share/keywords/keyword_list.cmake | 1 + 2 files changed, 15 insertions(+) create mode 100644 src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GUIDERAT diff --git a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GUIDERAT b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GUIDERAT new file mode 100644 index 000000000..dd87a48da --- /dev/null +++ b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GUIDERAT @@ -0,0 +1,14 @@ +{"name" : "GUIDERAT", "sections" : ["SCHEDULE"], "size": 1, +"items" : [ + {"name" : "MIN_CALC_TIME", "value_type" : "DOUBLE", "dimension" : "Time", "default" : 0}, + {"name" : "NOMINATED_PHASE", "value_type" : "STRING", "default" : "NONE"}, + {"name" : "A", "value_type" :"DOUBLE", "default" : 0}, + {"name" : "B", "value_type" :"DOUBLE", "default" : 0}, + {"name" : "C", "value_type" :"DOUBLE", "default" : 0}, + {"name" : "D", "value_type" :"DOUBLE", "default" : 0}, + {"name" : "E", "value_type" :"DOUBLE", "default" : 0}, + {"name" : "F", "value_type" :"DOUBLE", "default" : 0}, + {"name" : "ALLOW_INCREASE", "value_type" : "STRING", "default": "YES"}, + {"name" : "DAMPING_FACTOR", "value_type" : "DOUBLE", "default": 1.0}, + {"name" : "USE_FREE_GAS", "value_type" : "STRING", "default": "NO"}, + {"name" : "MIN_GUIDE_RATE", "value_type" : "DOUBLE", "default" : 1e-6}]} diff --git a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake index 9f4900393..b29da3067 100644 --- a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake +++ b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake @@ -130,6 +130,7 @@ set( keywords 000_Eclipse100/G/GRUPNET 000_Eclipse100/G/GRUPTREE 000_Eclipse100/G/GSATPROD + 000_Eclipse100/G/GUIDERAT 000_Eclipse100/I/IMBNUM 000_Eclipse100/I/IMKRVD 000_Eclipse100/I/IMPES From c986c49113b52e2ab6c35778f1b936bd3531dcc8 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 22 May 2019 06:48:39 +0200 Subject: [PATCH 5/7] Add keyword NODEPROP --- .../eclipse/share/keywords/000_Eclipse100/N/NODEPROP | 7 +++++++ src/opm/parser/eclipse/share/keywords/keyword_list.cmake | 1 + 2 files changed, 8 insertions(+) create mode 100644 src/opm/parser/eclipse/share/keywords/000_Eclipse100/N/NODEPROP diff --git a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/N/NODEPROP b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/N/NODEPROP new file mode 100644 index 000000000..f5edef919 --- /dev/null +++ b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/N/NODEPROP @@ -0,0 +1,7 @@ +{"name" : "NODEPROP", "sections" : ["SCHEDULE"], "items" : [ + {"name" : "NAME", "value_type" : "STRING"}, + {"name" : "PRESSURE", "value_type" : "DOUBLE", "dimension" : "Pressure"}, + {"name" : "AS_CHOKE", "value_type" : "STRING", "default" : "NO"}, + {"name" : "CHOKE_GROUP", "value_type" : "STRING"}, + {"name" : "SOURCE_SINK_GROUP", "value_type" : "STRING"}, + {"name" : "NETWORK_VALUE_TYPE", "value_type" : "STRING", "default" : "PROD"}]} diff --git a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake index b29da3067..8383bc8cb 100644 --- a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake +++ b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake @@ -185,6 +185,7 @@ set( keywords 000_Eclipse100/N/NEXTSTEP 000_Eclipse100/N/NNC 000_Eclipse100/N/NOCASC + 000_Eclipse100/N/NODEPROP 000_Eclipse100/N/NOECHO 000_Eclipse100/N/NOGGF 000_Eclipse100/N/NOINSPEC From eb2c0b74415f4f2b4ca447ef8c768a3f972c265e Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 22 May 2019 06:53:36 +0200 Subject: [PATCH 6/7] Add keyword BRANPROP --- .../eclipse/share/keywords/000_Eclipse100/B/BRANPROP | 7 +++++++ src/opm/parser/eclipse/share/keywords/keyword_list.cmake | 1 + 2 files changed, 8 insertions(+) create mode 100644 src/opm/parser/eclipse/share/keywords/000_Eclipse100/B/BRANPROP diff --git a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/B/BRANPROP b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/B/BRANPROP new file mode 100644 index 000000000..dfa1009b1 --- /dev/null +++ b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/B/BRANPROP @@ -0,0 +1,7 @@ +{"name" : "BRANPROP", "sections" : ["SCHEDULE"], "items" : [ + {"name" : "DOWNTREE_NODE", "value_type" : "STRING"}, + {"name" : "UPTREE_NODE", "value_type" : "STRING"}, + {"name" : "VFP_TABLE", "value_type" : "INT"}, + {"name" : "ALQ", "value_type" : "DOUBLE", "default" : 0}, + {"name" : "ALQ_SURFACE_DENSITY", "value_type" : "STRING", "default" : "NONE"} +]} \ No newline at end of file diff --git a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake index 8383bc8cb..0373a5217 100644 --- a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake +++ b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake @@ -34,6 +34,7 @@ set( keywords 000_Eclipse100/B/BLACKOIL 000_Eclipse100/B/BLOCK_PROBE 000_Eclipse100/B/BOX + 000_Eclipse100/B/BRANPROP 000_Eclipse100/C/CARFIN 000_Eclipse100/C/CECON 000_Eclipse100/C/COMPDAT From c0ccd06250c48ef26a38cb483d8cd0b4ac04c1f8 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 22 May 2019 06:26:52 +0200 Subject: [PATCH 7/7] Add keyword GCONSALE --- .../eclipse/share/keywords/000_Eclipse100/G/GCONSALE | 7 +++++++ src/opm/parser/eclipse/share/keywords/keyword_list.cmake | 1 + 2 files changed, 8 insertions(+) create mode 100644 src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSALE diff --git a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSALE b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSALE new file mode 100644 index 000000000..b19054b95 --- /dev/null +++ b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/G/GCONSALE @@ -0,0 +1,7 @@ +{"name" : "GCONSALE" , "sections" : ["SCHEDULE"], "items" : [ + {"name" : "GROUP" , "value_type" : "STRING" }, + {"name" : "SALES_TARGET" , "value_type" : "UDA", "dimension": "GasSurfaceVolume/Time"}, + {"name" : "MAX_SALES_RATE" , "value_type" : "UDA", "dimension": "GasSurfaceVolume/Time"}, + {"name" : "MIN_SALES_RATE" , "value_type" : "UDA", "dimension": "GasSurfaceVolume/Time", "default" : -1e20}, + {"name" : "MAX_PROC" , "value_type" : "STRING", "default" : "NONE"} +]} diff --git a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake index 0373a5217..2a6bb3fd7 100644 --- a/src/opm/parser/eclipse/share/keywords/keyword_list.cmake +++ b/src/opm/parser/eclipse/share/keywords/keyword_list.cmake @@ -113,6 +113,7 @@ set( keywords 000_Eclipse100/G/GAS 000_Eclipse100/G/GCONINJE 000_Eclipse100/G/GCONPROD + 000_Eclipse100/G/GCONSALE 000_Eclipse100/G/GCONSUMP 000_Eclipse100/G/GDFILE 000_Eclipse100/G/GDORIENT