Exemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::readGridDimensions(const QString& gridFileName, std::vector< std::vector<int> >& gridDimensions)
{
    ecl_grid_type * grid         = ecl_grid_alloc(RiaStringEncodingTools::toNativeEncoded(gridFileName).data());                               // bootstrap ecl_grid instance
    stringlist_type * lgr_names  = ecl_grid_alloc_lgr_name_list( grid );                                   // get a list of all the lgr names.

    //printf("grid:%s has %d a total of %d lgr's \n", grid_filename , stringlist_get_size( lgr_names ));
    for (int lgr_nr = 0; lgr_nr < stringlist_get_size( lgr_names); lgr_nr++)
    {
        ecl_grid_type * lgr_grid  = ecl_grid_get_lgr( grid , stringlist_iget( lgr_names , lgr_nr ));    // get the ecl_grid instance of the lgr - by name.

        int nx,ny,nz,active_size;
        ecl_grid_get_dims( lgr_grid , &nx , &ny , &nz , &active_size);                             // get some size info from this lgr.

        std::vector<int> values;
        values.push_back(nx);
        values.push_back(ny);
        values.push_back(nz);
        values.push_back(active_size);

        gridDimensions.push_back(values);
    }

    ecl_grid_free( grid );
    stringlist_free( lgr_names );

}
Exemplo n.º 2
0
void field_config_set_grid(field_config_type * config, ecl_grid_type * grid , bool private_grid) {
    if ((config->private_grid) && (config->grid != NULL))
        ecl_grid_free( config->grid );

    config->grid         = grid;
    config->private_grid = private_grid;

    ecl_grid_get_dims(grid , &config->nx , &config->ny , &config->nz , NULL);
    config->data_size = field_config_get_data_size_from_grid(config);
}
Exemplo n.º 3
0
void rms_export_roff_from_keyword(const char *filename, ecl_grid_type *ecl_grid, 
    ecl_kw_type **ecl_kw, int size) {
  
  rms_file_type *rms_file;
  rms_tagkey_type *data_key;
  int nx, ny, nz, active_size;
  int i, j, k;
  int global_size;
  int n;
    
  ecl_grid_get_dims(ecl_grid, &nx, &ny, &nz, &active_size);
  global_size = ecl_grid_get_global_size(ecl_grid);
  
  rms_file = rms_file_alloc(filename, false);
  rms_file_fopen_w(rms_file);

  rms_file_init_fwrite(rms_file , "parameter");
  rms_tag_fwrite_dimensions(nx , ny , nz , rms_file_get_FILE(rms_file));

  for (n = 0; n < size; n++) {
    float *src_data;
    float *target_data;

    src_data = (float *) ecl_kw_get_void_ptr(ecl_kw[n]);
    target_data = util_calloc(global_size , sizeof * target_data );

    for (k=0; k < nz; k++) {
      for (j=0; j < ny; j++) {
        for (i=0; i < nx; i++) {
          int index1D;
          int index3D;
          double fill = RMS_INACTIVE_FLOAT;
          /* TODO:
           * This currently only supports FLOAT / REAL type.
           */ 
          
          index1D = ecl_grid_get_active_index3(ecl_grid, i, j, k);
          index3D = rms_util_global_index_from_eclipse_ijk(nx, ny, nz, i, j, k);

          if (index1D >= 0)
            target_data[index3D] = src_data[index1D];
          else
            memcpy(&target_data[index3D] , &fill, sizeof(float));
        }
      }
    }

    data_key = rms_tagkey_alloc_complete("data", global_size, 
        rms_util_convert_ecl_type(ecl_kw_get_data_type(ecl_kw[n])) , target_data, true);
    rms_tag_fwrite_parameter(ecl_kw_get_header8(ecl_kw[n]), data_key, 
        rms_file_get_FILE(rms_file));
    rms_tagkey_free(data_key);
    
    util_safe_free(target_data);
  }

  rms_file_complete_fwrite(rms_file);
  rms_file_fclose(rms_file);
  rms_file_free(rms_file);
  
}
Exemplo n.º 4
0
static int gravity_check_input( const ecl_grid_type * ecl_grid , 
                                const ecl_file_type * init_file , 
                                const ecl_file_type * restart_file1, 
                                const ecl_file_type * restart_file2,
                                int   * __model_phases,
                                int   * __file_phases) {
  {
    int model_phases = 0;
    int file_phases  = 0;

    /* Check which phases are present in the model */
    if (ecl_file_has_kw(restart_file1 , "OIL_DEN")) {
      model_phases += OIL;  
      simulator = ECLIPSE100 ;
    } else if (ecl_file_has_kw(restart_file1 , "DENO")) {
      model_phases += OIL;  
      simulator = ECLIPSE300 ;
    } ;
      
    if (ecl_file_has_kw(restart_file1 , "WAT_DEN")) {
      model_phases += WATER;                         
      simulator = ECLIPSE100 ;
    } else if (ecl_file_has_kw(restart_file1 , "DENW")) {
      model_phases += WATER;                         
      simulator = ECLIPSE300 ;
    } ;
    
    if (ecl_file_has_kw(restart_file1 , "GAS_DEN")) {
      model_phases += GAS;
      simulator = ECLIPSE100 ;
    } else if (ecl_file_has_kw(restart_file1 , "DENG")) {
      model_phases += GAS;
      simulator = ECLIPSE300 ;
    } ;
    
    
    /* Check which phases are present in the restart files. We assume the restart file NEVER has SOIL information */
    if (ecl_file_has_kw(restart_file1 , "SWAT"))
      file_phases += WATER;
    if (ecl_file_has_kw(restart_file1 , "SGAS"))
      file_phases += GAS;
    
    
    /* Consiency check */
    {
      /**
         The following assumptions are made:
         
         1. All restart files should have water, i.e. the SWAT keyword. 
         2. All phases present in the restart file should also be present as densities, 
            in addition the model must contain one additional phase. 
         3. The restart files can never contain oil saturation.
         
      */
      if ( !has_phase( file_phases , WATER ) )
        util_exit("Could not locate SWAT keyword in restart files\n");
      
      if ( has_phase( file_phases , OIL ))
        util_exit("Can not handle restart files with SOIL keyword\n"); 
      
      if (! has_phase( model_phases , WATER ) )
        util_exit("Could not locate WAT_DEN keyword in restart files\n");      
      
      if ( has_phase( file_phases , GAS )) {
        /** Restart file has both water and gas - means we need all three densities. */
        if (! (has_phase( model_phases , GAS) && has_phase( model_phases , OIL)))
          util_exit("Could not find GAS_DEN and OIL_DEN keywords in restart files\n");
      } else {
        /* This is (water + oil) or (water + gas) system. We enforce one of the densities.*/
        if ( !has_phase( model_phases , GAS + OIL))
          util_exit("Could not find either GAS_DEN or OIL_DEN kewyords in restart files\n");
      }
    }
    *__model_phases = model_phases;
    *__file_phases  = file_phases;
  }
  
  /* Check that the restart files have RPORV information. This is ensured by giving the argument RPORV to the RPTRST keyword. */
  if ( !(ecl_file_has_kw( restart_file1 , "RPORV") && ecl_file_has_kw( restart_file2 , "RPORV")) )
    util_exit("Sorry: the restartfiles do  not contain RPORV\n");       


  /**
     Check that the rporv values are in the right ballpark.  For
     ECLIPSE version 2008.2 they are way f*****g off. Check PORV
     versus RPORV for ten 'random' locations in the grid.
  */
  {
    const ecl_kw_type * rporv1_kw     = ecl_file_iget_named_kw( restart_file1 , "RPORV" , 0);      
    const ecl_kw_type * rporv2_kw     = ecl_file_iget_named_kw( restart_file2 , "RPORV" , 0);      
    const ecl_kw_type * init_porv_kw  = ecl_file_iget_named_kw( init_file     , "PORV" , 0);

    int    active_index;
    int    active_delta;
    int    active_size;
    
    ecl_grid_get_dims( ecl_grid , NULL , NULL , NULL , &active_size );
    active_delta = active_size / 12;
    for (active_index = active_delta; active_index < active_size; active_index += active_delta) {
      int    global_index = ecl_grid_get_global_index1A( ecl_grid , active_index );
      double init_porv    = ecl_kw_iget_as_double( init_porv_kw , global_index );   /* NB - this uses global indexing. */
      double rporv1       = ecl_kw_iget_as_double( rporv1_kw ,  active_index );
      double rporv2       = ecl_kw_iget_as_double( rporv2_kw ,  active_index );
      double rporv12      = 0.5 * ( rporv1 + rporv2 );
      double fraction     = util_double_min( init_porv , rporv12 ) / util_double_max( init_porv , rporv12 );

      if (fraction  < 0.50) {
        fprintf(stderr,"-----------------------------------------------------------------\n");
        fprintf(stderr,"INIT PORV: %g \n",init_porv);
        fprintf(stderr,"RPORV1   : %g \n",rporv1);
        fprintf(stderr,"RPORV2   : %g \n",rporv2);
        fprintf(stderr,"Hmmm - the RPORV values extracted from the restart file seem to be \n");
        fprintf(stderr,"veeery different from the initial rporv value. This might indicated\n");
        fprintf(stderr,"an ECLIPSE bug. Version 2007.2 is known to be ok in this respect, \n");
        fprintf(stderr,"whereas version 2008.2 is known to have a bug. \n");
        fprintf(stderr,"-----------------------------------------------------------------\n");
        exit(1);
      }
    }
  }

  return 0;
}