예제 #1
0
    void restoreTemperatureData(const ecl_file_type* file,
                              EclipseStateConstPtr eclipse_state,
                              int numcells,
                              SimulatorState& simulator_state) {
        const char* temperature = "TEMP";

        if (ecl_file_has_kw(file , temperature)) {
            ecl_kw_type* temperature_kw = ecl_file_iget_named_kw(file, temperature, 0);

            if (ecl_kw_get_size(temperature_kw) != numcells) {
                throw std::runtime_error("Read of restart file: Could not restore temperature data, length of data from file not equal number of cells");
            }

            float* temperature_data = ecl_kw_get_float_ptr(temperature_kw);

            // factor and offset from the temperature values given in the deck to Kelvin
            double scaling = eclipse_state->getDeckUnitSystem().parse("Temperature")->getSIScaling();
            double offset  = eclipse_state->getDeckUnitSystem().parse("Temperature")->getSIOffset();

            for (size_t index = 0; index < simulator_state.temperature().size(); ++index) {
                simulator_state.temperature()[index] = unit::convert::from((double)temperature_data[index] - offset, scaling);
            }
          } else {
              throw std::runtime_error("Read of restart file: File does not contain TEMP data\n");
          }
    }
예제 #2
0
static int well_state_get_lgr_well_nr( const well_state_type * well_state , const ecl_file_type * ecl_file) {
  int well_nr = -1;

  if (ecl_file_has_kw( ecl_file , ZWEL_KW)) {
    ecl_rsthead_type  * header  = ecl_rsthead_alloc( ecl_file );
    const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW  , 0 );
    int num_wells               = header->nwells;
    well_nr = 0;
    while (true) {
      bool found = false;
      {
        char * lgr_well_name = util_alloc_strip_copy( ecl_kw_iget_ptr( zwel_kw , well_nr * header->nzwelz) );

        if ( strcmp( well_state->name , lgr_well_name) == 0)
          found = true;
        else
          well_nr++;

        free( lgr_well_name );
      }

      if (found)
        break;
      else if (well_nr == num_wells) {
        // The well is not in this LGR at all.
        well_nr = -1;
        break;
      }

    }
    ecl_rsthead_free( header );
  }
  return well_nr;
}
예제 #3
0
    void restoreOPM_XWELKeyword(const std::string& restart_filename, int reportstep, bool unified, WellState& wellstate)
    {
        const char * keyword = "OPM_XWEL";
        const char* filename = restart_filename.c_str();
        ecl_file_type* file_type = ecl_file_open(filename, 0);

        if (file_type != NULL) {

            bool block_selected = unified ? ecl_file_select_rstblock_report_step(file_type , reportstep) : true;

            if (block_selected) {
                ecl_kw_type* xwel = ecl_file_iget_named_kw(file_type , keyword, 0);
                const double* xwel_data = ecl_kw_get_double_ptr(xwel);
                std::copy_n(xwel_data + wellstate.getRestartTemperatureOffset(), wellstate.temperature().size(), wellstate.temperature().begin());
                std::copy_n(xwel_data + wellstate.getRestartBhpOffset(), wellstate.bhp().size(), wellstate.bhp().begin());
                std::copy_n(xwel_data + wellstate.getRestartPerfPressOffset(), wellstate.perfPress().size(), wellstate.perfPress().begin());
                std::copy_n(xwel_data + wellstate.getRestartPerfRatesOffset(), wellstate.perfRates().size(), wellstate.perfRates().begin());
                std::copy_n(xwel_data + wellstate.getRestartWellRatesOffset(), wellstate.wellRates().size(), wellstate.wellRates().begin());
            } else {
                std::string error_str = "Restart file " +  restart_filename + " does not contain data for report step " + std::to_string(reportstep) + "!\n";
                throw std::runtime_error(error_str);
            }
            ecl_file_close(file_type);
        } else {
            std::string error_str = "Restart file " + restart_filename + " not found!\n";
            throw std::runtime_error(error_str);
        }
    }
