Beispiel #1
0
void * enkf_main_init_case_from_existing_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );

  const char * source_case = stringlist_iget( args , 0 );
  enkf_fs_type * source_fs = enkf_main_mount_alt_fs( enkf_main , source_case , true );
  {
    enkf_fs_type * target_fs;

    if (stringlist_get_size(args) > 1) {
      const char * current_case = enkf_main_get_current_fs(enkf_main);
      const char * target_case = stringlist_iget( args , 1 );
      if (0 != strcmp(current_case, target_case)) {
        target_fs = enkf_main_mount_alt_fs( enkf_main , target_case , true );
      } else
        target_fs = enkf_fs_get_ref( enkf_main_get_fs(enkf_main) );  // Using get_ref so that we can unconditionally call decref() further down.
    } else
      target_fs = enkf_fs_get_ref( enkf_main_get_fs(enkf_main) );    // Using get_ref so that we can unconditionally call decref() further down.

    enkf_main_init_case_from_existing(enkf_main, source_fs, 0, ANALYZED, target_fs);
    enkf_fs_decref(target_fs);
  }
  enkf_fs_decref(source_fs);

  return NULL;
}
Beispiel #2
0
void * enkf_main_analysis_update_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  enkf_fs_type   * source_fs = enkf_main_mount_alt_fs( enkf_main , stringlist_iget(args , 0 ) , false);
  enkf_fs_type   * target_fs = enkf_main_mount_alt_fs( enkf_main , stringlist_iget(args , 1 ) , true);

  enkf_main_smoother_update( enkf_main , source_fs , target_fs);

  enkf_fs_decref( source_fs );
  enkf_fs_decref( target_fs );
  return NULL;
}
void test_init_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) {
  stringlist_type * args = stringlist_alloc_new();
  enkf_main_type * enkf_main = ert_test_context_get_main(test_context);

  test_assert_true( ert_test_context_install_workflow_job( test_context , "JOB" , job_file ) );

  //Test init current case from existing
  {
    enkf_fs_type * cur_fs = enkf_main_mount_alt_fs( enkf_main , "new_current_case" , true );
    enkf_main_select_fs(enkf_main, "new_current_case");

    test_assert_ptr_not_equal(cur_fs , enkf_main_get_fs( enkf_main ));

    stringlist_append_copy( args, "default"); //case to init from
    test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) );

    enkf_fs_decref(cur_fs);
  }

  {
    const char * current_case = enkf_main_get_current_fs( enkf_main );
    test_assert_string_equal(current_case, "new_current_case");
    test_assert_true(enkf_fs_has_node(enkf_main_get_fs(enkf_main), "PERMZ", PARAMETER, 0, 0, ANALYZED));

    enkf_fs_type * default_fs          = enkf_main_mount_alt_fs( enkf_main , "default" , true  );
    state_map_type * default_state_map = enkf_fs_get_state_map(default_fs);
    state_map_type * current_state_map = enkf_fs_get_state_map(enkf_main_get_fs(enkf_main));
    test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(current_state_map));
    enkf_fs_decref(default_fs);
  }


  //Test init case from existing case:
  stringlist_clear(args);
  stringlist_append_copy(args, "default"); //case to init from
  stringlist_append_copy(args, "new_not_current_case");
  test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) );
  {
    enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main, "new_not_current_case", true);
    test_assert_not_NULL( fs );
    test_assert_true( enkf_fs_has_node(fs, "PERMZ", PARAMETER, 0, 0, ANALYZED ));

    enkf_fs_type * default_fs          = enkf_main_mount_alt_fs( enkf_main , "default" , true );
    state_map_type * default_state_map = enkf_fs_get_state_map(default_fs);
    state_map_type * new_state_map     = enkf_fs_get_state_map(fs);
    test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(new_state_map));
    enkf_fs_decref(fs);
  }

  stringlist_free( args );
}
Beispiel #4
0
void enkf_tui_fs_initialize_case_from_copy(void * arg) 
{
  int prompt_len =50;
  char * source_case;
  int ens_size;
  int last_report;
  int src_step;
  state_enum src_state;
  enkf_main_type   * enkf_main = enkf_main_safe_cast( arg );

  ens_size = enkf_main_get_ensemble_size( enkf_main );

  
  last_report  = enkf_main_get_history_length( enkf_main );

  source_case = enkf_tui_fs_alloc_existing_case( enkf_main , "Initialize from case" , prompt_len);
  if (source_case != NULL) {                                              
    src_step                 = util_scanf_int_with_limits("Source report step",prompt_len , 0 , last_report);
    src_state                = enkf_tui_util_scanf_state("Source analyzed/forecast [A|F]" , prompt_len , false);
    enkf_fs_type * source_fs = enkf_main_mount_alt_fs( enkf_main , source_case , false );
    enkf_main_init_current_case_from_existing(enkf_main, source_fs , src_step , src_state);
    enkf_fs_decref(source_fs);
  }
  util_safe_free( source_case );
}
Beispiel #5
0
void * enkf_main_create_case_JOB( void * self , const stringlist_type * args) {
  enkf_main_type * enkf_main = enkf_main_safe_cast( self );
  const char * new_case = stringlist_iget( args , 0 );
  enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , new_case , true );
  enkf_fs_decref( fs );
  return NULL;
}
void enkf_main_set_fs( enkf_main_type * enkf_main , enkf_fs_type * fs , const char * case_path /* Can be NULL */) {
  if (enkf_main->dbase != fs) {
    enkf_fs_incref( fs );

    if (enkf_main->dbase)
      enkf_fs_decref( enkf_main->dbase );

    enkf_main->dbase = fs;
    enkf_main_invalidate_cache(enkf_main);
    enkf_main_update_current_case(enkf_main, case_path);
  }
}
Beispiel #7
0
void enkf_main_set_fs( enkf_main_type * enkf_main , enkf_fs_type * fs , const char * case_path /* Can be NULL */) {
  if (enkf_main->dbase != fs) {
    enkf_fs_incref( fs );

    if (enkf_main->dbase)
      enkf_fs_decref(enkf_main->dbase);

    enkf_main->dbase = fs;
    enkf_main_update_current_case(enkf_main, case_path);

    enkf_main_update_summary_config_from_fs__(enkf_main, fs);
    enkf_main_update_custom_kw_config_from_fs__(enkf_main, fs);
  }
}
Beispiel #8
0
void * enkf_main_analysis_update_JOB( void * self , const stringlist_type * args) {
  enkf_main_type   * enkf_main = enkf_main_safe_cast( self );
  enkf_fs_type * target_fs;
  int target_step;
  int_vector_type * step_list;
  bool decrease_ref = false;

  // Argument 0: Which case to write to
  if (stringlist_get_size(args)) {
    const char * target_fs_name = stringlist_iget( args , 0 );
    if (strcmp( target_fs_name , CURRENT_CASE_STRING) == 0)
      target_fs = enkf_main_get_fs( enkf_main );
    else {
      target_fs = enkf_main_mount_alt_fs( enkf_main , target_fs_name , true);
      decrease_ref = true;
    }
  } else
      target_fs = enkf_main_get_fs( enkf_main );
  {


    // Argument 1: The number of the step to write to
    if (stringlist_get_size(args) > 1)
      util_sscanf_int(stringlist_iget( args , 1) , &target_step);
    else
      target_step = 0;

    // Argument 2 - ??: The timesteps to use in the update
    if (stringlist_get_size( args ) > 2) {
      char * step_args = stringlist_alloc_joined_substring(args , 2 , stringlist_get_size(args) , " ");
      step_list = string_util_alloc_active_list( step_args );
      free( step_args );
    } else {
      int stride = 1;
      time_map_type * time_map = enkf_fs_get_time_map( enkf_main_get_fs( enkf_main ));
      step_list = enkf_main_update_alloc_step_list( enkf_main , 0 , time_map_get_last_step( time_map ) , stride);
    }

    enkf_main_UPDATE( enkf_main , step_list , target_fs , target_step , SMOOTHER_UPDATE);

    int_vector_free( step_list );

    if (decrease_ref)
      enkf_fs_decref( target_fs );
  }
  return NULL;
}
Beispiel #9
0
void enkf_main_select_fs( enkf_main_type * enkf_main , const char * case_path ) {
    if (enkf_main_case_is_current( enkf_main , case_path ))
        return;  /* We have tried to select the currently selected case - just return. */
    else {
        enkf_fs_type * new_fs = enkf_main_mount_alt_fs( enkf_main , case_path , true );
        if (enkf_main->dbase == new_fs)
            util_abort("%s : return reference to current FS in situation where that should not happen.\n",__func__);

        if (new_fs != NULL)
            enkf_main_set_fs( enkf_main , new_fs , case_path);
        else {
            const char * ens_path = model_config_get_enspath( enkf_main->model_config );
            util_exit("%s: select filesystem %s:%s failed \n",__func__ , ens_path , case_path );
        }
        enkf_fs_decref( new_fs );
    }
}
Beispiel #10
0
static bool enkf_main_case_is_initialized__( const enkf_main_type * enkf_main , enkf_fs_type * fs , bool_vector_type * __mask) {
    stringlist_type  * parameter_keys = ensemble_config_alloc_keylist_from_var_type( enkf_main->ensemble_config , PARAMETER );
    bool_vector_type * mask;
    bool initialized = true;
    int ikey = 0;
    if (__mask != NULL)
        mask = __mask;
    else
        mask = bool_vector_alloc(0 , true );

    while ((ikey < stringlist_get_size( parameter_keys )) && (initialized)) {
        const enkf_config_node_type * config_node = ensemble_config_get_node( enkf_main->ensemble_config , stringlist_iget( parameter_keys , ikey) );
        int iens = 0;
        do {
            if (bool_vector_safe_iget( mask , iens)) {
                node_id_type node_id = {.report_step = 0 , .iens = iens , .state = ANALYZED };
                initialized = enkf_config_node_has_node( config_node , fs , node_id);
            }
            iens++;
        } while ((iens < enkf_main->ens_size) && (initialized));
        ikey++;
    }

    stringlist_free( parameter_keys );
    if (__mask == NULL)
        bool_vector_free( mask );
    return initialized;
}



