int main(int argc , char ** argv) {
  util_install_signals();
  {
    ecl_grid_type * grid = ecl_grid_alloc( argv[1] );
    vector_type * expected = load_expected( grid, argv[2] );

    for (int c=0; c < vector_get_size( expected ); c++) {
      const point_type * p = vector_iget_const( expected , c );
      int g = ecl_grid_get_global_index_from_xyz(grid , p->x, p->y , p->z , 0 );
      if (g != ecl_grid_get_global_index3(grid, p->i,p->j, p->k)) {
        int i,j,k;
        ecl_grid_get_ijk1(grid, g, &i, &j, &k);
        fprintf(stderr,"point:%d   (%g,%g,%g), Simulated: %d:(%d,%d,%d)   Expected: %d:(%d,%d,%d)  contains:%d\n",
                c , p->x, p->y, p->z, g, i,j,k, p->g, p->i, p->j, p->k, ecl_grid_cell_contains_xyz1( grid, p->g , p->x , p->y, p->z));
      }
      if (!p->skip)
        test_assert_int_equal( g , ecl_grid_get_global_index3(grid, p->i,p->j, p->k));
      else {
        if ( g != ecl_grid_get_global_index3(grid, p->i,p->j, p->k))
          fprintf(stderr," ** Skipping failed test for point:%d \n",c);
      }
    }
    ecl_grid_free( grid );
    vector_free( expected );
  }
  exit(0);
}
Exemple #2
0
void ecl_config_free(ecl_config_type * ecl_config) {
  ecl_io_config_free( ecl_config->io_config );
  if (ecl_config->eclbase != NULL) 
    path_fmt_free( ecl_config->eclbase );

  set_free( ecl_config->static_kw_set );
  stringlist_free( ecl_config->user_static_kw );
  util_safe_free(ecl_config->data_file);
  if (ecl_config->sched_file != NULL)
    sched_file_free(ecl_config->sched_file);


  util_safe_free(ecl_config->schedule_target_file);
  hash_free( ecl_config->fixed_length_kw );

  util_safe_free(ecl_config->input_init_section);
  util_safe_free(ecl_config->init_section);
  util_safe_free(ecl_config->schedule_prediction_file);

  if (ecl_config->grid != NULL)
    ecl_grid_free( ecl_config->grid );

  ecl_refcase_list_free( ecl_config->refcase_list );
  
  free(ecl_config);
}
Exemple #3
0
void test_create_simple() {
  test_work_area_type * work_area = test_work_area_alloc("nnc-INIT");
  {
    int nx = 10;
    int ny = 10;
    int nz = 10;
    ecl_grid_type * grid0 = ecl_grid_alloc_rectangular(nx,ny,nz,1,1,1,NULL);

    ecl_grid_add_self_nnc(grid0, 0 ,nx*ny + 0, 0 );
    ecl_grid_add_self_nnc(grid0, 1 ,nx*ny + 1, 1 );
    ecl_grid_add_self_nnc(grid0, 2 ,nx*ny + 2, 2 );
    {
      ecl_nnc_geometry_type * nnc_geo = ecl_nnc_geometry_alloc( grid0 );
      test_assert_int_equal( ecl_nnc_geometry_size( nnc_geo ) , 3 );

      /*
        Create a dummy INIT file which *ony* contains a TRANNC keyword with the correct size.
      */
      {
        ecl_kw_type * trann_nnc = ecl_kw_alloc(TRANNNC_KW , ecl_nnc_geometry_size( nnc_geo ), ECL_FLOAT);
        fortio_type * f = fortio_open_writer( "TEST.INIT" , false, ECL_ENDIAN_FLIP );

        for (int i=0; i < ecl_kw_get_size( trann_nnc); i++)
          ecl_kw_iset_float( trann_nnc , i , i*1.0 );

        ecl_kw_fwrite( trann_nnc , f );
        fortio_fclose( f );
        ecl_kw_free( trann_nnc );
      }
    }
    ecl_grid_free( grid0 );
  }
  test_work_area_free( work_area );
}
Exemple #4
0
int main( int argc , char ** argv) {
  ecl_grid_type * grid = ecl_grid_alloc_rectangular( 10,11,12,1,2,3 , NULL);
  test_copy_grid( grid );
  ecl_grid_free( grid );

  exit(0);
}
int main( int argc , char ** argv) {
  const char * egrid_file = argv[1];

  ecl_grid_type * grid = ecl_grid_alloc( egrid_file );
  ecl_file_type * gfile = ecl_file_open( egrid_file , 0 );
  const ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw( gfile , "NNC1" ,0 );
  const ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw( gfile , "NNC2" ,0 );
  const int_vector_type * index_list = ecl_grid_get_nnc_index_list( grid );
  
  {
    int_vector_type * nnc = int_vector_alloc(0,0);
    
    int_vector_set_many( nnc , 0 , ecl_kw_get_ptr( nnc1_kw ) , ecl_kw_get_size( nnc1_kw ));
    int_vector_append_many( nnc , ecl_kw_get_ptr( nnc2_kw ) , ecl_kw_get_size( nnc2_kw ));
    int_vector_select_unique( nnc );
    test_assert_int_equal( int_vector_size( index_list ) , int_vector_size( nnc ));
    
    {
      int i;
      for (i=0; i < int_vector_size( nnc ); i++)
        test_assert_int_equal( int_vector_iget( nnc , i ) - 1 , int_vector_iget(index_list , i ));
    }
    int_vector_free( nnc );
  }
  
  ecl_file_close( gfile );
  ecl_grid_free( grid );

  exit(0);
}
void test_get_tranLL(const char * name) {
  char * grid_file_name = ecl_util_alloc_filename(NULL , name , ECL_EGRID_FILE , false  , -1);
  char * init_file_name = ecl_util_alloc_filename(NULL , name , ECL_INIT_FILE , false  , -1);
  ecl_grid_type * grid = ecl_grid_alloc( grid_file_name );
  ecl_file_type * grid_file = ecl_file_open( grid_file_name , 0 );
  ecl_file_type * init_file = ecl_file_open( init_file_name , 0 );

  test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG003017" ), ecl_grid_get_lgr_nr_from_name( grid , "LG003018" ),
               172 , 5.3957253 , 1.0099934);

  test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG002016" ), ecl_grid_get_lgr_nr_from_name( grid , "LG002017" ),
               93 , 1.4638059 , 0.36407200 );

  test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG002016" ), ecl_grid_get_lgr_nr_from_name( grid , "LG003016" ),
               56 , 2.7360380 , 10.053267);

  test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG009027" ), ecl_grid_get_lgr_nr_from_name( grid , "LG009026" ),
               152 , 155.47754, 219.23553);

  test_tranLL( grid , init_file , ecl_grid_get_lgr_nr_from_name( grid , "LG009027" ), ecl_grid_get_lgr_nr_from_name( grid , "LG008027" ),
               317 , 0.040260997 , 0.0066288318);


  free( init_file_name );
  free(grid_file_name);
  ecl_grid_free( grid );
  ecl_file_close( grid_file );
  ecl_file_close( init_file );
}
Exemple #7
0
void test_truncated() {
  test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" );
  {
    ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL);
    ecl_grid_fwrite_EGRID2( grid , "TEST.EGRID", ECL_METRIC_UNITS );
    ecl_grid_free( grid );
  }
  {
    ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
    test_assert_true( ecl_file_is_instance( ecl_file ) );
    ecl_file_close( ecl_file );
  }

  {
    offset_type file_size = util_file_size( "TEST.EGRID");
    FILE * stream = util_fopen("TEST.EGRID" , "r+");
    util_ftruncate( stream , file_size / 2 );
    fclose( stream );
  }
  {
    ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
    test_assert_NULL( ecl_file );
  }
  test_work_area_free( work_area );
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
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 );

}
Exemple #9
0
void field_config_free(field_config_type * config) {
    util_safe_free(config->ecl_kw_name);
    util_safe_free(config->input_transform_name);
    util_safe_free(config->output_transform_name);
    util_safe_free(config->init_transform_name);
    if ((config->private_grid) && (config->grid != NULL)) ecl_grid_free( config->grid );
    free(config);
}
Exemple #10
0
void test_create_empty() {
  ecl_grid_type * grid = ecl_grid_alloc_rectangular(10,10,10,1,1,1,NULL);
  ecl_nnc_geometry_type * nnc_geo = ecl_nnc_geometry_alloc( grid );
  test_assert_true( ecl_nnc_geometry_is_instance( nnc_geo ));
  test_assert_int_equal( ecl_nnc_geometry_size( nnc_geo ) , 0 );
  ecl_nnc_geometry_free( nnc_geo );
  ecl_grid_free( grid );
}
Exemple #11
0
int main(int argc , char ** argv) {
  const char * path_case = argv[1];
  char * grid_file = ecl_util_alloc_filename( NULL , path_case , ECL_EGRID_FILE , false , 0 );
  char * init_file = ecl_util_alloc_filename( NULL , path_case , ECL_INIT_FILE , false , 0 );

  ecl_file_type * init = ecl_file_open( init_file , 0 );
  ecl_grid_type * grid = ecl_grid_alloc( grid_file );
  const ecl_kw_type * poro_kw = ecl_file_iget_named_kw( init , "PORO" , 0 );
  const ecl_kw_type * porv_kw = ecl_file_iget_named_kw( init , "PORV" , 0 );
  ecl_kw_type * multpv = NULL;
  ecl_kw_type * NTG = NULL;
  bool error_found = false;

  double total_volume = 0;
  double total_diff = 0;
  int error_count = 0;
  int iactive;

  if (ecl_file_has_kw( init , "NTG"))
    NTG = ecl_file_iget_named_kw( init , "NTG" , 0);

  if (ecl_file_has_kw( init , "MULTPV"))
    multpv = ecl_file_iget_named_kw( init , "MULTPV" , 0);

  for (iactive = 0; iactive < ecl_grid_get_nactive( grid ); ++iactive) {
    int iglobal = ecl_grid_get_global_index1A( grid , iactive );
    double grid_volume = ecl_grid_get_cell_volume1( grid , iglobal );
    double eclipse_volume = ecl_kw_iget_float( porv_kw , iglobal ) / ecl_kw_iget_float( poro_kw , iactive );

    if (NTG)
      eclipse_volume /= ecl_kw_iget_float( NTG , iactive );

    if (multpv)
      eclipse_volume *= ecl_kw_iget_float( multpv , iactive);

    total_volume += grid_volume;
    total_diff += fabs( eclipse_volume - grid_volume );
    if (!util_double_approx_equal__( grid_volume , eclipse_volume , 2.5e-3, 0.00)) {
      double diff = 100 * (grid_volume - eclipse_volume) / eclipse_volume;
      printf("Error in cell: %d V1: %g    V2: %g   diff:%g %% \n", iglobal , grid_volume , eclipse_volume , diff);
      error_count++;
      error_found = true;
    }
  }
  printf("Total volume difference: %g %% \n", 100 * total_diff / total_volume );



  ecl_grid_free( grid );
  ecl_file_close( init );
  free( grid_file );
  free( init_file );
  if (error_found) {
    printf("Error_count: %d / %d \n",error_count , ecl_grid_get_nactive( grid ));
    exit(1);
  }  else
    exit(0);
}
Exemple #12
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);
}
Exemple #13
0
int main (int argc , char ** argv) {
  ecl_grid_type * grid = ecl_grid_alloc( argv[1] );
  {
    test_create_invalid_data( grid );
    test_create_from_field(grid);
    test_create_from_summary( grid);
  }
  ecl_grid_free( grid );
  exit(0);
}
//--------------------------------------------------------------------------------------------------
/// Open file and read geometry into given reservoir object
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::open(const QString& fileName, RigReservoir* reservoir)
{
    CVF_ASSERT(reservoir);
    caf::ProgressInfo progInfo(100, "");

    progInfo.setProgressDescription("Reading Grid");

    // Make sure everything's closed
    close();

    // Get set of files
    QStringList fileSet;
    if (!RifEclipseOutputFileTools::fileSet(fileName, &fileSet)) return false;

    progInfo.incrementProgress();

    progInfo.setNextProgressIncrement(20);
    // Keep the set of files of interest
    m_fileSet = fileSet;

    // Read geometry
    ecl_grid_type * mainEclGrid = ecl_grid_alloc( fileName.toAscii().data() );

    progInfo.incrementProgress();

    progInfo.setNextProgressIncrement(10);
    progInfo.setProgressDescription("Transferring grid geometry");

    if (!transferGeometry(mainEclGrid, reservoir)) return false;
    progInfo.incrementProgress();

    progInfo.setProgressDescription("Releasing reader memory");
    ecl_grid_free( mainEclGrid );
    progInfo.incrementProgress();

    progInfo.setProgressDescription("Reading Result index");
    progInfo.setNextProgressIncrement(60);

    m_mainGrid = reservoir->mainGrid();

    reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(this);
    reservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(this);

    // Build results meta data
    if (!buildMetaData(reservoir)) return false;
    progInfo.incrementProgress();

    progInfo.setNextProgressIncrement(8);
    progInfo.setProgressDescription("Reading Well information");

    readWellCells(reservoir);


    return true;
}
Exemple #15
0
int main(int argc , char ** argv) {
  ecl_grid_type * grid;

  if (argc == 1) 
    grid = ecl_grid_alloc_rectangular(6,6,6,1,2,3,NULL);
  else
    grid = ecl_grid_alloc( argv[1] );

  test_cells( grid );
  ecl_grid_free( grid );
  exit(0);
}
Exemple #16
0
int main(int argc, char ** argv) {
  if (argc < 2) {
    fprintf(stderr,"%s: filename \n",argv[0]);
    exit(1);
  }

  {
    ecl_grid_type * ecl_grid;
    const char    * grid_file = argv[1];
    
    
    ecl_grid = ecl_grid_alloc(grid_file );
    ecl_grid_summarize( ecl_grid );
    if (argc >= 3) {
      ecl_grid_type * grid2 = ecl_grid_alloc( argv[2] );
      
      if (ecl_grid_compare( ecl_grid , grid2 , true , false , false))
        printf("\nThe grids %s %s are IDENTICAL.\n" , argv[1] , argv[2]);
      else {
        printf("\n");
        ecl_grid_summarize( grid2 );
        printf("\nThe grids %s %s are DIFFERENT.\n", argv[1] , argv[2]);
      }
      ecl_grid_free( grid2 );
    }
    /*
    printf("----\n");
    {
      double * ri_points = util_calloc( ecl_grid_get_global_size( ecl_grid ) * 24 , sizeof * ri_points ); 
      ecl_grid_ri_export( ecl_grid , ri_points );
      free( ri_points );
    }
    printf("----\n");
    */
    ecl_grid_fwrite_EGRID( ecl_grid , "/tmp/INFO.EGRID", true);
    ecl_grid_free(ecl_grid);
  }
}
Exemple #17
0
int main(int argc , char ** argv) {
  const char * grid_file = argv[1];
  ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file );
  ecl_file_type * ecl_file = ecl_file_open( grid_file , 0);
  
  ecl_grid_test_lgr_consistency( ecl_grid );

  if (ecl_file_get_num_named_kw( ecl_file , COORD_KW ))
    test_assert_int_equal( ecl_file_get_num_named_kw( ecl_file , COORD_KW ) - 1, ecl_grid_get_num_lgr( ecl_grid ));
  
  ecl_grid_free( ecl_grid );
  ecl_file_close( ecl_file);
  exit(0);
}
Exemple #18
0
int main(int argc , char ** argv) {
  ecl_grid_type * ecl_grid = ecl_grid_alloc_rectangular( 9 , 9 , 2 , 1 , 1 , 1 , NULL );
  ecl_kw_type * fault_blk_kw = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( ecl_grid ) , ECL_INT_TYPE );

  test_create( ecl_grid , fault_blk_kw );
  test_create_invalid( ecl_grid );
  test_trace_edge( ecl_grid );
  test_export(ecl_grid);
  test_neighbours( ecl_grid );

  ecl_grid_free( ecl_grid );
  ecl_kw_free( fault_blk_kw );
  exit(0);
}
Exemple #19
0
int main(int argc , char ** argv) {
  const char * case_path = argv[1];
  char * grid_file = ecl_util_alloc_filename( NULL , case_path , ECL_EGRID_FILE , false , 0 );
  char * init_file = ecl_util_alloc_filename( NULL , case_path , ECL_INIT_FILE , false , 0 );
  char * rst_file  = ecl_util_alloc_filename( NULL , case_path , ECL_RESTART_FILE , false , 0 );
  
  ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file );
  ecl_file_type * RST_file = ecl_file_open( rst_file , 0);
  ecl_file_type * INIT_file = ecl_file_open( init_file , 0 );
  ecl_file_type * GRID_file = ecl_file_open( grid_file , 0);

  {
    ecl_kw_type * actnum = ecl_file_iget_named_kw( GRID_file , "ACTNUM" , 0 );
    ecl_kw_type * swat = ecl_file_iget_named_kw( RST_file , "SWAT" , 0 );
    ecl_kw_type * permx = ecl_file_iget_named_kw( INIT_file , "PERMX" , 0 );
    int fracture_size  = ecl_grid_get_nactive_fracture( ecl_grid );
    int matrix_size    = ecl_grid_get_nactive( ecl_grid );

    test_assert_int_equal( fracture_size + matrix_size , ecl_kw_get_size( swat ));
    test_assert_int_equal( fracture_size + matrix_size , ecl_kw_get_size( permx ));

    {
      int gi;
      int matrix_index = 0;
      int fracture_index = 0;

      for (gi = 0; gi < ecl_grid_get_global_size( ecl_grid ); gi++) {
        if (ecl_kw_iget_int( actnum , gi ) & CELL_ACTIVE_MATRIX) {
          test_assert_int_equal( ecl_grid_get_active_index1( ecl_grid , gi ) , matrix_index);
          test_assert_int_equal( ecl_grid_get_global_index1A( ecl_grid , matrix_index ) , gi);
          matrix_index++;
        }

        if (ecl_kw_iget_int( actnum , gi ) & CELL_ACTIVE_FRACTURE) {
          test_assert_int_equal( ecl_grid_get_active_fracture_index1( ecl_grid , gi ) , fracture_index);
          test_assert_int_equal( ecl_grid_get_global_index1F( ecl_grid , fracture_index ) , gi);
          fracture_index++;
        }
      }
    }
  }
  
  
  ecl_file_close( RST_file );
  ecl_file_close( INIT_file );
  ecl_grid_free( ecl_grid );

  exit(0);
}
Exemple #20
0
int main( int argc , char ** argv ) {
  if (argc < 3)
    usage();
  else {
    char * grid_file = argv[1];
    ecl_grid_type * grid = ecl_grid_alloc( grid_file );
    well_info_type * well_info = well_info_alloc( grid );
    int ifile;
    for (ifile = 2; ifile < argc; ifile++) {
      const char * rst_file = argv[ifile];
      printf("Loading restart file: %s \n",rst_file);
      well_info_load_rstfile( well_info , rst_file , true );
    }

    ecl_grid_free( grid );
    well_info_free( well_info );
  }
}
int main(int argc , char ** argv) {
  const char * grid_file = argv[1];
  const char * fault_blk_file = argv[2];
  ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file );
  ecl_kw_type * fault_blk_kw;
  {
    FILE * stream = util_fopen( fault_blk_file , "r");
    fault_blk_kw = ecl_kw_fscanf_alloc_grdecl( stream , "FAULTBLK" , ecl_grid_get_global_size( ecl_grid ) , ECL_INT);
    fclose( stream );
  }

  
  test_create( ecl_grid , fault_blk_kw );

  ecl_grid_free( ecl_grid );
  ecl_kw_free( fault_blk_kw );
  exit(0);
}
Exemple #22
0
int main(int argc, char ** argv) {
  if (argc != 5) {
    fprintf(stderr,"%s: basename nx ny nz \n",argv[0]);
    exit(1);
  }

  {
    const char    * base_input = argv[1];
    int             nx         = atoi(argv[2]);
    int             ny         = atoi(argv[3]);
    int             nz         = atoi(argv[4]);

    char * path , *basename;
    ecl_grid_type * ecl_grid;
    
    util_alloc_file_components( base_input , &path , &basename , NULL );

    ecl_grid = ecl_grid_alloc_rectangular(nx,ny,nz , 1 ,1 ,1 , NULL );
    {
      char * EGRID_file = util_alloc_filename( path , basename , "EGRID");

      printf("Writing file: %s ...",EGRID_file); fflush(stdout);
      ecl_grid_fwrite_EGRID2( ecl_grid , EGRID_file, ERT_ECL_METRIC_UNITS);
      free( EGRID_file );
    }

    {
      char * grdecl_file = util_alloc_filename( path , basename , "grdecl");
      FILE * stream = util_fopen( grdecl_file , "w");
      printf("\nWriting file: %s ...",grdecl_file); fflush(stdout);
      ecl_grid_fprintf_grdecl( ecl_grid , stream );
      fclose( stream );
      free( grdecl_file );
      printf("\n");
    }
    
    free( basename );
    util_safe_free( path );
    ecl_grid_free( ecl_grid );
  }
}
Exemple #23
0
int main(int argc , char ** argv) {
    FILE * stream = util_fopen( argv[1] , "r");
    ecl_kw_type * gridhead_kw = ecl_kw_fscanf_alloc_grdecl_dynamic__( stream , SPECGRID_KW , false , ECL_INT_TYPE );
    ecl_kw_type * zcorn_kw    = ecl_kw_fscanf_alloc_grdecl_dynamic( stream , ZCORN_KW  , ECL_FLOAT_TYPE );
    ecl_kw_type * coord_kw    = ecl_kw_fscanf_alloc_grdecl_dynamic( stream , COORD_KW  , ECL_FLOAT_TYPE );
    ecl_kw_type * actnum_kw   = ecl_kw_fscanf_alloc_grdecl_dynamic( stream , ACTNUM_KW , ECL_INT_TYPE );

    {
        int nx = ecl_kw_iget_int( gridhead_kw , SPECGRID_NX_INDEX );
        int ny = ecl_kw_iget_int( gridhead_kw , SPECGRID_NY_INDEX );
        int nz = ecl_kw_iget_int( gridhead_kw , SPECGRID_NZ_INDEX );
        ecl_grid_type * ecl_grid = ecl_grid_alloc_GRDECL_kw( nx , ny , nz, zcorn_kw, coord_kw , actnum_kw , NULL );
        /* .... */
        ecl_grid_free( ecl_grid );
    }
    ecl_kw_free( gridhead_kw );
    ecl_kw_free( zcorn_kw );
    ecl_kw_free( actnum_kw );
    ecl_kw_free( coord_kw );
    fclose( stream );
}
Exemple #24
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);
}
Exemple #25
0
int main(int argc , char ** argv) {
  const int nx = 5;
  const int ny = 4;
  const int nz = 2;
  const int g  = nx*ny*nz;
  const int nactive = g - 9;
  const int actnum1[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  const int actnum2[] = {0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0};
  ecl_grid_type * grid = ecl_grid_alloc_rectangular(nx , ny , nz , 1 , 1 , 1 , actnum1 );

  
  test_assert_int_equal( g , ecl_grid_get_nactive( grid ));
  ecl_grid_reset_actnum(grid , actnum2 );
  test_assert_int_equal( nactive , ecl_grid_get_nactive( grid ));

  test_assert_int_equal( -1 , ecl_grid_get_active_index1( grid , 0 ));
  test_assert_int_equal(  0 , ecl_grid_get_active_index1( grid , 1 ));
  test_assert_int_equal( -1 , ecl_grid_get_active_index1( grid , 2 ));
  test_assert_int_equal(  1 , ecl_grid_get_global_index1A( grid , 0 ));
  test_assert_int_equal(  3 , ecl_grid_get_global_index1A( grid , 1 ));
  test_assert_int_equal(  5 , ecl_grid_get_global_index1A( grid , 2 ));


  ecl_grid_reset_actnum(grid , NULL );
  test_assert_int_equal( g , ecl_grid_get_nactive( grid ));
  test_assert_int_equal(  0 , ecl_grid_get_active_index1( grid , 0 ));
  test_assert_int_equal(  1 , ecl_grid_get_active_index1( grid , 1 ));
  test_assert_int_equal(  2 , ecl_grid_get_active_index1( grid , 2 ));
  test_assert_int_equal(  0 , ecl_grid_get_global_index1A( grid , 0 ));
  test_assert_int_equal(  1 , ecl_grid_get_global_index1A( grid , 1 ));
  test_assert_int_equal(  2 , ecl_grid_get_global_index1A( grid , 2 ));

  
  
  ecl_grid_free( grid );
  exit(0);
}
Exemple #26
0
void ecl_config_set_grid( ecl_config_type * ecl_config , const char * grid_file ) {
  if (ecl_config->grid != NULL)
    ecl_grid_free( ecl_config->grid );
  ecl_config->grid = ecl_grid_alloc( grid_file );
}
Exemple #27
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigEclipseCaseData* eclipseCase, bool readFaultData)
{
    CVF_ASSERT(eclipseCase);

    std::vector< RifKeywordAndFilePos > keywordsAndFilePos;
    findKeywordsOnFile(fileName, &keywordsAndFilePos);

    qint64 coordPos = -1;
    qint64 zcornPos = -1;
    qint64 specgridPos = -1;
    qint64 actnumPos = -1;
    qint64 mapaxesPos = -1;

    findGridKeywordPositions(keywordsAndFilePos, &coordPos, &zcornPos, &specgridPos, &actnumPos, &mapaxesPos);

    if (coordPos < 0 || zcornPos < 0 || specgridPos < 0)
    {
        QString errorText = QString("Failed to import grid file '%1'\n").arg(fileName);

        if (coordPos < 0)
        {
            errorText += "  Missing required keyword COORD";
        }

        if (zcornPos < 0)
        {
            errorText += "  Missing required keyword ZCORN";
        }

        if (specgridPos < 0)
        {
            errorText += "  Missing required keyword SPECGRID";
        }

        RiaLogging::error(errorText);

        return false;
    }


    FILE* gridFilePointer = util_fopen(fileName.toLatin1().data(), "r");
    if (!gridFilePointer) return false;

    // Main grid dimensions
    // SPECGRID - This is whats normally available, but not really the input to Eclipse.
    // DIMENS - Is what Eclipse expects and uses, but is not defined in the GRID section and is not (?) available normally
    // ZCORN, COORD, ACTNUM, MAPAXES

    //ecl_kw_type  *  ecl_kw_fscanf_alloc_grdecl_dynamic__( FILE * stream , const char * kw , bool strict , ecl_type_enum ecl_type);
    //ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw ); 



    ecl_kw_type* specGridKw  = nullptr;
    ecl_kw_type* zCornKw     = nullptr;
    ecl_kw_type* coordKw     = nullptr;
    ecl_kw_type* actNumKw    = nullptr;
    ecl_kw_type* mapAxesKw   = nullptr;

    // Try to read all the needed keywords. Early exit if some are not found
    caf::ProgressInfo progress(8, "Read Grid from Eclipse Input file");



    bool allKwReadOk = true;

    fseek(gridFilePointer, specgridPos, SEEK_SET);
    allKwReadOk = allKwReadOk && nullptr != (specGridKw = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ecl_type_create_from_type(ECL_INT_TYPE)));
    progress.setProgress(1);

    fseek(gridFilePointer, zcornPos, SEEK_SET);
    allKwReadOk = allKwReadOk && nullptr != (zCornKw    = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ecl_type_create_from_type(ECL_FLOAT_TYPE)));
    progress.setProgress(2);

    fseek(gridFilePointer, coordPos, SEEK_SET);
    allKwReadOk = allKwReadOk && nullptr != (coordKw    = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ecl_type_create_from_type(ECL_FLOAT_TYPE)));
    progress.setProgress(3);

    // If ACTNUM is not defined, this pointer will be NULL, which is a valid condition
    if (actnumPos >= 0)
    {
        fseek(gridFilePointer, actnumPos, SEEK_SET);
        allKwReadOk = allKwReadOk && nullptr != (actNumKw   = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ecl_type_create_from_type(ECL_INT_TYPE)));
        progress.setProgress(4);
    }

    // If MAPAXES is not defined, this pointer will be NULL, which is a valid condition
    if (mapaxesPos >= 0)
    {
        fseek(gridFilePointer, mapaxesPos, SEEK_SET);
        mapAxesKw = ecl_kw_fscanf_alloc_current_grdecl__( gridFilePointer, false , ecl_type_create_from_type(ECL_FLOAT_TYPE));
    }

    if (!allKwReadOk)
    {
        if(specGridKw) ecl_kw_free(specGridKw);
        if(zCornKw) ecl_kw_free(zCornKw);
        if(coordKw) ecl_kw_free(coordKw);
        if(actNumKw) ecl_kw_free(actNumKw);
        if(mapAxesKw) ecl_kw_free(mapAxesKw);

        return false;
    }

    progress.setProgress(5);

    int nx = ecl_kw_iget_int(specGridKw, 0); 
    int ny = ecl_kw_iget_int(specGridKw, 1); 
    int nz = ecl_kw_iget_int(specGridKw, 2);

    ecl_grid_type* inputGrid = ecl_grid_alloc_GRDECL_kw( nx, ny, nz, zCornKw, coordKw, actNumKw, mapAxesKw ); 

    progress.setProgress(6);

    RifReaderEclipseOutput::transferGeometry(inputGrid, eclipseCase);

    progress.setProgress(7);
    progress.setProgressDescription("Read faults ...");

    if (readFaultData)
    {
        cvf::Collection<RigFault> faults;
        RifEclipseInputFileTools::readFaults(fileName, keywordsAndFilePos, &faults);

        RigMainGrid* mainGrid = eclipseCase->mainGrid();
        mainGrid->setFaults(faults);
    }
    
    progress.setProgress(8);
    progress.setProgressDescription("Cleaning up ...");

    ecl_kw_free(specGridKw);
    ecl_kw_free(zCornKw);
    ecl_kw_free(coordKw);
    if (actNumKw) ecl_kw_free(actNumKw);
    if (mapAxesKw) ecl_kw_free(mapAxesKw);

    ecl_grid_free(inputGrid);

    util_fclose(gridFilePointer);
    
    return true;
}
ECLFilesComparator::~ECLFilesComparator() {
    ecl_file_close(ecl_file1);
    ecl_file_close(ecl_file2);
    ecl_grid_free(ecl_grid1);
    ecl_grid_free(ecl_grid2);
}
Exemple #29
0
void test_copy_grid( const ecl_grid_type * grid ) {
  ecl_grid_type * grid_copy = ecl_grid_alloc_copy( grid );
  test_assert_true( ecl_grid_compare( grid , grid_copy , true , true ,  true ));
  ecl_grid_free( grid_copy );
}
Exemple #30
0
void test_grid(int nx, int ny, int nz) {
  ecl_kw_type * coord_kw = ecl_kw_alloc( COORD_KW , ECL_GRID_COORD_SIZE( nx , ny ) , ECL_FLOAT );
  ecl_kw_type * zcorn_kw = ecl_kw_alloc( ZCORN_KW , ECL_GRID_ZCORN_SIZE( nx , ny , nz) , ECL_FLOAT );
  int i,j,k;
  double a = 1.0;
  for (j= 0; j < ny; j++) {
    for (i = 0; i < nx; i++) {
      int offset = 6*(i + j*nx);
      ecl_kw_iset_float( coord_kw , offset    , a*i);
      ecl_kw_iset_float( coord_kw , offset + 1, a*j);
      ecl_kw_iset_float( coord_kw , offset + 2,  -1);

      ecl_kw_iset_float( coord_kw , offset + 3, a*i);
      ecl_kw_iset_float( coord_kw , offset + 4, a*j);
      ecl_kw_iset_float( coord_kw , offset + 5,  -1);

      for (k=0; k < nz; k++) {
        for (int c = 0; c < 4; c++) {
          int zi1 = ecl_grid_zcorn_index__( nx , ny , i , j , k , c);
          int zi2 = ecl_grid_zcorn_index__( nx , ny , i , j , k , c + 4);

          double z1 = k*a;
          double z2 = (k + 1) * a;

          ecl_kw_iset_float( zcorn_kw , zi1 , z1 );
          ecl_kw_iset_float( zcorn_kw , zi2 , z2 );
        }
      }
    }
  }


  {
    ecl_grid_type * grid = ecl_grid_alloc_GRDECL_kw( nx,ny,nz, zcorn_kw , coord_kw ,  NULL, NULL );
    test_assert_int_equal( ecl_grid_get_cell_twist3( grid , 0,0,0) , 0 );
    ecl_grid_free( grid );
  }


  {
    int zi1 = ecl_grid_zcorn_index__( nx , ny , 0 , 0 , 0 , 0);
    int zi2 = ecl_grid_zcorn_index__( nx , ny , 0 , 0 , 0 , 4);

    double z1 = 0;
    double z2 = -0.25;

    ecl_kw_iset_float( zcorn_kw , zi1 , z1 );
    ecl_kw_iset_float( zcorn_kw , zi2 , z2 );

    {
      ecl_grid_type * grid = ecl_grid_alloc_GRDECL_kw( nx,ny,nz, zcorn_kw , coord_kw ,  NULL, NULL );
      test_assert_int_equal( ecl_grid_get_cell_twist3( grid , 0,0,0) , 1 );
      ecl_grid_free( grid );
    }

    zi1 = ecl_grid_zcorn_index__( nx , ny , 0 , 0 , 0 , 3);
    zi2 = ecl_grid_zcorn_index__( nx , ny , 0 , 0 , 0 , 7);

    ecl_kw_iset_float( zcorn_kw , zi1 , z1 );
    ecl_kw_iset_float( zcorn_kw , zi2 , z2 );

    {
      ecl_grid_type * grid = ecl_grid_alloc_GRDECL_kw( nx,ny,nz, zcorn_kw , coord_kw ,  NULL, NULL );
      test_assert_int_equal( ecl_grid_get_cell_twist3( grid , 0,0,0) , 2 );
      ecl_grid_free( grid );
    }
  }


  ecl_kw_free( coord_kw );
  ecl_kw_free( zcorn_kw );
}