Beispiel #1
0
obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_type * conf_instance , 
                                                          const ecl_grid_type * grid , 
                                                          const ecl_sum_type * refcase , 
                                                          const history_type * history, 
                                                          ensemble_config_type * ensemble_config) {

  if(!conf_instance_is_of_class(conf_instance, "BLOCK_OBSERVATION"))
    util_abort("%s: internal error. expected \"BLOCK_OBSERVATION\" instance, got \"%s\".\n",
               __func__, conf_instance_get_class_name_ref(conf_instance) );

  block_obs_source_type source_type = SOURCE_SUMMARY;
  const char * obs_label            = conf_instance_get_name_ref(conf_instance);
  const char * source_string        = conf_instance_get_item_value_ref(conf_instance , "SOURCE");
  const char * field_name           = conf_instance_get_item_value_ref(conf_instance , "FIELD");
  const char * sum_kw = NULL;
  bool    OK     = true;
  
  if (strcmp(source_string , "FIELD") == 0) {
    source_type = SOURCE_FIELD;
    if (!ensemble_config_has_key( ensemble_config , field_name)) {
      OK = false;
      fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", field_name , obs_label);
    }
  } else if (strcmp( source_string , "SUMMARY") == 0) {
    source_type = SOURCE_SUMMARY;
    sum_kw = __summary_kw( field_name );
  } else 
    util_abort("%s: internal error \n",__func__);
  
  if (OK) {
    obs_vector_type * obs_vector = NULL;
    int          size = history_get_last_restart( history );
    int          obs_restart_nr ;
    
    stringlist_type * summary_keys    = stringlist_alloc_new();
    stringlist_type * obs_pt_keys = conf_instance_alloc_list_of_sub_instances_of_class_by_name(conf_instance, "OBS");
    int               num_obs_pts = stringlist_get_size(obs_pt_keys);
    
    double * obs_value = util_calloc(num_obs_pts , sizeof * obs_value);
    double * obs_std   = util_calloc(num_obs_pts , sizeof * obs_std  );
    int    * obs_i     = util_calloc(num_obs_pts , sizeof * obs_i    );
    int    * obs_j     = util_calloc(num_obs_pts , sizeof * obs_j    );
    int    * obs_k     = util_calloc(num_obs_pts , sizeof * obs_k    );

    obs_restart_nr = __conf_instance_get_restart_nr(conf_instance , obs_label , history  , size);  
    
    /** Build the observation. */
    for(int obs_pt_nr = 0; obs_pt_nr < num_obs_pts; obs_pt_nr++) {
      const char * obs_key    = stringlist_iget(obs_pt_keys, obs_pt_nr);
      const conf_instance_type * obs_instance = conf_instance_get_sub_instance_ref(conf_instance, obs_key);
      const char * error_mode = conf_instance_get_item_value_ref(obs_instance, "ERROR_MODE");
      double error     = conf_instance_get_item_value_double(obs_instance, "ERROR");
      double value     = conf_instance_get_item_value_double(obs_instance, "VALUE");
      double min_error = conf_instance_get_item_value_double(obs_instance, "ERROR_MIN");
      
      if (strcmp( error_mode , "REL") == 0)
        error *= value;
      else if (strcmp( error_mode , "RELMIN") == 0)
        error = util_double_max( error * value , min_error );

      obs_value[obs_pt_nr] = value;
      obs_std  [obs_pt_nr] = error;
      
      /**
         The input values i,j,k come from the user, and are offset 1. They
         are immediately shifted with -1 to become C-based offset zero.
      */
      obs_i[obs_pt_nr] = conf_instance_get_item_value_int(   obs_instance, "I") - 1;
      obs_j[obs_pt_nr] = conf_instance_get_item_value_int(   obs_instance, "J") - 1;
      obs_k[obs_pt_nr] = conf_instance_get_item_value_int(   obs_instance, "K") - 1;

      if (source_type == SOURCE_SUMMARY) {
        char * summary_key = smspec_alloc_block_ijk_key( SUMMARY_KEY_JOIN_STRING , sum_kw , 
                                                         obs_i[obs_pt_nr] + 1 , 
                                                         obs_j[obs_pt_nr] + 1 , 
                                                         obs_k[obs_pt_nr] + 1 );
        
        stringlist_append_owned_ref( summary_keys , summary_key );
      }
    }

    
    if (source_type == SOURCE_FIELD) {
      const enkf_config_node_type * config_node  = ensemble_config_get_node( ensemble_config , field_name);
      const field_config_type     * field_config = enkf_config_node_get_ref( config_node ); 
      block_obs_type * block_obs  = block_obs_alloc_complete(obs_label, source_type , NULL , field_config , grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std);
      
      if (block_obs != NULL) {
        obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , ensemble_config_get_node(ensemble_config , field_name), size );
        obs_vector_install_node( obs_vector , obs_restart_nr , block_obs);
      }
    } else if (source_type == SOURCE_SUMMARY) {
      OK = true;
      if (refcase != NULL) {
        for (int i=0; i < stringlist_get_size( summary_keys ); i++) {
          const char * sum_key = stringlist_iget( summary_keys , i );
          if (!ecl_sum_has_key(refcase , sum_key)) {
            /*
              If the 
            */
            fprintf(stderr,"** Warning missing summary %s for cell: (%d,%d,%d) in refcase - make sure that \"BPR  %d  %d  %d\" is included in ECLIPSE summary specification \n" , 
                    sum_key , obs_i[i]+1 , obs_j[i]+1 , obs_k[i]+1 , obs_i[i]+1 , obs_j[i]+1 , obs_k[i]+1  );
            //OK = false;
          }
        }
      }
      if (OK) {
        // We can create the container node and add the summary nodes.
        enkf_config_node_type * container_config = ensemble_config_add_container( ensemble_config , NULL );

        for (int i=0; i < stringlist_get_size( summary_keys ); i++) {
          const char * sum_key = stringlist_iget( summary_keys , i );
          enkf_config_node_type * child_node = ensemble_config_add_summary( ensemble_config , sum_key , LOAD_FAIL_WARN );
          enkf_config_node_update_container( container_config , child_node );
        }
        
        {
          block_obs_type * block_obs  = block_obs_alloc_complete(obs_label, source_type , summary_keys , enkf_config_node_get_ref(container_config) , 
                                                                 grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std);
          if (block_obs != NULL) {
            obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , container_config, size );
            obs_vector_install_node( obs_vector , obs_restart_nr , block_obs);
          }
        }
      }
    } else
      util_abort("%s: invalid source value \n",__func__);
    
    free(obs_value);
    free(obs_std);
    free(obs_i);
    free(obs_j);
    free(obs_k);
    stringlist_free(obs_pt_keys);
    stringlist_free(summary_keys);
    
    return obs_vector;
  } else {
    fprintf(stderr,"** Warning the ensemble key:%s does not exist - observation:%s not added \n", field_name , obs_label);
    return NULL;
  }
}
Beispiel #2
0
static void smspec_node_set_gen_keys( smspec_node_type * smspec_node , const char * key_join_string) {
  switch( smspec_node->var_type) {
  case(ECL_SMSPEC_COMPLETION_VAR):
    // KEYWORD:WGNAME:NUM
    smspec_node->gen_key1 = smspec_alloc_completion_ijk_key( key_join_string , smspec_node->keyword , smspec_node->wgname , smspec_node->ijk[0], smspec_node->ijk[1], smspec_node->ijk[2]);
    smspec_node->gen_key2 = smspec_alloc_completion_num_key( key_join_string , smspec_node->keyword , smspec_node->wgname , smspec_node->num);
    break;
  case(ECL_SMSPEC_FIELD_VAR):
    // KEYWORD
    smspec_node->gen_key1 = util_alloc_string_copy( smspec_node->keyword );
    break;
  case(ECL_SMSPEC_GROUP_VAR):
    // KEYWORD:WGNAME
    smspec_node->gen_key1 = smspec_alloc_group_key( key_join_string , smspec_node->keyword , smspec_node->wgname);
    break;
  case(ECL_SMSPEC_WELL_VAR):
    // KEYWORD:WGNAME
    smspec_node->gen_key1 = smspec_alloc_well_key( key_join_string , smspec_node->keyword , smspec_node->wgname);
    break;
  case(ECL_SMSPEC_REGION_VAR):
    // KEYWORD:NUM
    smspec_node->gen_key1 = smspec_alloc_region_key( key_join_string , smspec_node->keyword , smspec_node->num);
    break;
  case (ECL_SMSPEC_SEGMENT_VAR):
    // KEYWORD:WGNAME:NUM
    smspec_node->gen_key1 = smspec_alloc_segment_key( key_join_string , smspec_node->keyword , smspec_node->wgname , smspec_node->num);
    break;
  case(ECL_SMSPEC_REGION_2_REGION_VAR):
    // KEYWORDS:RXF:NUM and RXF:R1-R2
    {
      int r1,r2;
      smspec_node_decode_R1R2( smspec_node , &r1 , &r2);
      smspec_node->gen_key1 = smspec_alloc_region_2_region_r1r2_key( key_join_string , smspec_node->keyword , r1, r2);
    }
    smspec_node->gen_key2 = smspec_alloc_region_2_region_num_key( key_join_string , smspec_node->keyword , smspec_node->num);
    break;
  case(ECL_SMSPEC_MISC_VAR):
    // KEYWORD
    /* Misc variable - i.e. date or CPU time ... */
    smspec_node->gen_key1 = util_alloc_string_copy( smspec_node->keyword );
    break;
  case(ECL_SMSPEC_BLOCK_VAR):
    // KEYWORD:NUM
    smspec_node->gen_key1 = smspec_alloc_block_ijk_key( key_join_string , smspec_node->keyword , smspec_node->ijk[0], smspec_node->ijk[1], smspec_node->ijk[2]);
    smspec_node->gen_key2 = smspec_alloc_block_num_key( key_join_string , smspec_node->keyword , smspec_node->num);
    break;
  case(ECL_SMSPEC_LOCAL_WELL_VAR):
    /** KEYWORD:LGR:WGNAME */
    smspec_node->gen_key1 = smspec_alloc_local_well_key( key_join_string , smspec_node->keyword , smspec_node->lgr_name , smspec_node->wgname);
    break;
  case(ECL_SMSPEC_LOCAL_BLOCK_VAR):
    /* KEYWORD:LGR:i,j,k */
    smspec_node->gen_key1 = smspec_alloc_local_block_key( key_join_string ,
                                                         smspec_node->keyword ,
                                                         smspec_node->lgr_name ,
                                                         smspec_node->lgr_ijk[0] ,
                                                         smspec_node->lgr_ijk[1] ,
                                                         smspec_node->lgr_ijk[2] );
    break;
  case(ECL_SMSPEC_LOCAL_COMPLETION_VAR):
    /* KEYWORD:LGR:WELL:i,j,k */
    smspec_node->gen_key1 = smspec_alloc_local_completion_key( key_join_string ,
                                                              smspec_node->keyword ,
                                                              smspec_node->lgr_name ,
                                                              smspec_node->wgname ,
                                                              smspec_node->lgr_ijk[0],
                                                              smspec_node->lgr_ijk[1],
                                                              smspec_node->lgr_ijk[2]);

    break;
  case(ECL_SMSPEC_AQUIFER_VAR):
    smspec_node->gen_key1 = smspec_alloc_aquifer_key( key_join_string , smspec_node->keyword , smspec_node->num);
    break;
  default:
    util_abort("%s: internal error - should not be here? \n" , __func__);
  }
  smspec_node->valid = true;
}