Exemplo n.º 1
0
static void ecl_grid_dims_read_GRID( ecl_grid_dims_type * grid_dims , fortio_type * grid_fortio , fortio_type * data_fortio ) {
  while (ecl_kw_fseek_kw( DIMENS_KW , false , false , grid_fortio)) {
    grid_dims_type * dims;
    {
      ecl_kw_type * dimens_kw = ecl_kw_fread_alloc( grid_fortio );
    
      int nx = ecl_kw_iget_int( dimens_kw , DIMENS_NX_INDEX );
      int ny = ecl_kw_iget_int( dimens_kw , DIMENS_NY_INDEX );
      int nz = ecl_kw_iget_int( dimens_kw , DIMENS_NZ_INDEX );
      
      dims = grid_dims_alloc( nx , ny , nz , 0 );
      ecl_kw_free( dimens_kw );
    }

    if (data_fortio) {
      if (ecl_kw_fseek_kw( INTEHEAD_KW , false , false , data_fortio )) {
        ecl_kw_type * intehead_kw = ecl_kw_fread_alloc( data_fortio );
        dims->nactive = ecl_kw_iget_int( intehead_kw , INTEHEAD_NACTIVE_INDEX );
        ecl_kw_free( intehead_kw );
      }
    }
    
    vector_append_owned_ref( grid_dims->dims_list , dims, grid_dims_free__ );
  } 
}
Exemplo n.º 2
0
void ecl_init_file_fwrite_header( fortio_type * fortio , const ecl_grid_type * ecl_grid , const ecl_kw_type * poro , int phases , time_t start_date) {
  int simulator = INTEHEAD_ECLIPSE100_VALUE;
  {
    ecl_kw_type * intehead_kw = ecl_init_file_alloc_INTEHEAD( ecl_grid , phases , start_date , simulator );
    ecl_kw_fwrite( intehead_kw , fortio );
    ecl_kw_free( intehead_kw );
  }

  {
    ecl_kw_type * logihead_kw = ecl_init_file_alloc_LOGIHEAD( simulator );
    ecl_kw_fwrite( logihead_kw , fortio );
    ecl_kw_free( logihead_kw );
  }

  {
    ecl_kw_type * doubhead_kw = ecl_init_file_alloc_DOUBHEAD( );
    ecl_kw_fwrite( doubhead_kw , fortio );
    ecl_kw_free( doubhead_kw );
  }

  if (poro) {
    int poro_size = ecl_kw_get_size( poro );
    if ((poro_size == ecl_grid_get_nactive( ecl_grid )) || (poro_size == ecl_grid_get_global_size(ecl_grid)))
      ecl_init_file_fwrite_poro( fortio , ecl_grid , poro );
    else
      util_abort("%s: keyword PORO has wrong size:%d  Grid: %d/%d \n",__func__  , ecl_kw_get_size( poro ) , ecl_grid_get_nactive( ecl_grid ) , ecl_grid_get_global_size( ecl_grid ));
  }
}
Exemplo n.º 3
0
void test_export( const ecl_grid_type * grid) {
  fault_block_layer_type * layer = fault_block_layer_alloc( grid , 0 );
  ecl_kw_type * ecl_kw1 = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid )     , ECL_INT_TYPE );
  ecl_kw_type * ecl_kw2 = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid ) + 1 , ECL_INT_TYPE );
  ecl_kw_type * ecl_kw3 = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid )     , ECL_FLOAT_TYPE );
  fault_block_type * block = fault_block_layer_add_block( layer , 10 );
  
  fault_block_add_cell( block , 0 , 0 );
  fault_block_add_cell( block , 1 , 0 );
  fault_block_add_cell( block , 1 , 1 );
  fault_block_add_cell( block , 0 , 1 );


  test_assert_true( fault_block_layer_export( layer , ecl_kw1 ));
  test_assert_false( fault_block_layer_export( layer , ecl_kw2 ));
  test_assert_false( fault_block_layer_export( layer , ecl_kw3 ));

  {
    int nx = ecl_grid_get_nx( grid );
   
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , 0 ) , 10 );
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , 1 ) , 10 );
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , nx ) , 10 );
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , nx + 1 ) , 10 );
  }
  test_assert_int_equal( 40 , ecl_kw_element_sum_int( ecl_kw1 ));

  fault_block_layer_free( layer );
  ecl_kw_free( ecl_kw1 );
  ecl_kw_free( ecl_kw2 );
  ecl_kw_free( ecl_kw3 );
}
Exemplo n.º 4
0
void test_fread_alloc() {
  test_work_area_type * work_area = test_work_area_alloc("ecl_kw_fread" );
  {
    ecl_kw_type * kw1 = ecl_kw_alloc( "INT" , 100 , ECL_INT );
    int i;
    for (i=0; i < 100; i++)
      ecl_kw_iset_int( kw1 , i , i );
    {
      fortio_type * fortio = fortio_open_writer("INT" , false , true );
      ecl_kw_fwrite( kw1 , fortio );
      fortio_fclose( fortio );
    }
    {
      fortio_type * fortio = fortio_open_reader("INT" , false , true );
      ecl_kw_type * kw2 = ecl_kw_fread_alloc( fortio );
      test_assert_true( ecl_kw_is_instance( kw2 ));
      test_assert_true( ecl_kw_equal( kw1 , kw2 ));
      ecl_kw_free( kw2 );
      fortio_fclose( fortio );
    }

    {
      offset_type file_size = util_file_size("INT");
      test_truncated("INT" , file_size - 4 );
      test_truncated("INT" , file_size - 25 );
      test_truncated("INT" , 5 );
      test_truncated("INT" , 0 );
    }
    ecl_kw_free( kw1 );
  }
  test_work_area_free( work_area );
}
Exemplo n.º 5
0
void test_write_header() {
    int nx = 10;
    int ny = 10;
    int nz = 5;

    int_vector_type * actnum = int_vector_alloc( nx*ny*nz , 1 );
    test_work_area_type * test_area = test_work_area_alloc( "ecl_init_file" );
    time_t start_time = util_make_date(15 , 12 , 2010 );
    ecl_grid_type * ecl_grid;

    int_vector_iset( actnum , 10 , 0 );
    int_vector_iset( actnum , 100 , 0 );

    ecl_grid = ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, int_vector_get_ptr( actnum ));

    // Write poro with global size.
    {
        fortio_type * f = fortio_open_writer( "FOO1.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }


    // Write poro with nactive size.
    {
        fortio_type * f = fortio_open_writer( "FOO2.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }
    {
        ecl_file_type * file1 = ecl_file_open( "FOO1.INIT" , 0 );
        ecl_file_type * file2 = ecl_file_open( "FOO2.INIT" , 0 );

        test_assert_true( ecl_kw_equal( ecl_file_iget_named_kw( file1 , "PORV" , 0 ) ,
                                        ecl_file_iget_named_kw( file2 , "PORV" , 0)));

        ecl_file_close( file2 );
        ecl_file_close( file1 );
    }


    // Poro == NULL
    {
        fortio_type * f = fortio_open_writer( "FOO3.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_init_file_fwrite_header( f , ecl_grid , NULL , 7 , start_time );
        fortio_fclose( f );
    }
    test_work_area_free( test_area );
}
Exemplo n.º 6
0
void test_create_invalid( const ecl_grid_type * grid ) {
  ecl_kw_type * fault_blk_kw = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid ) - 1, ECL_INT_TYPE );
  
  test_assert_NULL( fault_block_layer_alloc( grid , 7 ));
  
  ecl_kw_free( fault_blk_kw );
}
Exemplo n.º 7
0
void ecl_file_kw_end_transaction(ecl_file_kw_type * file_kw, int ref_count) {
  if (ref_count == 0 && file_kw->ref_count > 0) {
    ecl_kw_free(file_kw->kw);
    file_kw->kw = NULL;
  }
  file_kw->ref_count = ref_count;
}
Exemplo n.º 8
0
static void ecl_file_kw_drop_kw( ecl_file_kw_type * file_kw , inv_map_type * inv_map ) {
  if (file_kw->kw != NULL) {
    inv_map_drop_kw( inv_map , file_kw->kw );
    ecl_kw_free( file_kw->kw );
    file_kw->kw = NULL;
  }
}
Exemplo n.º 9
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 );
}
Exemplo n.º 10
0
int main(int argc , char ** argv) {  
  int i;
  ecl_kw_type * ecl_kw = ecl_kw_alloc("HEAD" , 10  , ECL_INT_TYPE);

  for (i=0; i < 10; i++) 
    ecl_kw_iset_int(ecl_kw , i , i );

  {
    test_work_area_type * work_area = test_work_area_alloc("ecl_kw_grdecl" , true);
    FILE * stream = util_fopen( "FILE.grdecl" , "w");

    ecl_kw_fprintf_grdecl(ecl_kw , stream );
    fclose(stream);
    
    stream = util_fopen( "FILE.grdecl" , "r");
    {
      ecl_kw_type * ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD" , 10 , ECL_INT_TYPE);
      
      test_assert_not_NULL( ecl_kw2 );
      test_assert_true( ecl_kw_equal( ecl_kw , ecl_kw2));
      ecl_kw_free( ecl_kw2 );
    }
    fclose( stream );

    stream = util_fopen( "FILE.grdecl" , "w");
    ecl_kw_fprintf_grdecl__(ecl_kw , "HEAD1234" , stream );
    fclose( stream );

    stream = util_fopen( "FILE.grdecl" , "r");
    {
      ecl_kw_type * ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD" , 10 , ECL_INT_TYPE);
      
      test_assert_NULL( ecl_kw2 );
      ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD1234" , 10 , ECL_INT_TYPE);
      test_assert_not_NULL( ecl_kw2 );
      
      test_assert_string_equal( ecl_kw_get_header( ecl_kw2 ) , "HEAD1234" );
      test_assert_true( ecl_kw_content_equal( ecl_kw , ecl_kw2 ));
      ecl_kw_free( ecl_kw2 );
    }
    fclose( stream );
    test_work_area_free( work_area );
  }
  ecl_kw_free( ecl_kw );
  
  exit(0);
}
Exemplo n.º 11
0
int test_grdecl_loader() {
  FILE * stream = util_fopen("/private/joaho/ERT/NR/python/ctypes/test/data/eclipse/case/PERMX.grdecl" , "r");
  ecl_kw_type * kw = ecl_kw_fscanf_alloc_grdecl_dynamic( stream , "PERMX" , ECL_FLOAT_TYPE );
  ecl_kw_free( kw );
  fclose( stream );
  
  return 1;
}
Exemplo n.º 12
0
bool check_original_exported_data_equal(const enkf_node_type * field_node) {
  FILE * original_stream = util_fopen( "petro.grdecl" , "r");
  ecl_kw_type * kw_original = ecl_kw_fscanf_alloc_grdecl_dynamic( original_stream , "PORO" , ECL_DOUBLE_TYPE );

  enkf_node_ecl_write(field_node, "tmp", NULL, 0); 
  FILE * exported_stream = util_fopen( "tmp/PORO.grdecl" , "r");
  ecl_kw_type * kw_exported = ecl_kw_fscanf_alloc_grdecl_dynamic( exported_stream , "PORO" , ECL_DOUBLE_TYPE );

  bool ret = ecl_kw_numeric_equal(kw_original, kw_exported, 1e-5);

  util_fclose(original_stream); 
  util_fclose(exported_stream); 
  ecl_kw_free(kw_original); 
  ecl_kw_free(kw_exported); 
  
  return ret; 
}
Exemplo n.º 13
0
void test_kw_io_charlength() {
  test_work_area_type * work_area = test_work_area_alloc("ecl_kw_io_charlength");
  { 
    const char * KW0 = "QWERTYUI";
    const char * KW1 = "ABCDEFGHIJTTTTTTTTTTTTTTTTTTTTTTABCDEFGHIJKLMNOP";
    ecl_kw_type * ecl_kw_out0 = ecl_kw_alloc(KW0 , 5, ECL_FLOAT);
    ecl_kw_type * ecl_kw_out1 = ecl_kw_alloc(KW1 , 5, ECL_FLOAT);
    for (int i=0; i < ecl_kw_get_size( ecl_kw_out1); i++) {
       ecl_kw_iset_float( ecl_kw_out0 , i , i*1.5 );
       ecl_kw_iset_float( ecl_kw_out1 , i , i*1.5 );
    }

    {
       fortio_type * f = fortio_open_writer( "TEST1" , false, ECL_ENDIAN_FLIP );
       test_assert_true( ecl_kw_fwrite( ecl_kw_out0, f ));
       test_assert_false(ecl_kw_fwrite( ecl_kw_out1, f ));
       fortio_fclose( f );
    }

    {
       test_assert_false( util_file_exists( "TEST1"));
    }
   
    {
       FILE * file = util_fopen("TEST2", "w");
       ecl_kw_fprintf_grdecl(ecl_kw_out1 , file);
       fclose(file);
    }
    
    {
       FILE * file = util_fopen("TEST2", "r");
       ecl_kw_type * ecl_kw_in = ecl_kw_fscanf_alloc_grdecl( file , KW1 , -1 , ECL_FLOAT);
       test_assert_string_equal(KW1, ecl_kw_get_header(ecl_kw_in) );
       test_assert_int_equal(5, ecl_kw_get_size( ecl_kw_in) );

       test_assert_double_equal(ecl_kw_iget_as_double(ecl_kw_in, 0), 0.0);
       test_assert_double_equal(ecl_kw_iget_as_double(ecl_kw_in, 4), 6.0);

       fclose(file);
    }
    
    ecl_kw_free( ecl_kw_out0 );
    ecl_kw_free( ecl_kw_out1 );
  }
  test_work_area_free( work_area );
}
Exemplo n.º 14
0
void ecl_file_kw_free( ecl_file_kw_type * file_kw ) {
  if (file_kw->kw != NULL) {
    ecl_kw_free( file_kw->kw );
    file_kw->kw = NULL;
  }
  free( file_kw->header );
  free( file_kw );
}
Exemplo n.º 15
0
void test_float() {
  size_t N = 1000;
  int i;
  ecl_kw_type * kw = ecl_kw_alloc("KW" , N , ECL_FLOAT_TYPE);
  for (i=0; i < N; i++)
    test_assert_int_equal( 0 , ecl_kw_iget_float( kw , i ));

  ecl_kw_free( kw );
}
Exemplo n.º 16
0
void test_double() {
  size_t N = 1000;
  double i;
  ecl_kw_type * kw = ecl_kw_alloc("KW" , N , ECL_DOUBLE_TYPE);
  for (i=0; i < N; i++)
    test_assert_double_equal( 0 , ecl_kw_iget_double( kw , i ));

  ecl_kw_free( kw );
}
Exemplo n.º 17
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 );
}
Exemplo n.º 18
0
void ecl_file_kw_replace_kw( ecl_file_kw_type * file_kw , fortio_type * target , ecl_kw_type * new_kw ) {
  if ((file_kw->ecl_type == ecl_kw_get_type( new_kw )) && 
      (file_kw->kw_size == ecl_kw_get_size( new_kw ))) {
    
    if (file_kw->kw != NULL)
      ecl_kw_free( file_kw->kw );

    file_kw->kw = new_kw;
    fortio_fseek( target , file_kw->file_offset , SEEK_SET );
    ecl_kw_fwrite( file_kw->kw , target );
    
  } else
    util_abort("%s: sorry size/type mismatch between in-file keyword and new keyword \n",__func__);
}
Exemplo n.º 19
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);
}
Exemplo n.º 20
0
void ecl_sum_tstep_fwrite( const ecl_sum_tstep_type * ministep , const int_vector_type * index_map , fortio_type * fortio) {
  {
    ecl_kw_type * ministep_kw = ecl_kw_alloc( MINISTEP_KW , 1 , ECL_INT_TYPE );
    ecl_kw_iset_int( ministep_kw , 0 , ministep->ministep );
    ecl_kw_fwrite( ministep_kw , fortio );
    ecl_kw_free( ministep_kw );
  }

  {
    int compact_size = int_vector_size( index_map );
    ecl_kw_type * params_kw = ecl_kw_alloc( PARAMS_KW , compact_size , ECL_FLOAT_TYPE );

    const int * index = int_vector_get_ptr( index_map );
    float * data      = ecl_kw_get_ptr( params_kw );

    {
      int i;
      for (i=0; i < compact_size; i++)
        data[i] = ministep->data[ index[i] ];
    }
    ecl_kw_fwrite( params_kw , fortio );
    ecl_kw_free( params_kw );
  }
}
Exemplo n.º 21
0
void kw_list(const char *filename) {
  fortio_type *fortio;
  bool fmt_file = ecl_util_fmt_file(filename);
  ecl_kw_type * ecl_kw = ecl_kw_alloc_empty();

  printf("-----------------------------------------------------------------\n");
  printf("%s: \n",filename); 
  fortio = fortio_open_reader(filename , fmt_file , ECL_ENDIAN_FLIP);  
  while(  ecl_kw_fread_realloc(ecl_kw , fortio) ) 
    ecl_kw_summarize(ecl_kw);
  printf("-----------------------------------------------------------------\n");

  ecl_kw_free(ecl_kw);
  fortio_fclose(fortio);
}
Exemplo n.º 22
0
void ecl_file_kw_replace_kw( ecl_file_kw_type * file_kw , fortio_type * target , ecl_kw_type * new_kw ) {
  if (!ecl_type_is_equal(
              ecl_file_kw_get_data_type(file_kw),
              ecl_kw_get_data_type(new_kw)
              ))
    util_abort("%s: sorry type mismatch between in-file keyword and new keyword \n",__func__);
  if(file_kw->kw_size != ecl_kw_get_size(new_kw))
    util_abort("%s: sorry size mismatch between in-file keyword and new keyword \n",__func__);

  if (file_kw->kw != NULL)
    ecl_kw_free( file_kw->kw );

  file_kw->kw = new_kw;
  fortio_fseek( target , file_kw->file_offset , SEEK_SET );
  ecl_kw_fwrite( file_kw->kw , target );
}
Exemplo n.º 23
0
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);
}
Exemplo n.º 24
0
static void ecl_sum_data_fwrite_report__( const ecl_sum_data_type * data , int report_step , fortio_type * fortio) {
  {
    ecl_kw_type * seqhdr_kw = ecl_kw_alloc( SEQHDR_KW , SEQHDR_SIZE , ECL_INT_TYPE );
    ecl_kw_iset_int( seqhdr_kw , 0 , 0 );
    ecl_kw_fwrite( seqhdr_kw , fortio );
    ecl_kw_free( seqhdr_kw );
  }

  {
    int index , index1 , index2;
    
    ecl_sum_data_report2internal_range( data , report_step , &index1 , &index2);
    for (index = index1; index <= index2; index++) {
      const ecl_sum_tstep_type * tstep = ecl_sum_data_iget_ministep( data , index );
      ecl_sum_tstep_fwrite( tstep , ecl_smspec_get_index_map( data->smspec ) , fortio );
    }
  }
}
Exemplo n.º 25
0
//--------------------------------------------------------------------------------------------------
/// Read known properties from the input file
//--------------------------------------------------------------------------------------------------
std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QString& fileName, RigEclipseCaseData* caseData)
{
    CVF_ASSERT(caseData);

    caf::ProgressInfo mainProgress(2, "Reading Eclipse Input properties");

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

    mainProgress.setProgress(1);
    caf::ProgressInfo progress(fileKeywords.size(), "Reading properties");

    FILE* gridFilePointer = util_fopen(fileName.toLatin1().data(), "r");

    if (!gridFilePointer || !fileKeywords.size() ) 
    {
        return std::map<QString, QString>();
    }

    std::map<QString, QString> newResults;
    for (size_t i = 0; i < fileKeywords.size(); ++i)
    {
        if (!isValidDataKeyword(fileKeywords[i].keyword)) continue;

        fseek(gridFilePointer, fileKeywords[i].filePos, SEEK_SET);

        ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false, ecl_type_create_from_type(ECL_FLOAT_TYPE));
        if (eclipseKeywordData)
        {
            QString newResultName = caseData->results(RiaDefines::MATRIX_MODEL)->makeResultNameUnique(fileKeywords[i].keyword);
            if (readDataFromKeyword(eclipseKeywordData, caseData, newResultName))
            {
                newResults[newResultName] = fileKeywords[i].keyword;
            }

            ecl_kw_free(eclipseKeywordData);
        }

        progress.setProgress(i);
    }

    util_fclose(gridFilePointer);
    return newResults;
}
Exemplo n.º 26
0
void checkEgridFile()
{
    size_t numCells = ourFineGridManagerPtr->c_grid()->number_of_cells;

    // use ERT directly to inspect the EGRID file produced by EclipseWriter
    auto egridFile = fortio_open_reader("FOO.EGRID", /*isFormated=*/0, ECL_ENDIAN_FLIP);

    auto eclGrid = eclipseState->getEclipseGrid();

    ecl_kw_type *eclKeyword;
    // yes, that's an assignment!
    while ((eclKeyword = ecl_kw_fread_alloc(egridFile))) {
        std::string keywordName(ecl_kw_get_header(eclKeyword));
        if (keywordName == "COORD") {
            std::vector<double> sourceData, resultData;
            eclGrid->exportCOORD(sourceData);
            getErtData(eclKeyword, resultData);
            compareErtData(sourceData, resultData, /*percentTolerance=*/1e-6);
        }
        else if (keywordName == "ZCORN") {
            std::vector<double> sourceData, resultData;
            eclGrid->exportZCORN(sourceData);
            getErtData(eclKeyword, resultData);
            compareErtData(sourceData, resultData, /*percentTolerance=*/1e-6);
        }
        else if (keywordName == "ACTNUM") {
            std::vector<int> sourceData, resultData;
            eclGrid->exportACTNUM(sourceData);
            getErtData(eclKeyword, resultData);

            if (resultData.size() == numCells && sourceData.size() == 0) {
                sourceData.resize(numCells);
                std::fill(sourceData.begin(), sourceData.end(), 1);
            }

            compareErtData(sourceData, resultData);
        }

        ecl_kw_free(eclKeyword);
    }

    fortio_fclose(egridFile);
}
Exemplo n.º 27
0
static void ecl_init_file_fwrite_poro( fortio_type * fortio , const ecl_grid_type * ecl_grid , const ecl_kw_type * poro ) {
  {
    ecl_kw_type * porv = ecl_kw_alloc( PORV_KW , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE);
    int global_index;
    bool global_poro = (ecl_kw_get_size( poro ) == ecl_grid_get_global_size( ecl_grid )) ? true : false;
    for ( global_index = 0; global_index < ecl_grid_get_global_size( ecl_grid ); global_index++) {
      int active_index = ecl_grid_get_active_index1( ecl_grid , global_index );
      if (active_index >= 0) {
        int poro_index = global_poro ? global_index : active_index;
        ecl_kw_iset_float( porv , global_index , ecl_kw_iget_float( poro , poro_index ) * ecl_grid_get_cell_volume1( ecl_grid , global_index ));
      } else
        ecl_kw_iset_float( porv , global_index , 0 );
    }
    ecl_kw_fwrite( porv , fortio );
    ecl_kw_free( porv );
  }

  ecl_kw_fwrite( poro , fortio );
}
Exemplo n.º 28
0
int main(int argc, char ** argv) {
  if (argc < 4) {
    fprintf(stderr,"%s  src_file target_file kw1 kw2 kw3 \n",argv[0]);
    exit(0);
  }
  {
    const char *  src_file   = argv[1];
    const char * target_file = argv[2];
    const char ** kw_list    = (const char **) &argv[3];
    int num_kw               = argc - 3;
    fortio_type * fortio_src;
    fortio_type * fortio_target;
    bool fmt_src , fmt_target;
    set_type    * kw_set = set_alloc( num_kw , kw_list );
    
    if (!ecl_util_fmt_file(src_file, &fmt_src))
      util_exit("Hmm - could not determine formatted/unformatted status for:%s \n",src_file);
    
    fmt_target        = fmt_src;                         /* Can in principle be different */
    fortio_src        = fortio_open_reader(src_file     , fmt_src , ECL_ENDIAN_FLIP);
    fortio_target     = fortio_open_writer(target_file , fmt_target , ECL_ENDIAN_FLIP);

    {
      ecl_kw_type * ecl_kw = ecl_kw_alloc_empty();
      while (true) {
        if (ecl_kw_fread_header( ecl_kw , fortio_src )) {
          const char * header = ecl_kw_get_header( ecl_kw ); 
          if (set_has_key( kw_set , header )) {
            ecl_kw_fread_realloc_data(ecl_kw , fortio_src );
            ecl_kw_fwrite( ecl_kw , fortio_target );
          } else
            ecl_kw_fskip_data( ecl_kw , fortio_src );
        } else 
          break; /* We have reached EOF */
      }
      ecl_kw_free( ecl_kw );
    }
    
    fortio_fclose(fortio_src);
    fortio_fclose(fortio_target);
    set_free( kw_set );
  }
}
Exemplo n.º 29
0
//--------------------------------------------------------------------------------------------------
/// Reads the property data requested into the \a reservoir, overwriting any previous 
/// properties with the same name.
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigEclipseCaseData* caseData, const QString& eclipseKeyWord, const QString& resultName)
{
    CVF_ASSERT(caseData);

    if (!isValidDataKeyword(eclipseKeyWord)) return false;

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

    ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_grdecl_dynamic__(filePointer, eclipseKeyWord.toLatin1().data(), false, ecl_type_create_from_type(ECL_FLOAT_TYPE));
    bool isOk = false;
    if (eclipseKeywordData)
    {
        isOk = readDataFromKeyword(eclipseKeywordData, caseData, resultName);

        ecl_kw_free(eclipseKeywordData);
    }

    util_fclose(filePointer);

    return isOk;
}
Exemplo n.º 30
0
void test_neighbours( const ecl_grid_type * grid) {
  const int k = 0;
  fault_block_layer_type * layer = fault_block_layer_alloc( grid , k );
  geo_polygon_collection_type * polylines = geo_polygon_collection_alloc();
  ecl_kw_type * ecl_kw = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid )     , ECL_INT_TYPE );

  ecl_kw_iset_int( ecl_kw , 0 , 1);
  ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 3,3,k) , 2);
  ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 4,3,k) , 3);
  ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 5,3,k) , 4);
  ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 4,2,k) , 5);
  fault_block_layer_load_kw( layer , ecl_kw);
  
  {
    int_vector_type * neighbours = int_vector_alloc( 0,0);
    {
      fault_block_type * block = fault_block_layer_get_block( layer , 1 );

      test_assert_int_equal( 0 , int_vector_size( neighbours ));
      fault_block_list_neighbours( block , false , polylines , neighbours );
      test_assert_int_equal( 0 , int_vector_size( neighbours ));
    }

    {
      fault_block_type * block = fault_block_layer_get_block( layer , 2 );

      fault_block_list_neighbours( block , false , polylines , neighbours );
      test_assert_int_equal( 1 , int_vector_size( neighbours ));
      test_assert_true( int_vector_contains( neighbours , 3 ));
    }
    int_vector_free( neighbours );
    

  }
  
  geo_polygon_collection_free( polylines );
  fault_block_layer_free( layer );  
  ecl_kw_free( ecl_kw );
}