Skip to content

Commit

Permalink
Merge pull request #432 from joakim-hove/ecl-sum-data-refactor
Browse files Browse the repository at this point in the history
Ecl sum data refactor
  • Loading branch information
joakim-hove authored Jul 12, 2018
2 parents 85d0ebf + 1c38824 commit 027ceef
Show file tree
Hide file tree
Showing 18 changed files with 2,433 additions and 835 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ endif()
# Treat warnings as errors if not on Windows
if (NOT ERT_WINDOWS)
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wno-unknown-pragmas ")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall " )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-unknown-pragmas -Wno-unused-result -Wno-unused-parameter" )
endif()

if (MSVC)
Expand Down
10 changes: 8 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ add_library(ecl util/rng.cpp
ecl/ecl_grav_calc.cpp
ecl/ecl_smspec.cpp
ecl/ecl_sum_data.cpp
ecl/ecl_sum_file_data.cpp
ecl/ecl_util.cpp
ecl/ecl_kw.cpp
ecl/ecl_sum.cpp
Expand Down Expand Up @@ -178,6 +179,7 @@ target_include_directories(ecl
util
include
e3
${CMAKE_CURRENT_SOURCE_DIR}/private-include
${CMAKE_CURRENT_BINARY_DIR}/include
)

Expand All @@ -194,8 +196,8 @@ target_compile_options(ecl PUBLIC ${pthreadarg})


if (ERT_USE_OPENMP)
target_compile_options(ecl PUBLIC ${OpenMP_C_FLAGS})
set_property(TARGET ecl APPEND PROPERTY LINK_FLAGS ${OpenMP_C_FLAGS})
target_compile_options(ecl PUBLIC ${OpenMP_CXX_FLAGS})
set_property(TARGET ecl APPEND PROPERTY LINK_FLAGS ${OpenMP_CXX_FLAGS})
target_link_libraries( ecl PUBLIC ${OpenMP_EXE_LINKER_FLAGS})
endif ()

Expand Down Expand Up @@ -385,6 +387,10 @@ foreach (name ecl_alloc_cpgrid
add_test(NAME ${name} COMMAND ${name})
endforeach ()

add_executable(ecl_sum_data_intermediate ecl/tests/ecl_sum_data_intermediate_test.cpp)
target_link_libraries(ecl_sum_data_intermediate ecl)
add_test(NAME ecl_sum_data_intermediate COMMAND ecl_sum_data_intermediate)

add_executable(ecl_grid_cell_contains ecl/tests/ecl_grid_cell_contains.cpp)
target_link_libraries(ecl_grid_cell_contains ecl)
add_test(NAME ecl_grid_cell_contains1 COMMAND ecl_grid_cell_contains)
Expand Down
52 changes: 16 additions & 36 deletions lib/ecl/ecl_smspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ struct ecl_smspec_struct {
vector_type * smspec_nodes;
bool write_mode;
bool need_nums;
bool locked;
int_vector_type * index_map;

/*-----------------------------------------------------------------*/
Expand Down Expand Up @@ -275,7 +274,6 @@ ecl_smspec_type * ecl_smspec_alloc_empty(bool write_mode , const char * key_join
ecl_smspec->day_index = -1;
ecl_smspec->year_index = -1;
ecl_smspec->month_index = -1;
ecl_smspec->locked = false;
ecl_smspec->time_seconds = -1;

/*
Expand Down Expand Up @@ -335,21 +333,6 @@ int ecl_smspec_num_nodes( const ecl_smspec_type * smspec) {
}


/*
In the current implementation it is impossible to mix calls to
ecl_sum_add_var() and ecl_sum_add_tstep() - i.e. one must first add
*all* the variables with ecl_sum_add_var() calls, and then
subsequently add timesteps with ecl_sum_add_tstep().
The locked property of the smspec structure is to ensure that no new
variables are added to the ecl_smspec structure after the first
timestep has been added.
*/

void ecl_smspec_lock( ecl_smspec_type * smspec ) {
smspec->locked = true;
}

/**
* Returns an ecl data type for which all names will fit. If the maximum name
* length is at most 8, an ECL_CHAR is returned and otherwise a large enough
Expand Down Expand Up @@ -1103,30 +1086,27 @@ static void ecl_smspec_set_params_size( ecl_smspec_type * ecl_smspec , int param


void ecl_smspec_insert_node(ecl_smspec_type * ecl_smspec, smspec_node_type * smspec_node){
if (!ecl_smspec->locked) {
int internal_index = vector_get_size( ecl_smspec->smspec_nodes );
int internal_index = vector_get_size( ecl_smspec->smspec_nodes );

/* This IF test should only apply in write_mode. */
if (smspec_node_get_params_index( smspec_node ) < 0) {
if (!ecl_smspec->write_mode)
util_abort("%s: internal error \n",__func__);
smspec_node_set_params_index( smspec_node , internal_index);
/* This IF test should only apply in write_mode. */
if (smspec_node_get_params_index( smspec_node ) < 0) {
if (!ecl_smspec->write_mode)
util_abort("%s: internal error \n",__func__);
smspec_node_set_params_index( smspec_node , internal_index);

if (internal_index >= ecl_smspec->params_size)
ecl_smspec_set_params_size( ecl_smspec , internal_index + 1);
}
vector_append_owned_ref( ecl_smspec->smspec_nodes , smspec_node , smspec_node_free__ );
if (internal_index >= ecl_smspec->params_size)
ecl_smspec_set_params_size( ecl_smspec , internal_index + 1);
}
vector_append_owned_ref( ecl_smspec->smspec_nodes , smspec_node , smspec_node_free__ );

{
int params_index = smspec_node_get_params_index( smspec_node );
{
int params_index = smspec_node_get_params_index( smspec_node );

/* This indexing must be used when writing. */
int_vector_iset( ecl_smspec->index_map , internal_index , params_index);
/* This indexing must be used when writing. */
int_vector_iset( ecl_smspec->index_map , internal_index , params_index);

float_vector_iset( ecl_smspec->params_default , params_index , smspec_node_get_default(smspec_node) );
}
} else
util_abort("%s: sorry - the smspec header has been locked (can not mix ecl_sum_add_var() and ecl_sum_add_tstep() calls.)\n",__func__);
float_vector_iset( ecl_smspec->params_default , params_index , smspec_node_get_default(smspec_node) );
}
}


Expand Down
12 changes: 8 additions & 4 deletions lib/ecl/ecl_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
for more details.
*/

#include <stdexcept>

#include <string.h>
#include <stdbool.h>
#include <math.h>
Expand Down Expand Up @@ -279,6 +281,10 @@ void ecl_sum_set_fmt_case( ecl_sum_type * ecl_sum , bool fmt_case ) {


smspec_node_type * ecl_sum_add_var( ecl_sum_type * ecl_sum , const char * keyword , const char * wgname , int num , const char * unit , float default_value) {
if (ecl_sum_data_get_length(ecl_sum->data) > 0)
throw std::invalid_argument("Can not interchange variable adding and timesteps.\n");


smspec_node_type * smspec_node = smspec_node_alloc( ecl_smspec_identify_var_type(keyword),
wgname,
keyword,
Expand All @@ -289,6 +295,7 @@ smspec_node_type * ecl_sum_add_var( ecl_sum_type * ecl_sum , const char * keywor
-1,
default_value);
ecl_smspec_add_node(ecl_sum->smspec, smspec_node);
ecl_sum_data_reset_self_map( ecl_sum->data );
return smspec_node;
}

Expand Down Expand Up @@ -754,7 +761,7 @@ const char * ecl_sum_get_general_var_unit( const ecl_sum_type * ecl_sum , const
ecl_sum_type * ecl_sum_alloc_resample(const ecl_sum_type * ecl_sum, const char * ecl_case, const time_t_vector_type * times) {
time_t start_time = ecl_sum_get_data_start(ecl_sum);

if ( time_t_vector_get_first(times) < start_time )
if ( time_t_vector_get_first(times) < start_time )
return NULL;
if ( time_t_vector_get_last(times) > ecl_sum_get_end_time(ecl_sum) )
return NULL;
Expand Down Expand Up @@ -881,9 +888,6 @@ int ecl_sum_iget_report_end( const ecl_sum_type * ecl_sum, int report_step) {
return ecl_sum_data_iget_report_end(ecl_sum->data , report_step );
}

int ecl_sum_iget_report_start( const ecl_sum_type * ecl_sum, int report_step) {
return ecl_sum_data_iget_report_start(ecl_sum->data , report_step );
}

int ecl_sum_iget_report_step( const ecl_sum_type * ecl_sum , int internal_index ){
return ecl_sum_data_iget_report_step( ecl_sum->data , internal_index );
Expand Down
Loading

0 comments on commit 027ceef

Please sign in to comment.