bool enkf_main_case_is_initialized( const enkf_main_type * enkf_main , const char * case_name ,  bool_vector_type * __mask) {
    enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main , case_name , false );
    if (fs) {
        bool initialized = enkf_main_case_is_initialized__(enkf_main , fs , __mask);
        enkf_fs_decref( fs );
        return initialized;
    } else
        return false;
}
Beispiel #11
0
static void enkf_tui_fs_copy_ensemble__(
  enkf_main_type * enkf_main,
  const char     * source_case,
  const char     * target_case,
  int              report_step_from,
  state_enum       state_from,
  int              report_step_to,
  state_enum       state_to,
  bool             only_parameters)
{
  msg_type       * msg          = msg_alloc("Copying: " , false);
  ensemble_config_type * config = enkf_main_get_ensemble_config(enkf_main);
  int ens_size                  = enkf_main_get_ensemble_size(enkf_main);
  char * ranking_key;
  const int  * ranking_permutation = NULL;
  int  * identity_permutation;
  ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
  

  if (ranking_table_get_size( ranking_table ) > 0) {
    util_printf_prompt("Name of ranking to resort by (or blank)" , 50  , '=' , "=> ");
    ranking_key = util_alloc_stdin_line();
    if (ranking_table_has_ranking( ranking_table , ranking_key )) 
      ranking_permutation = ranking_table_get_permutation( ranking_table , ranking_key );
    else {
      fprintf(stderr," Sorry: ranking:%s does not exist \n", ranking_key );
      return;
    }
  }
  identity_permutation = util_calloc( ens_size , sizeof * identity_permutation );
  {
    int iens;
    for (iens =0; iens < ens_size; iens++) 
      identity_permutation[iens] = iens;
  }

  if (ranking_permutation == NULL)
    ranking_permutation = identity_permutation;
  

  {
    /* If the current target_case does not exist it is automatically created by the select_write_dir function */
    enkf_fs_type * src_fs    = enkf_main_mount_alt_fs( enkf_main , source_case , false );
    enkf_fs_type * target_fs = enkf_main_mount_alt_fs( enkf_main , target_case , true );
    
    stringlist_type * nodes = ensemble_config_alloc_keylist_from_var_type(config, PARAMETER);
    
    {
      int num_nodes = stringlist_get_size(nodes);
      msg_show(msg);
      for(int i = 0; i < num_nodes; i++) {
        const char * key = stringlist_iget(nodes, i);
        enkf_config_node_type * config_node = ensemble_config_get_node(config , key);
        msg_update(msg , key);
        enkf_node_copy_ensemble(config_node, src_fs , target_fs , report_step_from, state_from, report_step_to , state_to , ens_size , ranking_permutation);
      }
    }
    
    enkf_fs_decref( src_fs );
    enkf_fs_decref( target_fs );
    
    msg_free(msg , true);
    stringlist_free(nodes);
  }
  free( identity_permutation );
}
Beispiel #12
0
void enkf_main_close_fs( enkf_main_type * enkf_main ) {
  if (enkf_main->dbase != NULL)
    enkf_fs_decref( enkf_main->dbase );
}
Beispiel #13
0
int main(int argc, char ** argv) {
  const char * config_file = argv[1];
  test_work_area_type * work_area = test_work_area_alloc( "enkf_main_fs" );
  char * model_config;
  util_alloc_file_components( config_file , NULL , &model_config , NULL);
  test_work_area_copy_parent_content( work_area , config_file );
  {
    const char * site_config = "/project/res/etc/ERT/site-config";
    enkf_main_type * enkf_main = enkf_main_bootstrap( site_config , model_config , false , false );

    enkf_main_select_fs( enkf_main , "enkf");
    test_assert_true( enkf_main_case_is_current( enkf_main , "enkf"));
    test_assert_false( enkf_main_case_is_current( enkf_main , "default_fs"));
    test_assert_false( enkf_main_case_is_current( enkf_main , "does_not_exist"));

    test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    {
      enkf_fs_type * fs_ref = enkf_main_get_fs_ref( enkf_main );
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( fs_ref );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }

    {
      state_map_type * map1 = enkf_fs_get_state_map( enkf_main_get_fs( enkf_main ));
      state_map_type * map2 = enkf_main_alloc_readonly_state_map(enkf_main , "enkf");
      test_assert_true(state_map_equal( map1 , map2 ));
      state_map_free( map2 );
    }
    {
      enkf_fs_type * fs1 = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      enkf_fs_type * fs2 = enkf_main_mount_alt_fs( enkf_main , "enkf" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      test_assert_int_equal( 2 , enkf_fs_get_refcount( fs2 ));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( fs1 ));

      enkf_fs_decref( fs1 );
      enkf_fs_decref( fs2 );
    }

    {
      enkf_fs_type * enkf_fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false  );
      
      enkf_main_select_fs( enkf_main , "default");
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( enkf_fs );
    }

    {
      enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_main_select_fs( enkf_main , "default");
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( default_fs );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }
    /*****************************************************************/
    {
      enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "default" , false  );
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      
      enkf_main_set_fs( enkf_main , fs , NULL );
      enkf_fs_decref( fs );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }
    {
      enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false );
      enkf_fs_type * current = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( current ));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( fs));
      enkf_main_set_fs( enkf_main , fs , NULL);
      test_assert_int_equal( 2 , enkf_fs_get_refcount( fs));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( current ));

      enkf_fs_decref( current );
      enkf_fs_decref( fs);
    }

    
    

    test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    enkf_main_free( enkf_main );
  }
  test_work_area_free( work_area );
  exit(0);
}