예제 #4
0
static void ecl_grav_survey_assert_RPORV( const ecl_grav_survey_type * survey , const ecl_file_type * init_file ) {
  const ecl_grid_cache_type * grid_cache = survey->grid_cache;
  int   active_size                      = ecl_grid_cache_get_size( grid_cache );
  const ecl_kw_type * init_porv_kw       = ecl_file_iget_named_kw( init_file , PORV_KW , 0);
  int check_points                       = 100;     
  int check_nr                           = 0;
  
  while (check_nr < check_points) {
    int active_index    = rand() % active_size;
    int    global_index = ecl_grid_cache_iget_global_index( grid_cache , active_index );

    double init_porv    = ecl_kw_iget_as_double( init_porv_kw , global_index );    /* NB - this uses global indexing. */
    if (init_porv > 0) {
      double rporv      = survey->porv[ active_index ];                           
      double log_pormod = log10( rporv / init_porv );   
      
      if (fabs( log_pormod ) > 1) {  
        /* Detected as error if the effective pore volume multiplier
           is greater than 10 or less than 0.10. */
        fprintf(stderr,"-----------------------------------------------------------------\n");
        fprintf(stderr,"INIT PORV : %g \n",init_porv);
        fprintf(stderr,"RPORV     : %g \n",rporv);
        fprintf(stderr,"Hmmm - the RPORV values extracted from the restart file seem to be \n");
        fprintf(stderr,"veeery different from the initial porv value. This might indicate \n");
        fprintf(stderr,"an ECLIPSE bug in the RPORV handling. Try using another ECLIPSE version,\n");
        fprintf(stderr,"or alternatively the PORMOD approach instead\n");
        fprintf(stderr,"-----------------------------------------------------------------\n");
        exit(1);
      }
      check_nr++;
    }
  }
}
예제 #5
0
ecl_rsthead_type * ecl_rsthead_ialloc( const ecl_file_type * rst_file , int occurence) {
  if (ecl_file_get_num_named_kw( rst_file , INTEHEAD_KW) > occurence) {
    const ecl_kw_type * intehead_kw = ecl_file_iget_named_kw( rst_file , INTEHEAD_KW , occurence);
    const ecl_kw_type * logihead_kw = ecl_file_iget_named_kw( rst_file , LOGIHEAD_KW , occurence);
    const ecl_kw_type * doubhead_kw = ecl_file_iget_named_kw( rst_file , DOUBHEAD_KW , occurence);
    
    ecl_rsthead_type * rsthead = util_malloc( sizeof * rsthead );
    
    {
      const int * data = (const int *) ecl_kw_get_void_ptr( intehead_kw );
      
      rsthead->day       = data[INTEHEAD_DAY_INDEX];
      rsthead->month     = data[INTEHEAD_MONTH_INDEX];
      rsthead->year      = data[INTEHEAD_YEAR_INDEX];
      rsthead->version   = data[INTEHEAD_IPROG_INDEX];
      rsthead->phase_sum = data[INTEHEAD_PHASE_INDEX];
      
      rsthead->nx        = data[INTEHEAD_NX_INDEX];
      rsthead->ny        = data[INTEHEAD_NY_INDEX];
      rsthead->nz        = data[INTEHEAD_NZ_INDEX];
      rsthead->nactive   = data[INTEHEAD_NACTIVE_INDEX];
      
      rsthead->nwells    = data[INTEHEAD_NWELLS_INDEX];
      rsthead->niwelz    = data[INTEHEAD_NIWELZ_INDEX];
      rsthead->nzwelz    = data[INTEHEAD_NZWELZ_INDEX];
      
      rsthead->nsconz    = data[INTEHEAD_NSCONZ_INDEX];
      rsthead->niconz    = data[INTEHEAD_NICONZ_INDEX];
      rsthead->ncwmax    = data[INTEHEAD_NCWMAX_INDEX];
      
      rsthead->nisegz    = data[INTEHEAD_NISEGZ_INDEX];
      rsthead->nsegmx    = data[INTEHEAD_NSEGMX_INDEX];
      rsthead->nswlmx    = data[INTEHEAD_NSWLMX_INDEX];
      rsthead->nrsegz    = data[INTEHEAD_NRSEGZ_INDEX];
      
      // The only derived quantity
      rsthead->sim_time  = rsthead_date( rsthead->day , rsthead->month , rsthead->year );
    }
    rsthead->dualp    = ecl_kw_iget_bool( logihead_kw , LOGIHEAD_DUALP_INDEX);
    rsthead->sim_days = ecl_kw_iget_double( doubhead_kw , DOUBHEAD_DAYS_INDEX );
    
    return rsthead;
  } else
    return NULL;
}
예제 #6
0
static void ecl_rft_node_init_RFT_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft) {
  const ecl_kw_type * conipos     = ecl_file_iget_named_kw( rft , CONIPOS_KW , 0);
  const ecl_kw_type * conjpos     = ecl_file_iget_named_kw( rft , CONJPOS_KW , 0);
  const ecl_kw_type * conkpos     = ecl_file_iget_named_kw( rft , CONKPOS_KW , 0);
  const ecl_kw_type * depth_kw    = ecl_file_iget_named_kw( rft , DEPTH_KW , 0);
  const ecl_kw_type * swat_kw     = ecl_file_iget_named_kw( rft , SWAT_KW , 0);
  const ecl_kw_type * sgas_kw     = ecl_file_iget_named_kw( rft , SGAS_KW , 0);
  const ecl_kw_type * pressure_kw = ecl_file_iget_named_kw( rft , PRESSURE_KW , 0);

  const float * SW     = ecl_kw_get_float_ptr( swat_kw );
  const float * SG     = ecl_kw_get_float_ptr( sgas_kw );
  const float * P      = ecl_kw_get_float_ptr( pressure_kw );
  const float * depth  = ecl_kw_get_float_ptr( depth_kw );
  const int   * i      = ecl_kw_get_int_ptr( conipos );
  const int   * j      = ecl_kw_get_int_ptr( conjpos );
  const int   * k      = ecl_kw_get_int_ptr( conkpos );
  
  {
    int c;
    for (c = 0; c < ecl_kw_get_size( conipos ); c++) {
      /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */
      ecl_rft_cell_type * cell = ecl_rft_cell_alloc_RFT( i[c] - 1 , j[c] - 1 , k[c] - 1 , 
                                                         depth[c] , P[c] , SW[c] , SG[c]);
      ecl_rft_node_append_cell( rft_node , cell );
    }
  }
}
예제 #7
0
well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_nr ,  int global_well_nr ,bool load_segment_information) {
  if (ecl_file_has_kw( ecl_file , IWEL_KW)) {
    well_state_type   * well_state = NULL;
    ecl_rsthead_type  * global_header  = ecl_rsthead_alloc( ecl_file );
    const ecl_kw_type * global_iwel_kw = ecl_file_iget_named_kw( ecl_file , IWEL_KW   , 0);
    const ecl_kw_type * global_zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW   , 0);

    const int iwel_offset = global_header->niwelz * global_well_nr;
    {
      char * name;
      bool open;
      well_type_enum type = UNDOCUMENTED_ZERO;
      {
        int int_state = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_STATUS_ITEM );
        if (int_state > 0)
          open = true;
        else
          open = false;
      }

      {
        int int_type = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_TYPE_ITEM);
        type = well_state_translate_ecl_type_int( int_type );
      }

      {
        const int zwel_offset         = global_header->nzwelz * global_well_nr;
        name = util_alloc_strip_copy(ecl_kw_iget_ptr( global_zwel_kw , zwel_offset ));  // Hardwired max 8 characters in Well Name
      }

      well_state = well_state_alloc(name , global_well_nr , open , type , report_nr , global_header->sim_time);
      free( name );

      well_state_add_connections( well_state , grid , ecl_file , global_well_nr);
      if (ecl_file_has_kw( ecl_file , ISEG_KW))
        well_state_add_MSW( well_state , ecl_file , global_well_nr , load_segment_information);
      

    }
    ecl_rsthead_free( global_header );
    return well_state;
  } else
    /* This seems a bit weird - have come over E300 restart files without the IWEL keyword. */
    return NULL;
}
예제 #8
0
void ECLFilesComparator::deviationsForOccurence(const std::string& keyword, int occurence) {
    ecl_kw_type* ecl_kw1         = ecl_file_iget_named_kw(ecl_file1, keyword.c_str(), occurence);
    ecl_kw_type* ecl_kw2         = ecl_file_iget_named_kw(ecl_file2, keyword.c_str(), occurence);
    const unsigned int numCells1 = ecl_kw_get_size(ecl_kw1);
    const unsigned int numCells2 = ecl_kw_get_size(ecl_kw2);
    if (numCells1 != numCells2) {
        std::cout << "For keyword " << keyword << " and occurence " << occurence << ":\n";
        OPM_THROW(std::runtime_error, "Number of active cells are different.");
    }
    std::vector<double> values1(numCells1), values2(numCells2);
    ecl_kw_get_data_as_double(ecl_kw1, values1.data());
    ecl_kw_get_data_as_double(ecl_kw2, values2.data());

    auto it = std::find(keywordWhitelist.begin(), keywordWhitelist.end(), keyword);
    for (unsigned int cell = 0; cell < values1.size(); cell++) {
        deviationsForCell(values1[cell], values2[cell], keyword, occurence, cell, it == keywordWhitelist.end());
    }
}
예제 #9
0
static ecl_grav_survey_type * ecl_grav_survey_alloc_PORMOD(ecl_grav_type * ecl_grav , 
                                                           const ecl_file_type * restart_file , 
                                                           const char * name ) {
  ecl_grid_cache_type * grid_cache = ecl_grav->grid_cache;
  ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_PORMOD);
  ecl_kw_type * init_porv_kw    = ecl_file_iget_named_kw( ecl_grav->init_file    , PORV_KW   , 0 );  /* Global indexing */
  ecl_kw_type * pormod_kw       = ecl_file_iget_named_kw( restart_file , PORMOD_KW , 0 );            /* Active indexing */
  const int size                = ecl_grid_cache_get_size( grid_cache ); 
  const int * global_index      = ecl_grid_cache_get_global_index( grid_cache );
  int active_index;

  for (active_index = 0; active_index < size; active_index++) 
    survey->porv[ active_index ] = ecl_kw_iget_float( pormod_kw , active_index ) * ecl_kw_iget_float( init_porv_kw , global_index[active_index] );
  
  ecl_grav_survey_add_phases( ecl_grav , survey , restart_file , GRAV_CALC_PORMOD);
  
  return survey;
}
예제 #10
0
파일: ecl_file.c 프로젝트: akva2/ert
void test_writable(const char * src_file ) {
  test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" );
  char * fname = util_split_alloc_filename( src_file );

  test_work_area_copy_file( work_area , src_file );
  {
    ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE);
    ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
    ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat );
    test_assert_true( ecl_kw_equal( swat , swat0 ));
    ecl_kw_iset_float( swat , 0 , 1000.0 );
    ecl_file_save_kw( ecl_file , swat );
    test_assert_true( ecl_file_writable( ecl_file ));
    ecl_file_close( ecl_file );

    ecl_file = ecl_file_open( fname , 0);
    swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
    test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 ));
  }
  test_work_area_free( work_area );
}
예제 #11
0
int main(int argc , char ** argv) {
  const char * case_path = argv[1];
  char * egrid_file  = ecl_util_alloc_filename( NULL , case_path , ECL_EGRID_FILE , false , 0 );
  char * rst_file    = ecl_util_alloc_filename( NULL , case_path , ECL_RESTART_FILE , false , 0 );
  char * init_file   = ecl_util_alloc_filename( NULL , case_path , ECL_INIT_FILE , false , 0 );
  
  ecl_grid_type * GRID      = ecl_grid_alloc(egrid_file );
  ecl_file_type * RST_file  = ecl_file_open( rst_file , 0);
  ecl_file_type * INIT_file = ecl_file_open( init_file , 0);

  {
    test_assert_true( ecl_grid_have_coarse_cells( GRID ) );
    test_assert_int_equal( ecl_grid_get_num_coarse_groups( GRID ) , 3384);
  }

  {
    const ecl_kw_type * swat0 = ecl_file_iget_named_kw( RST_file , "SWAT" , 0 );
    const ecl_kw_type * porv  = ecl_file_iget_named_kw( INIT_file , "PORV" , 0 );
    
    test_assert_int_equal( ecl_kw_get_size( swat0 ) , ecl_grid_get_active_size( GRID ) );
    test_assert_int_equal( ecl_kw_get_size( porv )  , ecl_grid_get_global_size( GRID ) );
  }
  
  {
    int ic;
    for (ic = 0; ic < ecl_grid_get_num_coarse_groups(GRID); ic++) {
      ecl_coarse_cell_type * coarse_cell = ecl_grid_iget_coarse_group( GRID , ic );
      test_coarse_cell( GRID , coarse_cell );
    }
  }
  
  

  ecl_file_close( INIT_file );
  ecl_file_close( RST_file );
  ecl_grid_free( GRID );
  exit(0);
}
예제 #12
0
ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_type * rft) {
  ecl_kw_type       * welletc   = ecl_file_iget_named_kw(rft , WELLETC_KW , 0);
  ecl_rft_node_type * rft_node  = ecl_rft_node_alloc_empty(ecl_kw_iget_ptr(welletc , WELLETC_TYPE_INDEX));
  
  if (rft_node != NULL) {
    ecl_kw_type * date_kw = ecl_file_iget_named_kw( rft , DATE_KW    , 0);
    rft_node->well_name = util_alloc_strip_copy( ecl_kw_iget_ptr(welletc , WELLETC_NAME_INDEX));
    
    /* Time information. */
    {
      int * time = ecl_kw_get_int_ptr( date_kw );
      rft_node->recording_date = ecl_util_make_date( time[DATE_DAY_INDEX] , time[DATE_MONTH_INDEX] , time[DATE_YEAR_INDEX] );
    }
    rft_node->days = ecl_kw_iget_float( ecl_file_iget_named_kw( rft , TIME_KW , 0 ) , 0);
    if (ecl_file_has_kw( rft , CONLENST_KW))
      rft_node->MSW = true;
    else
      rft_node->MSW = false;

    ecl_rft_node_init_cells( rft_node , rft );
  }
  return rft_node;
}
예제 #13
0
static void ecl_sum_data_add_ecl_file(ecl_sum_data_type * data         , 
                                      time_t load_end , 
                                      int   report_step                , 
                                      const ecl_file_type   * ecl_file , 
                                      const ecl_smspec_type * smspec) {
  
  
  int num_ministep  = ecl_file_get_num_named_kw( ecl_file , PARAMS_KW);
  if (num_ministep > 0) {
    int ikw;

    for (ikw = 0; ikw < num_ministep; ikw++) {
      ecl_kw_type * ministep_kw = ecl_file_iget_named_kw( ecl_file , MINISTEP_KW , ikw);
      ecl_kw_type * params_kw   = ecl_file_iget_named_kw( ecl_file , PARAMS_KW   , ikw);

      {
        ecl_sum_tstep_type * tstep;
        int ministep_nr = ecl_kw_iget_int( ministep_kw , 0 );
        tstep = ecl_sum_tstep_alloc_from_file( report_step , 
                                               ministep_nr ,
                                               params_kw , 
                                               ecl_file_get_src_file( ecl_file ),
                                               smspec );
        
        if (tstep != NULL) {
          if (load_end == 0 || (ecl_sum_tstep_get_sim_time( tstep ) < load_end))
            ecl_sum_data_append_tstep__( data , ministep_nr , tstep );
          else 
            /* This tstep is in a time-period overlapping with data we
               already have; discard this. */
            ecl_sum_tstep_free( tstep );
        }
      }
    }
  }
}
예제 #14
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::isExportedFromIntersect(ecl_file_type* ecl_file)
{
    // This code is taken from ecl_file_get_ecl_version() in ecl_file.cpp

    ecl_kw_type* intehead_kw = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, 0);
    if (!intehead_kw) return false;

    int int_value = ecl_kw_iget_int(intehead_kw, INTEHEAD_IPROG_INDEX);
    if (int_value == INTEHEAD_INTERSECT_VALUE)
    {
        return true;
    }

    return false;
}
예제 #15
0
//--------------------------------------------------------------------------------------------------
/// Returns the following integer values from the first INTEHEAD keyword found
///  1  : METRIC
///  2  : FIELD
///  3  : LAB
///  -1 : No INTEHEAD keyword found
//--------------------------------------------------------------------------------------------------
int RifEclipseOutputFileTools::readUnitsType(ecl_file_type* ecl_file)
{
    int unitsType = -1;

    if (ecl_file)
    {
        ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, 0);
        if (kwINTEHEAD)
        {
            unitsType = ecl_kw_iget_int(kwINTEHEAD, INTEHEAD_UNIT_INDEX);
        }
    }

    return unitsType;
}
예제 #16
0
파일: ecl_nnc_export.c 프로젝트: flikka/ert
ecl_kw_type * ecl_nnc_export_get_tran_kw( const ecl_file_type * init_file , const char * kw , int lgr_nr ) {
  ecl_kw_type * tran_kw = NULL;
  if (lgr_nr == 0) {
    if (strcmp(kw , TRANNNC_KW) == 0)
      if(ecl_file_has_kw(init_file, kw)) {
        tran_kw = ecl_file_iget_named_kw(init_file, TRANNNC_KW, 0);
      }
  } else {
    if ((strcmp(kw , TRANNNC_KW) == 0) ||
        (strcmp(kw , TRANGL_KW) == 0)) {
      const int file_num_kw = ecl_file_get_size( init_file );
      int global_kw_index = 0;
      bool finished = false;
      bool correct_lgrheadi = false;
      int head_index = 0;
      int steps = 0;


      while(!finished){
        ecl_kw_type * ecl_kw = ecl_file_iget_kw( init_file , global_kw_index );
        const char *current_kw = ecl_kw_get_header(ecl_kw);
        if (strcmp( LGRHEADI_KW , current_kw) == 0) {
          if (ecl_kw_iget_int( ecl_kw , LGRHEADI_LGR_NR_INDEX) == lgr_nr) {
            correct_lgrheadi = true;
            head_index = global_kw_index;
          }else{
            correct_lgrheadi = false;
          }
        }
        if(correct_lgrheadi) {
          if (strcmp(kw, current_kw) == 0) {
            steps  = global_kw_index - head_index; /* This is to calculate who fare from lgrheadi we found the TRANGL/TRANNNC key word */
            if(steps == 3 || steps == 4 || steps == 6) { /* We only support a file format where TRANNNC is 3 steps and TRANGL is 4 or 6 steps from LGRHEADI */
              tran_kw = ecl_kw;
              finished = true;
              break;
            }
          }
        }
        global_kw_index++;
        if (global_kw_index == file_num_kw)
          finished = true;
      }
    }
  }
  return tran_kw;
}
예제 #17
0
static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_PRESSURE(ecl_subsidence_type * ecl_subsidence ,
                                                                         const ecl_file_view_type * restart_view ,
                                                                         const char * name ) {

  ecl_subsidence_survey_type * survey = ecl_subsidence_survey_alloc_empty( ecl_subsidence , name );
  ecl_grid_cache_type * grid_cache = ecl_subsidence->grid_cache;
  const int * global_index = ecl_grid_cache_get_global_index( grid_cache );
  const int size = ecl_grid_cache_get_size( grid_cache );
  int active_index;
  ecl_kw_type * init_porv_kw = ecl_file_iget_named_kw( ecl_subsidence->init_file , PORV_KW , 0); /*Global indexing*/
  ecl_kw_type * pressure_kw = ecl_file_view_iget_named_kw( restart_view , PRESSURE_KW , 0); /*Active indexing*/

  for (active_index = 0; active_index < size; active_index++){
    survey->porv[ active_index ] = ecl_kw_iget_float( init_porv_kw , global_index[active_index] );
    survey->pressure[ active_index ] = ecl_kw_iget_float( pressure_kw , active_index );
  }
  return survey;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<int>* values)
{
    ecl_kw_type* kwData = ecl_file_iget_named_kw(ecl_file, keyword.toAscii().data(), static_cast<int>(fileKeywordOccurrence));
    if (kwData)
    {
        size_t numValues = ecl_kw_get_size(kwData);

        std::vector<int> integerData;
        integerData.resize(numValues);

        ecl_kw_get_memcpy_int_data(kwData, integerData.data());
        values->insert(values->end(), integerData.begin(), integerData.end());

        return true;
    }

    return false;
}
예제 #19
0
static ecl_grav_survey_type * ecl_grav_survey_alloc_RPORV(ecl_grav_type * ecl_grav , 
                                                          const ecl_file_type * restart_file , 
                                                          const char * name ) {
  ecl_grav_survey_type * survey = ecl_grav_survey_alloc_empty( ecl_grav , name , GRAV_CALC_RPORV);
  if (ecl_file_has_kw( restart_file , RPORV_KW)) {
    ecl_kw_type * rporv_kw = ecl_file_iget_named_kw( restart_file , RPORV_KW , 0);
    int iactive;
    for (iactive = 0; iactive < ecl_kw_get_size( rporv_kw ); iactive++) 
      survey->porv[ iactive ] = ecl_kw_iget_as_double( rporv_kw , iactive );
  } else 
    util_abort("%s: restart file did not contain %s keyword??\n",__func__ , RPORV_KW);
  
  {
    const ecl_file_type * init_file = ecl_grav->init_file;
    ecl_grav_survey_assert_RPORV( survey , init_file );
    ecl_grav_survey_add_phases( ecl_grav , survey ,  restart_file , GRAV_CALC_RPORV);
  }
  return survey;
}
예제 #20
0
bool ECLFilesComparator::keywordValidForComparing(const std::string& keyword) const {
    auto it = std::find(keywords1.begin(), keywords1.end(), keyword);
    if (it == keywords1.end()) {
        std::cout << "Could not find keyword: " << keyword << std::endl;
        OPM_THROW(std::runtime_error, "Keyword does not exist in first file.");
    }
    it = find(keywords2.begin(), keywords2.end(), keyword);
    if (it == keywords2.end()) {
        std::cout << "Could not find keyword: " << keyword << std::endl;
        OPM_THROW(std::runtime_error, "Keyword does not exist in second file.");
    }
    ecl_kw_type* ecl_kw = ecl_file_iget_named_kw(ecl_file1, keyword.c_str(), 0);
    ecl_type_enum ecl_kw_type = ecl_kw_get_type(ecl_kw);
    switch (ecl_kw_type) {
        case ECL_DOUBLE_TYPE:
            return true;
        case ECL_FLOAT_TYPE:
            return true;
        case ECL_CHAR_TYPE:
            std::cout << "\nKeyword " << keyword << " is of type ECL_CHAR_TYPE, "
                << "which is not supported for comparison." << std::endl;
            return false;
        case ECL_INT_TYPE:
            std::cout << "\nKeyword " << keyword << " is of type ECL_INT_TYPE, "
                << "which is not supported for comparison." << std::endl;
            return false;
        case ECL_BOOL_TYPE:
            std::cout << "\nKeyword " << keyword << " is of type ECL_BOOL_TYPE, "
                << "which is not supported for comparison." << std::endl;
            return false;
        case ECL_MESS_TYPE:
            std::cout << "\nKeyword " << keyword << " is of type ECL_MESS_TYPE, "
                << "which is not supported for comparison." << std::endl;
            return false;
        default:
            std::cout << "\nKeyword " << keyword << "has undefined type." << std::endl;
            return false;
    }
}
예제 #21
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<int>* values)
{
    bool result = false;

#pragma omp critical(critical_section_keywordData_int)
    {
        ecl_kw_type* kwData = ecl_file_iget_named_kw(ecl_file, RiaStringEncodingTools::toNativeEncoded(keyword).data(), static_cast<int>(fileKeywordOccurrence));
        if (kwData)
        {
            size_t numValues = ecl_kw_get_size(kwData);

            std::vector<int> integerData;
            integerData.resize(numValues);

            ecl_kw_get_memcpy_int_data(kwData, integerData.data());
            values->insert(values->end(), integerData.begin(), integerData.end());

            result = true;
        }
    }

    return result;
}
예제 #22
0
    void restorePressureData(const ecl_file_type* file,
                             EclipseStateConstPtr eclipse_state,
                             int numcells,
                             SimulatorState& simulator_state) {
        const char* pressure = "PRESSURE";

        if (ecl_file_has_kw(file , pressure)) {

            ecl_kw_type* pressure_kw = ecl_file_iget_named_kw(file, pressure, 0);

            if (ecl_kw_get_size(pressure_kw) != numcells) {
                throw std::runtime_error("Read of restart file: Could not restore pressure data, length of data from file not equal number of cells");
            }

            float* pressure_data = ecl_kw_get_float_ptr(pressure_kw);
            const double deck_pressure_unit = (eclipse_state->getDeckUnitSystem().getType() == UnitSystem::UNIT_TYPE_METRIC) ? Opm::unit::barsa : Opm::unit::psia;
            for (size_t index = 0; index < simulator_state.pressure().size(); ++index) {
                simulator_state.pressure()[index] = unit::convert::from((double)pressure_data[index], deck_pressure_unit);
            }
        } else {
            throw std::runtime_error("Read of restart file: File does not contain PRESSURE data\n");
        }
    }
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
std::vector<int> RifEclipseUnifiedRestartFileAccess::reportNumbers()
{
    std::vector<int> reportNr;

    // Taken from well_info_add_UNRST_wells

    int num_blocks = ecl_file_get_num_named_kw(m_ecl_file, SEQNUM_KW);
    int block_nr;
    for (block_nr = 0; block_nr < num_blocks; block_nr++) {
        ecl_file_push_block(m_ecl_file);      // <-------------------------------------------------------
        {                                                                                               //
            ecl_file_subselect_block(m_ecl_file, SEQNUM_KW, block_nr);                                  //  Ensure that the status
            {                                                                                             //  is not changed as a side
                const ecl_kw_type * seqnum_kw = ecl_file_iget_named_kw(m_ecl_file, SEQNUM_KW, 0);          //  effect.
                int report_nr = ecl_kw_iget_int(seqnum_kw, 0);                                           //

                reportNr.push_back(report_nr);
            }                                                                                             //
        }                                                                                               //
        ecl_file_pop_block(m_ecl_file);       // <-------------------------------------------------------
    }

    return reportNr;
}
예제 #24
0
int main(int argc , char ** argv) {
  const char * Xfile = argv[1];
  ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
  ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file );
  const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
  const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 );
  const ecl_kw_type * rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0 );
  const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );

  test_install_SIGNALS();
  test_assert_not_NULL( rst_file );
  test_assert_not_NULL( rst_head );
  {
    int well_nr;
    for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) {
      well_conn_collection_type * connections = well_conn_collection_alloc();
      well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , well_nr , rst_head);
      {
        well_segment_collection_type * segments = well_segment_collection_alloc();

        if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_kw , rst_head )) {
          well_branch_collection_type * branches = well_branch_collection_alloc();

          test_assert_true( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head));
          well_segment_collection_link( segments );
          {
            int is;
            for (is=0; is < well_segment_collection_get_size( segments ); is++) {
              well_segment_type * segment = well_segment_collection_iget( segments , is );

              if (well_segment_nearest_wellhead( segment ))
                test_assert_NULL( well_segment_get_outlet( segment ));
              else
                test_assert_not_NULL( well_segment_get_outlet( segment ));

              test_assert_ptr_not_equal( segment , well_segment_get_outlet( segment ));
            }
          }

          well_segment_collection_add_branches( segments , branches );
          {
            int ib;
            for (ib = 0; ib < well_branch_collection_get_size( branches ); ib++) {
              const well_segment_type * start_segment = well_branch_collection_iget_start_segment( branches , ib );
              const well_segment_type * segment = start_segment;

              printf("Branch %d/%d " , ib , well_branch_collection_get_size( branches ) );
              while (segment) {
                printf("[%p]%d -> \n",segment , well_segment_get_id( segment ));
                segment = well_segment_get_outlet( segment );
              }
              printf("\n");
              sleep(1);
            }
          }
          well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections );
          well_branch_collection_free( branches );
        } else
          test_assert_false( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head ));

        well_segment_collection_free( segments );
      }
      well_conn_collection_free( connections );
    }
  }

  ecl_file_close( rst_file );
  ecl_rsthead_free( rst_head );
  exit(0);
}
예제 #25
0
파일: segment_info.c 프로젝트: agchitu/ert
int main(int argc , char ** argv) {
  const char * Xfile = argv[1];
  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));
  const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
  const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 );
  well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(ecl_file_get_global_view(rst_file));
  const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
  const ecl_kw_type * scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0 );
  const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( rst_file , ZWEL_KW , 0 );

  { 
    int well_nr;
    for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) {
      const int zwel_offset  = rst_head->nzwelz * well_nr;
      char * well_name       = util_alloc_strip_copy(ecl_kw_iget_ptr( zwel_kw , zwel_offset ));  
      
      printf("=================================================================\n");
      printf("Well: %s ",well_name);
      {
        well_conn_collection_type * connections = well_conn_collection_alloc();
        well_segment_collection_type * segments = well_segment_collection_alloc();
        bool load_segment_information = true;
        bool is_MSW_well = false;
                
        if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_loader , rst_head , load_segment_information , &is_MSW_well)) {
          well_branch_collection_type * branches = well_branch_collection_alloc();

          well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , scon_kw , well_nr , rst_head);
          well_segment_collection_link( segments );
          well_segment_collection_add_branches( segments , branches );
          well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); 
          
          printf("\n");
          printf("Segments:\n");
          {
            int is;
            for (is=0; is < well_segment_collection_get_size( segments ); is++) {
              well_segment_type * segment = well_segment_collection_iget( segments , is );
              printf("-----------------------------------------------------------------\n");
              printf("ID          : %d \n",well_segment_get_id( segment ));
              printf("Outlet      : %d \n",well_segment_get_outlet_id( segment ));
              printf("Branch      : %d \n",well_segment_get_branch_id( segment ));
              printf("Connections : [");
              {
                const well_conn_collection_type * connections = well_segment_get_global_connections( segment );
                if (connections) {
                  int ic;
                  for (ic = 0; ic < well_conn_collection_get_size( connections ); ic++) {
                    const well_conn_type * conn = well_conn_collection_iget( connections , ic );
                    printf("(%d , %d , %d)  ",well_conn_get_i( conn ), well_conn_get_j( conn ), well_conn_get_k( conn ));
                  }
                }
              }
              
              printf("]\n");
            }
          }
          well_branch_collection_free( branches );
        } else
          printf("not MSW well\n\n");

        well_conn_collection_free( connections );
        well_segment_collection_free( segments );
      }
    }
  }

  ecl_file_close( rst_file );
  ecl_rsthead_free( rst_head );
}
예제 #26
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;
  }
}
예제 #27
0
static void ecl_rft_node_init_PLT_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft) {
  /* For PLT there is quite a lot of extra information which is not yet internalized. */
  const ecl_kw_type * conipos     = ecl_file_iget_named_kw( rft , CONIPOS_KW  , 0);
  const ecl_kw_type * conjpos     = ecl_file_iget_named_kw( rft , CONJPOS_KW  , 0);
  const ecl_kw_type * conkpos     = ecl_file_iget_named_kw( rft , CONKPOS_KW  , 0);  

  const int   * i      = ecl_kw_get_int_ptr( conipos );
  const int   * j      = ecl_kw_get_int_ptr( conjpos );
  const int   * k      = ecl_kw_get_int_ptr( conkpos );
  
  const float * WR               = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWRAT_KW , 0));
  const float * GR               = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGRAT_KW , 0)); 
  const float * OR               = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONORAT_KW , 0)); 
  const float * P                = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONPRES_KW , 0));
  const float * depth            = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONDEPTH_KW , 0));
  const float * flowrate         = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONVTUB_KW , 0));
  const float * oil_flowrate     = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONOTUB_KW , 0));
  const float * gas_flowrate     = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGTUB_KW , 0));
  const float * water_flowrate   = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWTUB_KW , 0));
  const float * connection_start = NULL;
  const float * connection_end   = NULL; 

  /* The keywords CONLENST_KW and CONLENEN_KW are ONLY present if we are dealing with a MSW well. */
  if (ecl_file_has_kw( rft , CONLENST_KW))
    connection_start = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENST_KW , 0));
  
  if (ecl_file_has_kw( rft , CONLENEN_KW))
    connection_end = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENEN_KW , 0));

  {
    int c;
    for ( c = 0; c < ecl_kw_get_size( conipos ); c++) {
      ecl_rft_cell_type * cell;
      double cs = 0;
      double ce = 0;
      
      if (connection_start)
        cs = connection_start[c];
      
      if (connection_end)
        ce = connection_end[c];

      /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */
      cell = ecl_rft_cell_alloc_PLT( i[c] -1 , j[c] -1 , k[c] -1 , 
                                     depth[c] , P[c] , OR[c] , GR[c] , WR[c] , cs , ce,  flowrate[c] , oil_flowrate[c] , gas_flowrate[c] , water_flowrate[c]);
      ecl_rft_node_append_cell( rft_node , cell );
    }
  }
}
예제 #28
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 );
}
//--------------------------------------------------------------------------------------------------
/// Get list of time step texts (dates)
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, std::vector<QDateTime>* timeSteps, bool* detectedFractionOfDay )
{
    CVF_ASSERT(timeSteps);
    CVF_ASSERT(ecl_file);

    // Get the number of occurrences of the INTEHEAD keyword
    int numINTEHEAD = ecl_file_get_num_named_kw(ecl_file, INTEHEAD_KW);

    // Get the number of occurrences of the DOUBHEAD keyword
    int numDOUBHEAD = ecl_file_get_num_named_kw(ecl_file, DOUBHEAD_KW);

    CVF_ASSERT(numINTEHEAD == numDOUBHEAD);

    bool hasFractionOfDay = false;
    bool foundAllDayValues = false;
    const double delta = 0.001;

    // Find all days, and stop when the double value is lower than the previous
    QList<double> days;
    for (int i = 0; i < numDOUBHEAD; i++)
    {
        if (foundAllDayValues) continue;;

        ecl_kw_type* kwDOUBHEAD = ecl_file_iget_named_kw(ecl_file, DOUBHEAD_KW, i);
        if (kwDOUBHEAD)
        {
            double dayValue = ecl_kw_iget_double(kwDOUBHEAD, DOUBHEAD_DAYS_INDEX);
            double floorDayValue = cvf::Math::floor(dayValue);

            if (dayValue - floorDayValue > delta)
            {
                hasFractionOfDay = true;
            }

            days.push_back(dayValue);
        }
    }

    std::vector<QDateTime> timeStepsFound;

    if (hasFractionOfDay)
    {
        ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, 0);
        if (kwINTEHEAD)
        {
            int day = 0;
            int month = 0;
            int year = 0;
            getDayMonthYear(kwINTEHEAD, &day, &month, &year);

            QDateTime simulationStart(QDate(year, month, day));
            for (int i = 0; i < days.size(); i++)
            {
                QDateTime reportDateTime(simulationStart);
                CVF_ASSERT(reportDateTime.isValid());

                double dayValue = days[i];
                double floorDayValue = cvf::Math::floor(dayValue);
                reportDateTime = reportDateTime.addDays(static_cast<int>(floorDayValue));

                double dayFraction = dayValue - floorDayValue;
                int seconds = static_cast<int>(dayFraction * 24.0 * 60.0 * 60.0);
                QTime time(0, 0);
                time = time.addSecs(seconds);

                reportDateTime.setTime(time);

                if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) ==  timeStepsFound.end())
                {
                    timeStepsFound.push_back(reportDateTime);
                }
            }
        }
    }
    else
    {
        for (int i = 0; i < numINTEHEAD; i++)
        {
            ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, i);
            if (kwINTEHEAD)
            {
                int day = 0;
                int month = 0;
                int year = 0;
                getDayMonthYear(kwINTEHEAD, &day, &month, &year);

                QDateTime reportDateTime(QDate(year, month, day));
                QTime time(0, 0);
                reportDateTime.setTime(time);

                CVF_ASSERT(reportDateTime.isValid());

                if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) ==  timeStepsFound.end())
                {
                    timeStepsFound.push_back(reportDateTime);
                }
            }
        }
    }

    // Return time step info to caller
    *timeSteps = timeStepsFound;

    if (detectedFractionOfDay)
    {
        *detectedFractionOfDay = hasFractionOfDay;
    }
}
예제 #30
0
파일: ecl_unpack.c 프로젝트: akva2/ert
void unpack_file(const char * filename) {
  ecl_file_enum target_type = ECL_OTHER_FILE;
  ecl_file_enum file_type;
  bool fmt_file;
  file_type = ecl_util_get_file_type(filename , &fmt_file , NULL);
  if (file_type == ECL_UNIFIED_SUMMARY_FILE)
    target_type = ECL_SUMMARY_FILE;
  else if (file_type == ECL_UNIFIED_RESTART_FILE)
    target_type = ECL_RESTART_FILE;
  else 
    util_exit("Can only unpack unified ECLIPSE summary and restart files\n");
  
  if (target_type == ECL_SUMMARY_FILE) {
    printf("** Warning: when unpacking unified summary files it as ambigous - starting with 0001  -> \n");
  }
  {
    ecl_file_type * src_file = ecl_file_open( filename , 0 );
    int    size;
    int    offset;
    int    report_step = 0;
    int    block_index = 0;
    char * path; 
    char * base;
    msg_type * msg;
    util_alloc_file_components( filename , &path , &base , NULL);
    {
      char * label  = util_alloc_sprintf("Unpacking %s => ", filename);
      msg = msg_alloc( label , false);
      free( label );
    }
    msg_show(msg);

    if (target_type == ECL_SUMMARY_FILE) 
      size = ecl_file_get_num_named_kw( src_file , "SEQHDR" );
    else
      size = ecl_file_get_num_named_kw( src_file , "SEQNUM" );
    
    
    while (true) {
      if (block_index == size)
        break;

      if (target_type == ECL_SUMMARY_FILE) {
        ecl_file_select_block( src_file , SEQHDR_KW , block_index );
        report_step += 1;
        offset = 0;
      } else {
        ecl_kw_type * seqnum_kw;
        ecl_file_select_block( src_file , SEQNUM_KW , block_index );
        seqnum_kw = ecl_file_iget_named_kw( src_file , SEQNUM_KW , 0);
        report_step = ecl_kw_iget_int( seqnum_kw , 0);
        offset = 1;
      }

      /**
         Will unpack to cwd, even though the source files might be
         somewhere else. To unpack to the same directory as the source
         files, just send in @path as first argument when creating the
         target_file.
      */
      
      {
        char * target_file = ecl_util_alloc_filename( NULL , base , target_type , fmt_file , report_step);
        fortio_type * fortio_target = fortio_open_writer( target_file , fmt_file , ECL_ENDIAN_FLIP );
        msg_update(msg , target_file);
        ecl_file_fwrite_fortio( src_file , fortio_target , offset);
        
        fortio_fclose(fortio_target);
        free(target_file);
      }
      block_index++;
    } 
    ecl_file_close( src_file );
    util_safe_free(path);
    free(base);
    msg_free(msg , true);
  }
}