Пример #1
0
model_config_type * model_config_alloc() {
  model_config_type * model_config  = util_malloc(sizeof * model_config );
  /**
     There are essentially three levels of initialisation:

     1. Initialize to NULL / invalid.
     2. Initialize with default values.
     3. Initialize with user supplied values.

  */
  UTIL_TYPE_ID_INIT(model_config , MODEL_CONFIG_TYPE_ID);
  model_config->case_names                = NULL;
  model_config->enspath                   = NULL;
  model_config->rftpath                   = NULL;
  model_config->dbase_type                = INVALID_DRIVER_ID;
  model_config->current_runpath           = NULL;
  model_config->current_path_key          = NULL;
  model_config->enkf_sched                = NULL;
  model_config->enkf_sched_file           = NULL;   
  model_config->case_table_file           = NULL;
  model_config->select_case               = NULL;    
  model_config->history                   = NULL;
  model_config->jobname_fmt               = NULL;
  model_config->forward_model             = NULL;
  model_config->internalize_state         = bool_vector_alloc( 0 , false );
  model_config->__load_state              = bool_vector_alloc( 0 , false ); 
  model_config->history_source            = HISTORY_SOURCE_INVALID;
  model_config->runpath_map               = hash_alloc(); 
  model_config->gen_kw_export_file_name   = NULL;

  model_config_set_enspath( model_config        , DEFAULT_ENSPATH );
  model_config_set_rftpath( model_config        , DEFAULT_RFTPATH );
  model_config_set_dbase_type( model_config     , DEFAULT_DBASE_TYPE );
  model_config_set_max_internal_submit( model_config   , DEFAULT_MAX_INTERNAL_SUBMIT);
  model_config_add_runpath( model_config , DEFAULT_RUNPATH_KEY , DEFAULT_RUNPATH);
  model_config_select_runpath( model_config , DEFAULT_RUNPATH_KEY );
  model_config_set_gen_kw_export_file(model_config, DEFAULT_GEN_KW_EXPORT_FILE);
  
  return model_config;
}
Пример #2
0
static run_arg_type * run_arg_alloc(enkf_fs_type * init_fs ,
                                    enkf_fs_type * result_fs ,
                                    enkf_fs_type * update_target_fs ,
                                    int iens ,
                                    run_mode_type run_mode          ,
                                    int init_step_parameters        ,
                                    state_enum init_state_parameter ,
                                    state_enum init_state_dynamic   ,
                                    int step1                       ,
                                    int step2                       ,
                                    int iter                        ,
                                    const char * runpath) {

  run_arg_type * run_arg = util_malloc(sizeof * run_arg );
  UTIL_TYPE_ID_INIT(run_arg , RUN_ARG_TYPE_ID);

  run_arg->init_fs = init_fs;
  run_arg->result_fs = result_fs;
  run_arg->update_target_fs = update_target_fs;

  run_arg->iens = iens;
  run_arg->run_mode = run_mode;
  run_arg->init_step_parameters = init_step_parameters;
  run_arg->init_state_parameter = init_state_parameter;
  run_arg->init_state_dynamic = init_state_dynamic;
  run_arg->step1 = step1;
  run_arg->step2 = step2;
  run_arg->iter = iter;
  run_arg->run_path = util_alloc_abs_path( runpath );
  run_arg->num_internal_submit = 0;
  run_arg->queue_index = INVALID_QUEUE_INDEX;
  run_arg->run_status = JOB_NOT_STARTED;

  if (step1 == 0)
    run_arg->load_start = 1;
  else
    run_arg->load_start = step1;

  return run_arg;
}
Пример #3
0
/**
   The input vectors i,j,k should contain offset zero values.
*/
block_obs_type * block_obs_alloc(const char   * obs_key,
                                 block_obs_source_type source_type , 
                                 const stringlist_type * summary_keys , 
                                 const void * data_config , 
                                 const ecl_grid_type * grid ,
                                 int            size,
                                 const int    * i,
                                 const int    * j,
                                 const int    * k,
                                 const double * obs_value,
                                 const double * obs_std)
{
  block_obs_validate_ijk( grid , size , i,j,k);
  
  {
    block_obs_type * block_obs = util_malloc(sizeof * block_obs);
    char           * sum_kw    = NULL;

    UTIL_TYPE_ID_INIT( block_obs , BLOCK_OBS_TYPE_ID );
    block_obs->obs_key         = util_alloc_string_copy(obs_key);
    block_obs->data_config     = data_config;
    block_obs->source_type     = source_type; 
    block_obs->size            = 0;
    block_obs->point_list      = NULL;
    block_obs->grid            = grid;
    block_obs_resize( block_obs , size );
    
    {
      for (int l=0; l < size; l++) {
        int active_index = ecl_grid_get_active_index3( block_obs->grid , i[l],j[l],k[l]);
        char * sum_key   = NULL;
        if (source_type == SOURCE_SUMMARY) 
          sum_key = stringlist_iget( summary_keys , l );
        
        block_obs->point_list[l] = point_obs_alloc(source_type , i[l] , j[l] , k[l] , active_index , sum_key , obs_value[l] , obs_std[l]);
      }
    }
    return block_obs;
  }
}
Пример #4
0
smspec_node_type * smspec_node_alloc_new(int params_index, float default_value) {
  smspec_node_type * node = (smspec_node_type*)util_malloc( sizeof * node );

  UTIL_TYPE_ID_INIT( node , SMSPEC_TYPE_ID);
  node->params_index  = params_index;
  smspec_node_set_default( node , default_value );

  node->wgname        = NULL;
  node->ijk           = NULL;

  node->gen_key1      = NULL;
  node->gen_key2      = NULL;

  node->var_type      = ECL_SMSPEC_INVALID_VAR;
  node->unit          = NULL;
  node->keyword       = NULL;
  node->lgr_name      = NULL;
  node->lgr_ijk       = NULL;

  smspec_node_set_invalid_flags( node );
  return node;               // This is NOT usable
}
Пример #5
0
well_state_type * well_state_alloc(const char * well_name , int global_well_nr , bool open, well_type_enum type , int report_nr, time_t valid_from) {
  well_state_type * well_state = util_malloc( sizeof * well_state );
  UTIL_TYPE_ID_INIT( well_state , WELL_STATE_TYPE_ID );
  well_state->index_wellhead = vector_alloc_new();
  well_state->name_wellhead  = hash_alloc();

  well_state->name = util_alloc_string_copy( well_name );
  well_state->valid_from_time = valid_from;
  well_state->valid_from_report = report_nr;
  well_state->open = open;
  well_state->type = type;
  well_state->global_well_nr = global_well_nr;
  well_state->connections = hash_alloc();
  well_state->segments = well_segment_collection_alloc();
  well_state->branches = well_branch_collection_alloc();
  well_state->is_MSW_well = false;

  /* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */
  if ((type == UNDOCUMENTED_ZERO) && open)
    util_abort("%s: Invalid type value for open wells.\n",__func__ );
  return well_state;
}
Пример #6
0
smspec_node_type* smspec_node_alloc_copy( const smspec_node_type* node ) {

  if( !node ) return NULL;

  {
    smspec_node_type* copy = (smspec_node_type*)util_malloc( sizeof * copy );
    UTIL_TYPE_ID_INIT( copy, SMSPEC_TYPE_ID );
    copy->gen_key1 = util_alloc_string_copy( node->gen_key1 );
    copy->gen_key2 = util_alloc_string_copy( node->gen_key2 );
    copy->var_type = node->var_type;
    copy->wgname = util_alloc_string_copy( node->wgname );
    copy->keyword = util_alloc_string_copy( node->keyword );
    copy->unit = util_alloc_string_copy( node->unit );
    copy->num = node->num;

    copy->ijk = NULL;
    if( node->ijk ) {
        copy->ijk = (int*)util_calloc( 3 , sizeof * node->ijk );
        memcpy( copy->ijk, node->ijk, 3 * sizeof( * node->ijk ) );
    }

    copy->lgr_name = util_alloc_string_copy( node->lgr_name );
    copy->lgr_ijk = NULL;
    if( node->lgr_ijk ) {
        copy->lgr_ijk = (int*)util_calloc( 3 , sizeof * node->lgr_ijk );
        memcpy( copy->lgr_ijk, node->lgr_ijk, 3 * sizeof( * node->lgr_ijk ) );
    }

    copy->valid = node->valid;
    copy->rate_variable = node->rate_variable;
    copy->total_variable = node->total_variable;
    copy->historical = node->historical;
    copy->params_index = node->params_index;
    copy->default_value = node->default_value;
    return copy;
  }
}
Пример #7
0
group_rate_type * group_rate_alloc(const sched_history_type * sched_history , const time_t_vector_type * time_vector , const char * name , const char * phase , const char * type_string , const char * filename) {
  group_rate_type * group_rate = util_malloc( sizeof * group_rate , __func__);
  UTIL_TYPE_ID_INIT( group_rate , GROUP_RATE_ID );
  group_rate->name             = util_alloc_string_copy( name );
  group_rate->time_vector      = time_vector;
  group_rate->shift            = double_vector_alloc(0,0);
  group_rate->base_rate        = double_vector_alloc(0,0);
  group_rate->min_shift        = double_vector_alloc(0 , 0);
  group_rate->max_shift        = double_vector_alloc(0 , 0);
  group_rate->min_shift_string = stringlist_alloc_new();
  group_rate->max_shift_string = stringlist_alloc_new();
  group_rate->phase            = sched_phase_type_from_string( phase );  
  group_rate->sched_history    = sched_history;
  {
    if (strcmp( type_string , "INJECTOR") == 0)
      group_rate->producer = false;
    else if ( strcmp( type_string , "PRODUCER") == 0)
      group_rate->producer = true;
  }
  
  fscanf_2ts( time_vector , filename , group_rate->min_shift_string , group_rate->max_shift_string );
  group_rate->well_rates   = vector_alloc_new();
  return group_rate;
}
Пример #8
0
block_obs_type * block_obs_alloc(const char * obs_key,
                                 const void * data_config ,
                                 const ecl_grid_type * grid) {

    if (!(field_config_is_instance( data_config ) || container_config_is_instance( data_config )))
        return NULL;

    {
        block_obs_type * block_obs = util_malloc(sizeof * block_obs);
        UTIL_TYPE_ID_INIT( block_obs , BLOCK_OBS_TYPE_ID );

        block_obs->obs_key         = util_alloc_string_copy(obs_key);
        block_obs->data_config     = data_config;
        block_obs->point_list      = vector_alloc_new();
        block_obs->grid            = grid;

        if (field_config_is_instance( data_config ))
            block_obs->source_type = SOURCE_FIELD;
        else
            block_obs->source_type = SOURCE_SUMMARY;

        return block_obs;
    }
}
Пример #9
0
module_data_block_vector_type * module_data_block_vector_alloc( ) {
  module_data_block_vector_type * module_data_block_vector = util_malloc( sizeof * module_data_block_vector );
  UTIL_TYPE_ID_INIT( module_data_block_vector , MODULE_DATA_BLOCK_VECTOR_TYPE_ID );
  module_data_block_vector->data_block_vector = vector_alloc_new();
  return module_data_block_vector;
}
Пример #10
0
/**
   The matrix objecty is NOT ready for use after this function.
*/
static matrix_type * matrix_alloc_empty( ) {
  matrix_type * matrix  = util_malloc( sizeof * matrix );
  UTIL_TYPE_ID_INIT( matrix , MATRIX_TYPE_ID );
  matrix->name = NULL;
  return matrix;
}
Пример #11
0
surface_config_type  * surface_config_alloc_empty( ) {
  surface_config_type * config = util_malloc( sizeof * config );
  UTIL_TYPE_ID_INIT( config , SURFACE_CONFIG_TYPE_ID );
  config->base_surface  = NULL;
  return config;
}
Пример #12
0
static ecl_grav_phase_type * ecl_grav_phase_alloc( ecl_grav_type * ecl_grav , 
                                                   ecl_grav_survey_type * survey , 
                                                   ecl_phase_enum phase , 
                                                   const ecl_file_type * restart_file, 
                                                   grav_calc_type calc_type) {
  
  const ecl_file_type * init_file        = ecl_grav->init_file;
  const ecl_grid_cache_type * grid_cache = ecl_grav->grid_cache;
  const char * sat_kw_name               = ecl_util_get_phase_name( phase );
  {
    ecl_grav_phase_type * grav_phase = util_malloc( sizeof * grav_phase );
    const int size                   = ecl_grid_cache_get_size( grid_cache );
    
    UTIL_TYPE_ID_INIT( grav_phase , ECL_GRAV_PHASE_TYPE_ID );
    grav_phase->grid_cache   = grid_cache;
    grav_phase->aquifer_cell = ecl_grav->aquifer_cell;
    grav_phase->fluid_mass   = util_calloc( size , sizeof * grav_phase->fluid_mass );
    grav_phase->phase        = phase;
    grav_phase->work         = NULL;

    if (calc_type == GRAV_CALC_FIP) {
      ecl_kw_type * pvtnum_kw = ecl_file_iget_named_kw( init_file , PVTNUM_KW , 0 );
      double_vector_type * std_density = hash_get( ecl_grav->std_density , ecl_util_get_phase_name( phase ));
      ecl_kw_type * fip_kw;
        
      if ( phase == ECL_OIL_PHASE)
        fip_kw = ecl_file_iget_named_kw( restart_file , FIPOIL_KW , 0 );
      else if (phase == ECL_GAS_PHASE)
        fip_kw = ecl_file_iget_named_kw( restart_file , FIPGAS_KW , 0 );
      else
        fip_kw = ecl_file_iget_named_kw( restart_file , FIPWAT_KW , 0 );
      
      {
        int iactive;
        for (iactive=0; iactive < size; iactive++) {
          double fip    = ecl_kw_iget_as_double( fip_kw , iactive );
          int    pvtnum = ecl_kw_iget_int( pvtnum_kw , iactive );
          grav_phase->fluid_mass[ iactive ] = fip * double_vector_safe_iget( std_density , pvtnum );
        }
      }
    } else {
      ecl_version_enum      ecl_version = ecl_file_get_ecl_version( init_file );
      const char          * den_kw_name = get_den_kw( phase , ecl_version );
      const ecl_kw_type   * den_kw      = ecl_file_iget_named_kw( restart_file , den_kw_name , 0 );

      if (calc_type == GRAV_CALC_RFIP) {
        ecl_kw_type * rfip_kw;
        if ( phase == ECL_OIL_PHASE)
          rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPOIL_KW , 0 );
        else if (phase == ECL_GAS_PHASE)
          rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPGAS_KW , 0 );
        else
          rfip_kw = ecl_file_iget_named_kw( restart_file , RFIPWAT_KW , 0 );
        
        {
          int iactive;
          for (iactive=0; iactive < size; iactive++) {
            double rho   = ecl_kw_iget_as_double( den_kw  , iactive );
            double rfip  = ecl_kw_iget_as_double( rfip_kw , iactive );
            grav_phase->fluid_mass[ iactive ] = rho * rfip;
          }
        }
      } else {
        /* (calc_type == GRAV_CALC_RPORV) || (calc_type == GRAV_CALC_PORMOD) */
        ecl_kw_type * sat_kw;
        bool private_sat_kw = false;
        if (ecl_file_has_kw( restart_file , sat_kw_name )) 
          sat_kw = ecl_file_iget_named_kw( restart_file , sat_kw_name , 0 );
        else {
          /* We are targeting the residual phase, e.g. the OIL phase in a three phase system. */
          const ecl_kw_type * swat_kw = ecl_file_iget_named_kw( restart_file , "SWAT" , 0 );
          sat_kw = ecl_kw_alloc_copy( swat_kw );
          ecl_kw_scalar_set_float( sat_kw , 1.0 );
          ecl_kw_inplace_sub( sat_kw , swat_kw );  /* sat = 1 - SWAT */
          
          if (ecl_file_has_kw( restart_file , "SGAS" )) {
            const ecl_kw_type * sgas_kw = ecl_file_iget_named_kw( restart_file , "SGAS" , 0 );
            ecl_kw_inplace_sub( sat_kw , sgas_kw );  /* sat -= SGAS */
          }
          private_sat_kw = true;
        }
        
        {
          int iactive;
          for (iactive=0; iactive < size; iactive++) {
            double rho  = ecl_kw_iget_as_double( den_kw , iactive );
            double sat  = ecl_kw_iget_as_double( sat_kw , iactive );
            grav_phase->fluid_mass[ iactive ] = rho * sat * survey->porv[ iactive ];
          }
        }
        
        if (private_sat_kw)
          ecl_kw_free( sat_kw );
      }
    }
    
    return grav_phase;
  }
}
Пример #13
0
job_queue_node_type * job_queue_node_alloc( const char * job_name ,
                                            const char * run_path ,
                                            const char * run_cmd ,
                                            int argc ,
                                            const char ** argv,
                                            int num_cpu,
                                            const char * ok_file,
                                            const char * exit_file,
                                            job_callback_ftype * done_callback,
                                            job_callback_ftype * retry_callback,
                                            job_callback_ftype * exit_callback,
                                            void * callback_arg) {

  if (util_is_directory( run_path )) {
    job_queue_node_type * node = util_malloc(sizeof * node );

    UTIL_TYPE_ID_INIT( node , JOB_QUEUE_NODE_TYPE_ID );
    {
      /* The data initialized in this block should *NEVER* change. */
      node->job_name       = util_alloc_string_copy( job_name );

      if (util_is_abs_path(run_path))
        node->run_path = util_alloc_string_copy( run_path );
      else
        node->run_path = util_alloc_realpath( run_path );

      node->run_cmd        = util_alloc_string_copy( run_cmd );
      node->argc           = argc;
      node->argv           = util_alloc_stringlist_copy( argv , argc );
      node->num_cpu        = num_cpu;

      if (ok_file)
        node->ok_file = util_alloc_filename(node->run_path , ok_file , NULL);
      else
        node->ok_file = NULL;

      if (exit_file)
        node->exit_file = util_alloc_filename(node->run_path , exit_file , NULL);
      else
        node->exit_file = NULL;

      node->exit_callback  = exit_callback;
      node->retry_callback = retry_callback;
      node->done_callback  = done_callback;
      node->callback_arg   = callback_arg;
    }
    {
      node->error_reason   = NULL;
      node->stderr_capture = NULL;
      node->stderr_file    = NULL;
      node->failed_job     = NULL;
    }
    {
      node->job_status     = JOB_QUEUE_NOT_ACTIVE;
      node->queue_index    = INVALID_QUEUE_INDEX;
      node->submit_attempt = 0;
      node->job_data       = NULL;                                    /* The allocation is run in single thread mode - we assume. */
      node->sim_start      = 0;
      node->sim_end        = 0;
      node->submit_time    = time( NULL );
    }

    pthread_mutex_init( &node->data_mutex , NULL );
    return node;
  } else
    return NULL;
}
Пример #14
0
well_rate_type * well_rate_alloc(const sched_history_type * sched_history , const time_t_vector_type * time_vector , const char * name , double corr_length , const char * filename, sched_phase_enum phase, bool producer) {
  well_rate_type * well_rate = util_malloc( sizeof * well_rate , __func__);
  UTIL_TYPE_ID_INIT( well_rate , WELL_RATE_ID );
  well_rate->name         = util_alloc_string_copy( name );
  well_rate->time_vector  = time_vector;
  well_rate->corr_length  = corr_length;
  well_rate->shift        = double_vector_alloc(0,0);
  well_rate->mean_shift   = double_vector_alloc(0 , 0);
  well_rate->std_shift    = double_vector_alloc(0 , 0);
  well_rate->mean_shift_string   = stringlist_alloc_new();
  well_rate->std_shift_string    = stringlist_alloc_new();
  well_rate->base_value   = double_vector_alloc(0 , 0);
  well_rate->rate         = double_vector_alloc(0 , 0);
  well_rate->phase        = phase;
  well_rate->sched_history= sched_history; 
  well_rate->percent_std  = bool_vector_alloc( 0 , false );
  well_rate->producer     = producer;
  fscanf_2ts( time_vector , filename , well_rate->mean_shift_string , well_rate->std_shift_string);
  
  {
    char * key;
    if (well_rate->producer) {
      switch(well_rate->phase) {
      case (WATER):
        key = util_alloc_sprintf("WWPRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( GAS ):
        key = util_alloc_sprintf("WGPRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( OIL ):
        key = util_alloc_sprintf("WOPRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      default:
        key = NULL;
        util_abort("%s: unknown phase identitifier: %d \n",__func__ , well_rate->phase);
      }
    } else {
      switch(well_rate->phase) {
      case (WATER):
        key = util_alloc_sprintf("WWIRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( GAS ):
        key = util_alloc_sprintf("WGIRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      case( OIL ):
        key = util_alloc_sprintf("WOIRH%s%s" , sched_history_get_join_string( sched_history ) , well_rate->name );
        break;
      default:
        util_abort("%s: unknown phase identitifier: %d \n",__func__ , well_rate->phase);
        key = NULL;
      }
    }
    
    if (sched_history_has_key( sched_history , key)) {
      sched_history_init_vector( sched_history , key , well_rate->base_value );
      well_rate_eval_stat( well_rate );
    } else 
      fprintf(stderr,"** Warning - schedule history does not have key:%s - suspicious?\n", key );
    
    free( key );
  }
  return well_rate;
}
Пример #15
0
ecl_static_kw_type * ecl_static_kw_alloc( ) {  
  ecl_static_kw_type * static_kw = util_malloc(sizeof *static_kw );
  UTIL_TYPE_ID_INIT( static_kw , STATIC );
  static_kw->ecl_kw        = NULL;
  return static_kw;
}
Пример #16
0
job_queue_manager_type * job_queue_manager_alloc( job_queue_type * job_queue ) {
  job_queue_manager_type * manager = util_malloc( sizeof * manager );
  UTIL_TYPE_ID_INIT( manager , JOB_QUEUE_MANAGER_TYPE_ID );
  manager->job_queue = job_queue;
  return manager;
}
Пример #17
0
summary_key_matcher_type * summary_key_matcher_alloc() {
  summary_key_matcher_type * matcher = util_malloc(sizeof * matcher);
  UTIL_TYPE_ID_INIT( matcher , SUMMARY_KEY_MATCHER_TYPE_ID);
  matcher->key_set = hash_alloc();
  return matcher;
}
Пример #18
0
sched_kw_compdat_type * sched_kw_compdat_alloc_empty( ) {
  sched_kw_compdat_type * kw = util_malloc(sizeof *kw );
  kw->completions = vector_alloc_new();
  UTIL_TYPE_ID_INIT( kw , SCHED_KW_COMPDAT_ID );
  return kw;
}