Exemplo n.º 1
0
void test_stop_long_running( ) {
  analysis_config_type * ac = create_analysis_config( );
  test_assert_bool_equal( false , analysis_config_get_stop_long_running( ac ) );
  analysis_config_set_stop_long_running( ac , true );
  test_assert_bool_equal( true , analysis_config_get_stop_long_running( ac ) );
  analysis_config_free( ac );
}
Exemplo n.º 2
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 );
  test_work_area_set_store(work_area, true); 
  
  bool strict = true;
  enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true );
  enkf_fs_type * init_fs = enkf_main_get_fs(enkf_main);
  enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 );
  run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( init_fs , 0 ,0 , "simulations/run0");
  enkf_node_type * field_node = enkf_state_get_node( state , "PORO" );
  
  bool forward_init;
  test_assert_true( util_sscanf_bool( forward_init_string , &forward_init));
  test_assert_bool_equal( enkf_node_use_forward_init( field_node ) , forward_init );
  test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main )));
  
  util_clear_directory( "Storage" , true , true );
  
  create_runpath( enkf_main );
  test_assert_true( util_is_directory( "simulations/run0" ));

  if (forward_init)
    util_copy_file( init_file , "simulations/run0/petro.grdecl");

  {
    bool_vector_type * iactive = bool_vector_alloc( enkf_main_get_ensemble_size(enkf_main) , true);
    int error = 0;
    stringlist_type * msg_list = stringlist_alloc_new();  
    enkf_state_load_from_forward_model( state , run_arg ,  &error , false , msg_list );
    stringlist_free( msg_list );
    bool_vector_free( iactive );
    test_assert_int_equal(error, 0); 
  }

  test_assert_true(check_original_exported_data_equal(field_node));

  run_arg_free( run_arg );
  enkf_main_free(enkf_main);    
  test_work_area_free(work_area); 
}
Exemplo n.º 3
0
void create_test_area(const char * test_name , bool store) {
  char * pre_cwd = util_alloc_cwd();
  test_work_area_type * work_area = test_work_area_alloc( test_name , store);
  char * work_path = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
  
  test_assert_true( util_is_directory( work_path ));
  test_work_area_free( work_area );
  test_assert_bool_equal( store , util_entry_exists( work_path ));
  
  {
    char * post_cwd = util_alloc_cwd();
    test_assert_string_equal( pre_cwd , post_cwd );
    free( post_cwd );
  }
  free( pre_cwd );
  free( work_path );
}
Exemplo n.º 4
0
void test_case_no_path( const char * sum_case , bool expected_exist) {
  path_stack_type * path_stack = path_stack_alloc();
  path_stack_push_cwd( path_stack );
  {
    char * basename , *path;

    util_alloc_file_components( sum_case , &path , &basename , NULL );
    if (path)
      chdir( path );
    test_assert_bool_equal(expected_exist ,  ecl_sum_case_exists( basename ));

    free( path );
    free( basename );
  }
  path_stack_pop( path_stack );
  path_stack_free( path_stack );
}
Exemplo n.º 5
0
int main(int argc , char ** argv) {

  hash_type * h = hash_alloc();

  test_assert_bool_equal( hash_add_option( h , "Key" ) , false );
  test_assert_false( hash_add_option( h , "Key" ) );

  test_assert_true( hash_add_option( h , "Key1:Value" ) );
  test_assert_true( hash_add_option( h , "Key2:Value1:Value2" ) );
  test_assert_true( hash_add_option( h , "Key3:Value1:value2:Value3" ) );

  test_assert_string_equal( (const char *) hash_get( h , "Key1" ) , "Value" );
  test_assert_string_equal( (const char *) hash_get( h , "Key2" ) , "Value1:Value2" );
  test_assert_string_equal( (const char *) hash_get( h , "Key3" ) , "Value1:value2:Value3" );

  test_assert_false( hash_has_key( h , "Key" ));

  hash_free( h );
  exit(0);
}
Exemplo n.º 6
0
int main( int argc , char ** argv) {
    const char * case1 = argv[1];
    const char * case2 = argv[2];
    const char * compatible_string = argv[3];
    bool compatible;
    ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":");
    ecl_sum_type * ecl_sum2 = ecl_sum_fread_alloc_case( case2 , ":");

    test_assert_true( ecl_sum_is_instance( ecl_sum1 ));
    test_assert_true( ecl_sum_is_instance( ecl_sum2 ));
    test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) );
    test_assert_true( util_sscanf_bool( compatible_string , &compatible ));

    test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) );
    test_assert_true( ecl_sum_report_step_compatible( ecl_sum2 , ecl_sum2) );
    test_assert_bool_equal( compatible , ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum2 ));

    ecl_sum_free( ecl_sum1 );
    ecl_sum_free( ecl_sum2 );
    exit(0);
}
Exemplo n.º 7
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 , false);
  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_param_node = enkf_state_get_node( state , "PARAM" );
      {
        const enkf_config_node_type * gen_param_config_node = enkf_node_get_config( gen_param_node );
        char * init_file1 = enkf_config_node_alloc_initfile( gen_param_config_node , NULL , 0);
        char * init_file2 = enkf_config_node_alloc_initfile( gen_param_config_node , "/tmp", 0);

        test_assert_bool_equal( enkf_config_node_use_forward_init( gen_param_config_node ) , forward_init );
        test_assert_string_equal( init_file1 , "PARAM_INIT");
        test_assert_string_equal( init_file2 , "/tmp/PARAM_INIT");

        free( init_file1 );
        free( init_file2 );
      }
  
      test_assert_bool_equal( enkf_node_use_forward_init( gen_param_node ) , forward_init );
      if (forward_init)
        test_assert_bool_not_equal( enkf_node_initialize( gen_param_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 );
      enkf_node_type * gen_param_node = enkf_state_get_node( state , "PARAM" );
      node_id_type node_id = {.report_step = 0 ,  
                              .iens = 0,
                              .state = ANALYZED };

      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "simulations/run0" ));
      
      {
        run_mode_type run_mode = ENSEMBLE_EXPERIMENT; 
        enkf_main_init_run(enkf_main , run_mode);     /* This is ugly */
        
        
        test_assert_false( enkf_node_has_data( gen_param_node , fs, node_id ));
        util_unlink_existing( "simulations/run0/PARAM_INIT" );
      }
      


      {
        FILE * stream = util_fopen("simulations/run0/PARAM_INIT" , "w");
        fprintf(stream , "0\n1\n2\n3\n" );
        fclose( stream );
      }
      
      {
        bool loadOK = true;
        stringlist_type * msg_list = stringlist_alloc_new();

        {
          run_mode_type run_mode = ENSEMBLE_EXPERIMENT; 
          enkf_main_init_run(enkf_main , run_mode);     /* This is ugly */
        }
        
        test_assert_true( enkf_node_forward_init( gen_param_node , "simulations/run0" , 0 ));
        enkf_state_forward_init( state , fs , &loadOK );
        test_assert_true( loadOK );
        enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
        stringlist_free( msg_list );
        test_assert_true( loadOK );

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

          test_assert_true( enkf_node_user_get( gen_param_node , fs , "1" , node_id , &value)); 
          test_assert_double_equal( 1 , value);

          test_assert_true( enkf_node_user_get( gen_param_node , fs , "2" , node_id , &value)); 
          test_assert_double_equal( 2 , 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/PARAM.INC" ));
      {
        FILE * stream = util_fopen("simulations/run0/PARAM.INC" , "r");
        double v0,v1,v2,v3;
        fscanf(stream , "%lg %lg %lg %lg" , &v0,&v1,&v2,&v3);
        fclose( stream );                
        test_assert_double_equal( 0 , v0);
        test_assert_double_equal( 1 , v1);
        test_assert_double_equal( 2 , v2);
        test_assert_double_equal( 3 , v3);
      }
      util_clear_directory( "simulations" , true , true );
    }
    enkf_main_free( enkf_main );
  }
  test_work_area_free( work_area );
}
Exemplo n.º 8
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 );
  }
}
Exemplo n.º 9
0
int main(int argc , char ** argv) {
  const char * Xfile = argv[1];
  bool MSW;
  ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
  ecl_rsthead_type * rst_head = ecl_rsthead_alloc( ecl_file_get_global_view(rst_file) , ecl_util_filename_report_nr( Xfile ));
  
  test_install_SIGNALS();
  test_assert_true( util_sscanf_bool( argv[2] , &MSW ));
  test_assert_not_NULL( rst_file );
  test_assert_not_NULL( rst_head );
  
  {
    int iwell;
    const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
    const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
    ecl_kw_type * scon_kw = NULL;

    bool caseMSW = false;

    for (iwell = 0; iwell < rst_head->nwells; iwell++) {
      const int iwel_offset = rst_head->niwelz * iwell;
      int num_connections   = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_CONNECTIONS_INDEX );
      int iconn;
      well_conn_collection_type * wellcc = well_conn_collection_alloc( );
      well_conn_collection_type * wellcc_ref = well_conn_collection_alloc();

      for (iconn = 0; iconn < num_connections; iconn++) {
        well_conn_type * conn = well_conn_alloc_from_kw( icon_kw , scon_kw , rst_head , iwell , iconn );
        
        test_assert_true( well_conn_is_instance( conn ));
        test_assert_not_NULL( conn );
        if (!MSW)
          test_assert_bool_equal( well_conn_MSW( conn ) , MSW);
        else
          caseMSW |= well_conn_MSW( conn );
        
        well_conn_collection_add( wellcc , conn );
        well_conn_collection_add_ref( wellcc_ref , conn );
        test_assert_int_equal( iconn + 1 , well_conn_collection_get_size( wellcc ));
        test_assert_ptr_equal( well_conn_collection_iget_const( wellcc , iconn) , conn);
        test_assert_ptr_equal( well_conn_collection_iget_const( wellcc_ref , iconn) , conn);
      }
      well_conn_collection_free( wellcc_ref );
      {

        int i;
        for (i=0; i < well_conn_collection_get_size( wellcc ); i++)
          test_assert_true( well_conn_is_instance( well_conn_collection_iget_const( wellcc , i )));
        
      }
      {
        well_conn_collection_type * wellcc2 = well_conn_collection_alloc();
        int i;
        
        test_assert_int_equal( well_conn_collection_get_size( wellcc ) , 
                               well_conn_collection_load_from_kw( wellcc2 , iwel_kw , icon_kw , scon_kw , iwell , rst_head));
        
        for (i=0; i < well_conn_collection_get_size( wellcc2 ); i++) {
          test_assert_true( well_conn_is_instance( well_conn_collection_iget_const( wellcc2 , i )));
          test_assert_true( well_conn_equal( well_conn_collection_iget_const( wellcc2 , i ) , well_conn_collection_iget_const( wellcc , i )));
        }
        well_conn_collection_free( wellcc2 );
      }
      well_conn_collection_free( wellcc );
    }
    test_assert_bool_equal( caseMSW , MSW);
  }
  

  exit( 0 );
}
Exemplo n.º 10
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 );
}
Exemplo n.º 11
0
int main(int argc , char ** argv) {
  int i = 10;
  int j = 5;
  int k = 16;
  double CF = 0;
  bool open = true;
  test_install_SIGNALS();

  {
    well_conn_dir_enum dir = well_conn_dirX;
    well_conn_type * conn = well_conn_alloc(i,j,k,CF,dir,open);
    well_conn_type * conn2 = well_conn_alloc(i,j,k,CF,dir,open);
    well_conn_type * conn3 = well_conn_alloc(i,j,k+1,CF,dir,open);
    test_assert_not_NULL( conn );
    test_assert_true( well_conn_is_instance( conn ));
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_false( well_conn_MSW( conn ));
    test_assert_true( well_conn_matrix_connection( conn ));
    test_assert_true( well_conn_equal( conn , conn2 ));
    test_assert_false( well_conn_equal( conn , conn3 ));
    test_assert_double_equal( CF , well_conn_get_connection_factor( conn ));
    well_conn_free( conn3 );
    well_conn_free( conn2 );
    well_conn_free( conn );
  }

  {
    well_conn_dir_enum dir = well_conn_fracX;
    well_conn_type * conn = well_conn_alloc(i,j,k,CF,dir,open);
    test_assert_NULL( conn );
  }


  {
    well_conn_dir_enum dir = well_conn_fracX;
    well_conn_type * conn = well_conn_alloc_fracture(i,j,k,CF,dir,open);
    test_assert_not_NULL( conn );
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_false( well_conn_MSW( conn ));
    test_assert_false( well_conn_matrix_connection( conn ));
    test_assert_true( well_conn_fracture_connection( conn ));
    well_conn_free( conn );
  }


  {
    well_conn_dir_enum dir = well_conn_dirX;
    well_conn_type * conn = well_conn_alloc_fracture(i,j,k,CF,dir,open);
    test_assert_not_NULL( conn );
    well_conn_free( conn );
  }

  {
    int segment = 16;
    well_conn_dir_enum dir = well_conn_dirX;
    well_conn_type * conn = well_conn_alloc_MSW(i,j,k,CF,dir,open,segment);
    test_assert_not_NULL( conn );
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_int_equal( segment , well_conn_get_segment_id( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_true( well_conn_MSW( conn ));
    test_assert_true( well_conn_matrix_connection( conn ));
    well_conn_free( conn );
  }


  {
    int segment = 16;
    well_conn_dir_enum dir = well_conn_fracX;
    well_conn_type * conn = well_conn_alloc_fracture_MSW(i,j,k,CF,dir,open,segment);
    test_assert_not_NULL( conn );
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_int_equal( segment , well_conn_get_segment_id( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_true( well_conn_MSW( conn ));
    test_assert_false( well_conn_matrix_connection( conn ));
    well_conn_free( conn );
  }

  test_conn_rate();

}
int main(int argc , char ** argv) {
  enkf_main_install_SIGNALS();
  {
    const char * config_file = argv[1];
    const char * init_file = argv[2];
    const char * forward_init_string = argv[3];
    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( "/tmp/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 * 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 );
      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( "/tmp/simulations/run0" ));
      
      {
        bool loadOK = true;
        stringlist_type * msg_list = stringlist_alloc_new();

        {
          run_mode_type run_mode = ENSEMBLE_EXPERIMENT; 
          enkf_main_init_run(enkf_main , run_mode);     /* This is ugly */
        }
        
        
        test_assert_false( enkf_node_has_data( surface_node , fs, node_id ));
        
        util_unlink_existing( "/tmp/simulations/run0/Surface.irap" );
        
        test_assert_false( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 ));
        enkf_state_forward_init( state , fs , &loadOK );
        test_assert_false( loadOK );

        loadOK = true;
        enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
        stringlist_free( msg_list );
        test_assert_false( loadOK );
      }
      

      util_copy_file( init_file , "/tmp/simulations/run0/Surface.irap");
      {
        bool loadOK = true;
        stringlist_type * msg_list = stringlist_alloc_new();

        {
          run_mode_type run_mode = ENSEMBLE_EXPERIMENT; 
          enkf_main_init_run(enkf_main , run_mode);     /* This is ugly */
        }
        
        test_assert_true( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 ));
        enkf_state_forward_init( state , fs , &loadOK );
        test_assert_true( loadOK );
        enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list );
        stringlist_free( msg_list );
        test_assert_true( loadOK );

        {
          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( "/tmp/simulations" , true , true );
      create_runpath( enkf_main );
      test_assert_true( util_is_directory( "/tmp/simulations/run0" ));
      test_assert_true( util_is_file( "/tmp/simulations/run0/SURFACE.INC" ));
      test_assert_true( enkf_node_fload( surface_node , "/tmp/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( "/tmp/simulations" , true , true );
    }
    enkf_main_free( enkf_main );
  }
}
Exemplo n.º 13
0
void test_case( const char * sum_case , bool expected_exist) {
  test_assert_bool_equal( expected_exist , ecl_sum_case_exists( sum_case ));
}