コード例 #1
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_io( ) {
  test_work_area_type * work_area = test_work_area_alloc( "enkf-state-map" );
  {
    state_map_type * state_map = state_map_alloc();
    state_map_type * copy1 , *copy2;
    state_map_iset( state_map , 0 , STATE_INITIALIZED );
    state_map_iset( state_map , 100 , STATE_INITIALIZED );
    state_map_fwrite( state_map , "map");
    
    copy1 = state_map_fread_alloc( "map" );
    test_assert_true( state_map_equal( state_map , copy1 ));
    
    copy2 = state_map_alloc();
    state_map_fread( copy2 , "map" );
    test_assert_true( state_map_equal( state_map , copy2 ));

    state_map_iset( copy2 , 67 , STATE_INITIALIZED );
    test_assert_false(state_map_equal( state_map , copy2 ));
    
    state_map_fread( copy2 , "map");
    test_assert_true( state_map_equal( state_map , copy2 ));

    state_map_fread( copy2 , "DoesNotExis");
    test_assert_int_equal( 0 , state_map_get_size( copy2 ));
  }
  test_work_area_free( work_area );
}
コード例 #2
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_readonly() {
  {
    state_map_type * map1 = state_map_fread_alloc_readonly("FileDoesNotExist");
    
    test_assert_true(state_map_is_instance(map1));
    test_assert_int_equal(0 , state_map_get_size( map1 ));
    test_assert_true( state_map_is_readonly( map1 ));
    state_map_free(map1);
  }
  {
    test_work_area_type * work_area = test_work_area_alloc("state-map");
    state_map_type * map1 = state_map_alloc();
    
    state_map_iset(map1 , 5 , STATE_INITIALIZED);
    state_map_iset(map1 , 9 , STATE_INITIALIZED);

    state_map_fwrite(map1 , "map1");
    {
      state_map_type * map2 = state_map_fread_alloc_readonly("map1");
      
      test_assert_true(state_map_equal(map1 , map2));
      state_map_free(map2);
    }
    test_work_area_free( work_area );
    state_map_free(map1);
  }
}
コード例 #3
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_deselect_matching( ) {
  state_map_type * map = state_map_alloc( );
  bool_vector_type * mask1 = bool_vector_alloc(0 , false);
  bool_vector_type * mask2 = bool_vector_alloc(1000 , true);

  state_map_iset( map , 10 , STATE_INITIALIZED );
  state_map_iset( map , 10 , STATE_HAS_DATA );
  state_map_iset( map , 20 , STATE_INITIALIZED );
  state_map_deselect_matching( map , mask1 , STATE_HAS_DATA | STATE_INITIALIZED );
  state_map_deselect_matching( map , mask2 , STATE_HAS_DATA | STATE_INITIALIZED );
  
  test_assert_int_equal( state_map_get_size( map ) , bool_vector_size( mask1 ));
  
  for (int i=0; i < bool_vector_size( mask1 ); i++) {
    if (i==10)
      test_assert_false( bool_vector_iget( mask1 , i ));
    else if (i== 20)
      test_assert_false( bool_vector_iget( mask2 , i ));
    else {
      test_assert_false( bool_vector_iget( mask1 , i ));
      test_assert_true( bool_vector_iget( mask2 , i ));
    }
  }
    
  bool_vector_free( mask1 );
  bool_vector_free( mask2 );
  state_map_free( map );
}
コード例 #4
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void set_test( ) {
  state_map_type * state_map = state_map_alloc();
  state_map_iset( state_map , 0 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( state_map , 0 ));

  state_map_iset( state_map , 100 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( state_map , 100 ));

  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( state_map , 50 ));
  test_assert_int_equal( 101 , state_map_get_size( state_map ));
  state_map_free( state_map );
}
コード例 #5
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_copy() {
  state_map_type * state_map = state_map_alloc();
  state_map_iset( state_map , 0 , STATE_INITIALIZED );
  state_map_iset( state_map , 100 , STATE_INITIALIZED );
  {
    state_map_type * copy = state_map_alloc_copy( state_map );
    test_assert_true( state_map_equal( copy , state_map ));

    state_map_iset( state_map , 10 , STATE_INITIALIZED );
    test_assert_false( state_map_equal( copy , state_map ));                      
    
    state_map_free( copy );
  }
  state_map_free( state_map );
}
コード例 #6
0
ファイル: state_map.c プロジェクト: shulNN/ert
static void state_map_set_from_mask__( state_map_type * map , const bool_vector_type * mask , realisation_state_enum state, bool invert) {
  const bool * mask_ptr = bool_vector_get_ptr(mask);
  for (int i=0; i < bool_vector_size( mask); i++) {
    if (mask_ptr[i] != invert)
      state_map_iset(map , i , state);
  }
}
コード例 #7
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_update_matching( ) {
  state_map_type * map = state_map_alloc( );
  
  state_map_iset( map , 10 , STATE_INITIALIZED );
  state_map_iset( map , 3 , STATE_PARENT_FAILURE );
  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( map , 5 ) );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );

  state_map_update_matching( map , 5 , STATE_UNDEFINED | STATE_LOAD_FAILURE , STATE_INITIALIZED );
  state_map_update_matching( map , 10 , STATE_UNDEFINED | STATE_LOAD_FAILURE , STATE_INITIALIZED );
  state_map_update_matching( map , 3 , STATE_UNDEFINED | STATE_LOAD_FAILURE , STATE_INITIALIZED );
  
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 5 ) );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
  test_assert_int_equal( STATE_PARENT_FAILURE , state_map_iget( map , 3 ) );
  
  state_map_update_undefined( map , 10 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
  
  state_map_free( map );
}
コード例 #8
0
ファイル: enkf_main_manage_fs.c プロジェクト: eoia/ert
static void enkf_main_copy_ensemble( const enkf_main_type * enkf_main,
                                     enkf_fs_type * source_case_fs,
                                     int source_report_step,
                                     state_enum source_state,
                                     enkf_fs_type * target_case_fs,
                                     int target_report_step,
                                     state_enum target_state,
                                     const bool_vector_type * iens_mask,
                                     const char * ranking_key , /* It is OK to supply NULL - but if != NULL it must exist */
                                     const stringlist_type * node_list) {

    const int ens_size = enkf_main_get_ensemble_size( enkf_main );
    state_map_type * target_state_map = enkf_fs_get_state_map(target_case_fs);

    {
        int * ranking_permutation;
        int inode , src_iens;

        if (ranking_key != NULL) {
            ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
            ranking_permutation = (int *) ranking_table_get_permutation( ranking_table , ranking_key );
        } else {
            ranking_permutation = util_calloc( ens_size , sizeof * ranking_permutation );
            for (src_iens = 0; src_iens < ens_size; src_iens++)
                ranking_permutation[src_iens] = src_iens;
        }

        for (inode =0; inode < stringlist_get_size( node_list ); inode++) {
            enkf_config_node_type * config_node = ensemble_config_get_node( enkf_main_get_ensemble_config(enkf_main) , stringlist_iget( node_list , inode ));
            for (src_iens = 0; src_iens < enkf_main_get_ensemble_size( enkf_main ); src_iens++) {
                if (bool_vector_safe_iget(iens_mask , src_iens)) {
                    int target_iens = ranking_permutation[src_iens];
                    node_id_type src_id    = {.report_step = source_report_step , .iens = src_iens    , .state = source_state };
                    node_id_type target_id = {.report_step = target_report_step , .iens = target_iens , .state = target_state };

                    /* The copy is careful ... */
                    if (enkf_config_node_has_node( config_node , source_case_fs , src_id))
                        enkf_node_copy( config_node ,
                                        source_case_fs , target_case_fs ,
                                        src_id , target_id );

                    if (0 == target_report_step)
                        state_map_iset(target_state_map, target_iens, STATE_INITIALIZED);
                }
            }
        }

        if (ranking_permutation == NULL)
            free( ranking_permutation );
    }
}
コード例 #9
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_update_undefined( ) {
  state_map_type * map = state_map_alloc( );
  
  state_map_iset( map , 10 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( map , 5 ) );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );

  state_map_update_undefined( map , 5 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 5 ) );
  
  state_map_update_undefined( map , 10 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
  
  state_map_free( map );
}
コード例 #10
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_count_matching() {
  state_map_type * map1 = state_map_alloc();
  state_map_iset(map1 , 10 , STATE_INITIALIZED );

  state_map_iset(map1 , 15 , STATE_INITIALIZED );
  state_map_iset(map1 , 15 , STATE_HAS_DATA );

  state_map_iset(map1 , 16 , STATE_INITIALIZED );
  state_map_iset(map1 , 16 , STATE_HAS_DATA );
  state_map_iset(map1 , 16 , STATE_LOAD_FAILURE );
  
  test_assert_int_equal( 1 , state_map_count_matching( map1 , STATE_HAS_DATA));
  test_assert_int_equal( 2 , state_map_count_matching( map1 , STATE_HAS_DATA | STATE_LOAD_FAILURE));
  test_assert_int_equal( 3 , state_map_count_matching( map1 , STATE_HAS_DATA | STATE_LOAD_FAILURE | STATE_INITIALIZED));

  state_map_free( map1 );
}
コード例 #11
0
ファイル: enkf_state_map.c プロジェクト: andlaus/ResInsight
void test_equal() {
  state_map_type * state_map1 = state_map_alloc();
  state_map_type * state_map2 = state_map_alloc();

  test_assert_true( state_map_equal( state_map1 , state_map2 ));
  for (int i =0; i < 25; i++) {
    state_map_iset( state_map1 , i , STATE_INITIALIZED );
    state_map_iset( state_map2 , i , STATE_INITIALIZED );
  }
  test_assert_true( state_map_equal( state_map1 , state_map2 ));

  state_map_iset( state_map2 , 15 , STATE_HAS_DATA );
  test_assert_false( state_map_equal( state_map1 , state_map2 ));
  state_map_iset( state_map2 , 15 , STATE_LOAD_FAILURE );
  state_map_iset( state_map2 , 15 , STATE_INITIALIZED );
  test_assert_true( state_map_equal( state_map1 , state_map2 ));
  
  state_map_iset( state_map2 , 150 , STATE_INITIALIZED );
  test_assert_false( state_map_equal( state_map1 , state_map2 ));
}
コード例 #12
0
int main(int argc , char ** argv) {
  enkf_main_install_SIGNALS();
  const char * root_path = argv[1];
  const char * config_file = argv[2];
  const char * init_file = argv[3];
  const char * forward_init_string = argv[4];
  test_work_area_type * work_area = test_work_area_alloc(config_file );

  test_work_area_copy_directory_content( work_area , root_path );
  test_work_area_install_file( work_area , init_file );
  {

    bool forward_init;
    bool strict = true;
    enkf_main_type * enkf_main;

    test_assert_true( util_sscanf_bool( forward_init_string , &forward_init));

    util_clear_directory( "Storage" , true , true );
    enkf_main = enkf_main_bootstrap( config_file , strict , true );
    {
      enkf_state_type * state   = enkf_main_iget_state( enkf_main , 0 );
      enkf_node_type * surface_node = enkf_state_get_node( state , "SURFACE" );
      {
        const enkf_config_node_type * surface_config_node = enkf_node_get_config( surface_node );
        char * init_file1 = enkf_config_node_alloc_initfile( surface_config_node , NULL , 0);
        char * init_file2 = enkf_config_node_alloc_initfile( surface_config_node , "/tmp", 0);

        test_assert_bool_equal( enkf_config_node_use_forward_init( surface_config_node ) , forward_init );
        test_assert_string_equal( init_file1 , "Surface.irap");
        test_assert_string_equal( init_file2 , "/tmp/Surface.irap");

        free( init_file1 );
        free( init_file2 );
      }
  
      test_assert_bool_equal( enkf_node_use_forward_init( surface_node ) , forward_init );
      if (forward_init)
        test_assert_bool_not_equal( enkf_node_initialize( surface_node , 0 , enkf_state_get_rng( state )) , forward_init);
      // else hard_failure()
    }
    test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main )));
    
    if (forward_init) {
      enkf_state_type * state   = enkf_main_iget_state( enkf_main , 0 );
      enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
      run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , 0 ,0 , "simulations/run0");
      enkf_node_type * surface_node = enkf_state_get_node( state , "SURFACE" );
      node_id_type node_id = {.report_step = 0 ,  
                              .iens = 0,
                              .state = ANALYZED };

      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "simulations/run0" ));
      
      {
        int error = 0;
        stringlist_type * msg_list = stringlist_alloc_new();

                
        test_assert_false( enkf_node_has_data( surface_node , fs, node_id ));
        
        util_unlink_existing( "simulations/run0/Surface.irap" );
        
        test_assert_false( enkf_node_forward_init( surface_node , "simulations/run0" , 0 ));
        enkf_state_forward_init( state , run_arg , &error );
        test_assert_true(LOAD_FAILURE & error);

        error = 0;
        {
          enkf_fs_type * fs = enkf_main_get_fs(enkf_main);
          state_map_type * state_map = enkf_fs_get_state_map(fs);
          state_map_iset(state_map, 0, STATE_INITIALIZED);
        }
        enkf_state_load_from_forward_model(state, run_arg , &error, false, msg_list);

        stringlist_free( msg_list );
        test_assert_true(LOAD_FAILURE & error);
      }
      

      util_copy_file( init_file , "simulations/run0/Surface.irap");
      {
        int error = 0; 
        stringlist_type * msg_list = stringlist_alloc_new();

        
        test_assert_true( enkf_node_forward_init( surface_node , "simulations/run0" , 0 ));
        enkf_state_forward_init( state , run_arg , &error );
        test_assert_int_equal(0, error); 
        enkf_state_load_from_forward_model( state , run_arg , &error , false , msg_list );
        stringlist_free( msg_list );
        test_assert_int_equal(0, error); 

        {
          double value;
          test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); 
          test_assert_double_equal( 2735.7461 , value);

          test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); 
          test_assert_double_equal( 2737.0122 , value);
        }
      }
      util_clear_directory( "simulations" , true , true );
      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "simulations/run0" ));
      test_assert_true( util_is_file( "simulations/run0/SURFACE.INC" ));
      test_assert_true( enkf_node_fload( surface_node , "simulations/run0/SURFACE.INC"));
      {
        double value;
        test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); 
        test_assert_double_equal( 2735.7461 , value);
      
        test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); 
        test_assert_double_equal( 2737.0122 , value);
      }
      util_clear_directory( "simulations" , true , true );
    }
    enkf_main_free( enkf_main );
  }
}
コード例 #13
0
ファイル: state_map.c プロジェクト: shulNN/ert
void state_map_update_matching( state_map_type * map , int index , int state_mask , realisation_state_enum new_state) {
  realisation_state_enum current_state = state_map_iget( map , index );
  if (current_state & state_mask)
    state_map_iset( map , index , new_state );
}
コード例 #14
0
ファイル: state_map.c プロジェクト: myrseth/ert
void state_map_update_undefined( state_map_type * map , int index , realisation_state_enum new_state) {
  realisation_state_enum current_state = state_map_iget( map , index );
  if (current_state == STATE_UNDEFINED)
    state_map_iset( map , index , new_state );
}
コード例 #15
0
int main(int argc , char ** argv) {
  enkf_main_install_SIGNALS();
  const char * root_path = argv[1];
  const char * config_file = argv[2];
  const char * forward_init_string = argv[3];
  test_work_area_type * work_area = test_work_area_alloc(config_file );
  test_work_area_copy_directory_content( work_area , root_path );
  {  
    bool forward_init;
    bool strict = true;
    enkf_main_type * enkf_main;
    
    test_assert_true( util_sscanf_bool( forward_init_string , &forward_init));
    
    util_clear_directory( "Storage" , true , true );
    enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true );
    {
      enkf_state_type * state   = enkf_main_iget_state( enkf_main , 0 );
      enkf_node_type * gen_kw_node = enkf_state_get_node( state , "MULTFLT" );
      {
        const enkf_config_node_type * gen_kw_config_node = enkf_node_get_config( gen_kw_node );
        char * init_file1 = enkf_config_node_alloc_initfile( gen_kw_config_node , NULL , 0);
        char * init_file2 = enkf_config_node_alloc_initfile( gen_kw_config_node , "/tmp", 0);
        
        test_assert_bool_equal( enkf_config_node_use_forward_init( gen_kw_config_node ) , forward_init );
        test_assert_string_equal( init_file1 , "MULTFLT_INIT");
        test_assert_string_equal( init_file2 , "/tmp/MULTFLT_INIT");
        
        free( init_file1 );
        free( init_file2 );
      }
      
      test_assert_bool_equal( enkf_node_use_forward_init( gen_kw_node ) , forward_init );
      if (forward_init)
        test_assert_bool_not_equal( enkf_node_initialize( gen_kw_node , 0 , enkf_state_get_rng( state )) , forward_init);
      // else hard_failure()
    }
    test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main )));
    
    if (forward_init) {
      enkf_state_type * state   = enkf_main_iget_state( enkf_main , 0 );
      enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
      run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , 0 , 0 , "simulations/run0");
      enkf_node_type * gen_kw_node = enkf_state_get_node( state , "MULTFLT" );
      node_id_type node_id = {.report_step = 0 ,  
                              .iens = 0,
                              .state = ANALYZED };
      
      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "simulations/run0" ));
      
      {
        int error = 0;
        stringlist_type * msg_list = stringlist_alloc_new();
        bool_vector_type * iactive = bool_vector_alloc( enkf_main_get_ensemble_size( enkf_main ) , true);
        
        test_assert_false( enkf_node_has_data( gen_kw_node , fs, node_id ));
        util_unlink_existing( "simulations/run0/MULTFLT_INIT" );
        

        test_assert_false( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 ));
        enkf_state_forward_init( state , run_arg ,  &error );
        test_assert_true(LOAD_FAILURE & error);
        
        error = 0;
        {
          enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
          state_map_type * state_map = enkf_fs_get_state_map(fs);
          state_map_iset(state_map , 0 , STATE_INITIALIZED);
        }
        enkf_state_load_from_forward_model( state , run_arg ,  &error , false , msg_list );
        stringlist_free( msg_list );
        bool_vector_free( iactive );
        test_assert_true(LOAD_FAILURE & error);
      }
      
      
      
      {
        FILE * stream = util_fopen("simulations/run0/MULTFLT_INIT" , "w");
        fprintf(stream , "123456.0\n" );
        fclose( stream );
      }
      
      {
        int error = 0;
        stringlist_type * msg_list = stringlist_alloc_new();

        test_assert_true( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 ));
        enkf_state_forward_init( state , run_arg ,  &error );
        test_assert_int_equal(0, error);
        enkf_state_load_from_forward_model( state , run_arg , &error , false , msg_list );
       
        stringlist_free( msg_list );
        test_assert_int_equal(0, error);

        {
          double value;
          test_assert_true( enkf_node_user_get( gen_kw_node , fs , "MULTFLT" , node_id , &value)); 
          test_assert_double_equal( 123456.0 , value);
        }
      }

      test_assert_true( util_is_file ("simulations/run0/parameters.txt")); //Export of gen kw params

      util_clear_directory( "simulations" , true , true );
      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "simulations/run0" ));
      test_assert_true( util_is_file( "simulations/run0/MULTFLT.INC" ));
      {
        FILE * stream = util_fopen("simulations/run0/MULTFLT.INC" , "r");
        double value;
        fscanf(stream , "%lg" , &value);
        fclose( stream );
        test_assert_double_equal( 123456.0 , value);
      }
      util_clear_directory( "simulations" , true , true );
      run_arg_free( run_arg );
    }
    enkf_main_free( enkf_main );
  }
  test_work_area_free( work_area );
}