Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to add_node issue, copy smspec_node constructor, args to summary_… #1

Merged
merged 1 commit into from
Nov 29, 2018
Merged
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
7 changes: 5 additions & 2 deletions bin/summary_resample
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ parser.add_argument("input_case", metavar="input_case", type=str)
parser.add_argument("output_case", metavar="output_case", type=str)
parser.add_argument("--num-timestep", type=int, default=50)
parser.add_argument("--refcase", metavar="refcase", type=str)
parser.add_argument("--extrapolation", action="store_true")
args = parser.parse_args()

input_case = EclSum(args.input_case)
Expand All @@ -23,6 +24,8 @@ else:
end_time = input_case.get_end_time()
time_points = TimeVector.create_linear(CTime(start_time), CTime(end_time), args.num_timestep)

sys.stderr.write("The summary_resample code is partly broken as of October 24.th 2018. Should be fixed\n")
output_case = input_case.resample(args.output_case, time_points)
output_case = input_case.resample(args.output_case,
time_points,
lower_extrapolation=args.extrapolation,
upper_extrapolation=args.extrapolation)
output_case.fwrite( )
6 changes: 5 additions & 1 deletion lib/ecl/ecl_smspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,11 @@ const ecl::smspec_node * ecl_smspec_add_node(ecl_smspec_type * ecl_smspec, const
ecl_smspec->key_join_string.c_str())));
}


//copy given node with a new index
const ecl::smspec_node * ecl_smspec_add_node(ecl_smspec_type * ecl_smspec, const ecl::smspec_node& node) {
int params_index = ecl_smspec->smspec_nodes.size();
return ecl_smspec_insert_node(ecl_smspec, std::unique_ptr<ecl::smspec_node>( new ecl::smspec_node(node, params_index)));
}


const ecl::smspec_node * ecl_smspec_add_node(ecl_smspec_type * ecl_smspec, const char * keyword, const char * unit, float default_value) {
Expand Down
7 changes: 1 addition & 6 deletions lib/ecl/ecl_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,7 @@ const ecl::smspec_node * ecl_sum_add_var( ecl_sum_type * ecl_sum , const char *


const ecl::smspec_node * ecl_sum_add_smspec_node(ecl_sum_type * ecl_sum, const ecl::smspec_node * node) {
return ecl_sum_add_var(ecl_sum,
smspec_node_get_keyword(node),
smspec_node_get_wgname(node),
node->get_num(),
smspec_node_get_unit(node),
node->get_default());
return ecl_smspec_add_node(ecl_sum->smspec, *node);
}


Expand Down
10 changes: 6 additions & 4 deletions lib/ecl/smspec_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ void smspec_node::set_wgname(const char * wgname) {
void smspec_node::set_num( const int * grid_dims , int num_) {
if (num_ == SMSPEC_NUMS_INVALID)
util_abort("%s: explicitly trying to set nums == SMSPEC_NUMS_INVALID - seems like a bug?!\n",__func__);

this->num = num_;
if ((var_type == ECL_SMSPEC_COMPLETION_VAR) || (var_type == ECL_SMSPEC_BLOCK_VAR)) {
int global_index = this->num - 1;
Expand Down Expand Up @@ -751,6 +750,12 @@ smspec_node::smspec_node(int param_index, const char * keyword, const char * uni
{
}

//copy constructor with a new id
smspec_node::smspec_node(const smspec_node& node, int param_index)
{
*this = node;
this->params_index = param_index;
}

smspec_node::smspec_node(int param_index,
const char * keyword,
Expand Down Expand Up @@ -789,7 +794,6 @@ smspec_node::smspec_node(int param_index,
at all, e.g. like "FOPT" - the wgname input value is ignored
completely.
*/

this->var_type = this->valid_type(keyword, wgname, num);
if (this->var_type == ECL_SMSPEC_INVALID_VAR)
throw std::invalid_argument("Could not construct smspec_node from this input.");
Expand Down Expand Up @@ -857,7 +861,6 @@ smspec_node::smspec_node(int param_index,
throw std::invalid_argument("Should not be here ... ");
break;
}

set_gen_keys( key_join_string );
}

Expand All @@ -871,7 +874,6 @@ smspec_node::smspec_node( int param_index_,
const char * key_join_string_) {

this->var_type = this->valid_type(keyword_, wgname_, -1);
printf("keyword: %s\n",keyword_);
if (this->var_type == ECL_SMSPEC_INVALID_VAR)
throw std::invalid_argument("Could not construct smspec_node from this input.");

Expand Down
1 change: 1 addition & 0 deletions lib/include/ert/ecl/ecl_smspec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ extern "C" {
}
#endif

const ecl::smspec_node * ecl_smspec_add_node(ecl_smspec_type * ecl_smspec, const ecl::smspec_node& node);
const ecl::smspec_node * ecl_smspec_add_node(ecl_smspec_type * ecl_smspec, const char * keyword, int num, const char * unit, float default_value);
const ecl::smspec_node * ecl_smspec_add_node(ecl_smspec_type * ecl_smspec, const char * keyword, const char * unit, float default_value);
const ecl::smspec_node * ecl_smspec_add_node(ecl_smspec_type * ecl_smspec, const char * keyword, const char * wgname, const char * unit, float default_value);
Expand Down
1 change: 1 addition & 0 deletions lib/include/ert/ecl/smspec_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace ecl {
smspec_node(int param_index, const char * keyword, int num, const char * unit, float default_value, const char * key_join_string);
smspec_node(int param_index, const char * keyword, const char * wgname, const char * unit, float default_value, const char * key_join_string);
smspec_node(int param_index, const char * keyword, const char * wgname, int num, const char * unit, float default_value, const char * key_join_string);
smspec_node(const smspec_node& node, int param_index);

static ecl_smspec_var_type identify_var_type(const char * var);

Expand Down
8 changes: 4 additions & 4 deletions python/tests/ecl_tests/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,14 @@ def test_directory_conflict(self):
def test_resample_extrapolate(self):
"""
Test resampling of summary with extrapolate option of lower and upper boundaries enabled
Note: When performing resampling on cp_simple3 test case, it fails to duplicate node 251 so using mocked ecl_sum instead
path = os.path.join(self.TESTDATA_ROOT, "local/ECLIPSE/cp_simple3/SIMPLE_SUMMARY3")
ecl_sum = EclSum( path, lazy_load=True )
"""
from ecl.util.util import TimeVector, CTime

time_points = TimeVector()
ecl_sum = create_case(data_start=datetime.date(2010, 1, 1))

path = os.path.join(self.TESTDATA_ROOT, "local/ECLIPSE/cp_simple3/SIMPLE_SUMMARY3")
ecl_sum = EclSum( path, lazy_load=True )

start_time = ecl_sum.get_data_start_time() - datetime.timedelta(seconds=86400)
end_time = ecl_sum.get_end_time() + datetime.timedelta(seconds=86400)
delta = end_time - start_time
Expand Down
Binary file added test-data/local/ECLIPSE/cp_simple3/SHORT.SMSPEC
Binary file not shown.
Binary file added test-data/local/ECLIPSE/cp_simple3/SHORT.UNSMRY
Binary file not shown.