Example #1
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 );
}
Example #2
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 );
}
Example #3
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 );
}
Example #4
0
static ecl_kw_type * ecl_init_file_alloc_DOUBHEAD( ) {
  ecl_kw_type * doubhead_kw = ecl_kw_alloc( DOUBHEAD_KW , DOUBHEAD_INIT_SIZE , ECL_DOUBLE_TYPE );

  ecl_kw_scalar_set_double( doubhead_kw , 0);

  return doubhead_kw;
}
Example #5
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 );
}
Example #6
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 );
}
Example #7
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 );
}
Example #8
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 );
}
Example #9
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 );
}
Example #10
0
void test_exception_assing_ref_wrong_type() {
    auto* ptr = ecl_kw_alloc( "XYZ", 1, ECL_INT );

    try {
        ERT::EclKW< double > kw( ptr );
        test_assert_true( false );
    } catch (...) {
        ERT::EclKW< int > kw( ptr );
    }
}
Example #11
0
static ecl_kw_type * ecl_init_file_alloc_LOGIHEAD( int simulator ) {
  /*
    This function includes lots of hardcoded options; the main
    intention of writing the INIT file is to store the grid properties
    like e.g. PORO and SATNUM. The relperm/thermodynamics properties
    are just all defaulted to False.

    The documentation
  */
  bool with_RS                            = false;
  bool with_RV                            = false;
  bool with_directional_relperm           = false;
  bool with_reversible_relperm_ECLIPSE100 = false;
  bool radial_grid_ECLIPSE100             = false;
  bool radial_grid_ECLIPSE300             = false;
  bool with_reversible_relperm_ECLIPSE300 = false;
  bool with_hysterisis                    = false;
  bool dual_porosity                      = false;
  bool endpoint_scaling                   = false;
  bool directional_endpoint_scaling       = false;
  bool reversible_endpoint_scaling        = false;
  bool alternative_endpoint_scaling       = false;
  bool miscible_displacement              = false;
  bool scale_water_PC_at_max_sat          = false;
  bool scale_gas_PC_at_max_sat            = false;


  ecl_kw_type * logihead_kw = ecl_kw_alloc( LOGIHEAD_KW , LOGIHEAD_INIT_SIZE , ECL_BOOL_TYPE );

  ecl_kw_scalar_set_bool( logihead_kw , false );

  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_RS_INDEX                        , with_RS);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_RV_INDEX                        , with_RV);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_DIR_RELPERM_INDEX               , with_directional_relperm);

  if (simulator == INTEHEAD_ECLIPSE100_VALUE) {
    ecl_kw_iset_bool( logihead_kw , LOGIHEAD_REV_RELPERM100_INDEX            , with_reversible_relperm_ECLIPSE100);
    ecl_kw_iset_bool( logihead_kw , LOGIHEAD_RADIAL100_INDEX                 , radial_grid_ECLIPSE100);
  } else {
    ecl_kw_iset_bool( logihead_kw , LOGIHEAD_REV_RELPERM300_INDEX            , with_reversible_relperm_ECLIPSE300 );
    ecl_kw_iset_bool( logihead_kw , LOGIHEAD_RADIAL300_INDEX                 , radial_grid_ECLIPSE300);
  }

  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_HYSTERISIS_INDEX                , with_hysterisis);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_DUALP_INDEX                     , dual_porosity);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_ENDPOINT_SCALING_INDEX          , endpoint_scaling);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_DIR_ENDPOINT_SCALING_INDEX      , directional_endpoint_scaling);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_REV_ENDPOINT_SCALING_INDEX      , reversible_endpoint_scaling);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_ALT_ENDPOINT_SCALING_INDEX      , alternative_endpoint_scaling);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_MISC_DISPLACEMENT_INDEX         , miscible_displacement);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_SCALE_WATER_PC_AT_MAX_SAT_INDEX , scale_water_PC_at_max_sat);
  ecl_kw_iset_bool( logihead_kw , LOGIHEAD_SCALE_GAS_PC_AT_MAX_SAT_INDEX   , scale_gas_PC_at_max_sat);

  return logihead_kw;
}
Example #12
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);
}
Example #13
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 );
  }
}
Example #14
0
void test_cmp_string() {
  ecl_kw_type * ecl_kw = ecl_kw_alloc( "HEADER" , 1 , ECL_CHAR);

  ecl_kw_iset_string8( ecl_kw , 0 , "ABCD");

  test_assert_int_equal( 0 , strcmp( ecl_kw_iget_char_ptr( ecl_kw , 0 ) , "ABCD    "));
  test_assert_true(ecl_kw_icmp_string( ecl_kw , 0 , "ABCD"));
  test_assert_true(ecl_kw_icmp_string( ecl_kw , 0 , "ABCD    "));
  test_assert_true(ecl_kw_icmp_string( ecl_kw , 0 , "ABCD "));

  test_assert_false( ecl_kw_icmp_string( ecl_kw , 0 , "Different"));
  test_assert_false( ecl_kw_icmp_string( ecl_kw , 0 , ""));
  test_assert_false( ecl_kw_icmp_string( ecl_kw , 0 , ""));

}
Example #15
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);
}
Example #16
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 );
    }
  }
}
Example #17
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 );
}
Example #18
0
static ecl_kw_type * ecl_init_file_alloc_INTEHEAD( const ecl_grid_type * ecl_grid , int phases, time_t start_date , int simulator) {
  ecl_kw_type * intehead_kw = ecl_kw_alloc( INTEHEAD_KW , INTEHEAD_INIT_SIZE , ECL_INT_TYPE );
  ecl_kw_scalar_set_int( intehead_kw , 0 );

  ecl_kw_iset_int( intehead_kw , INTEHEAD_UNIT_INDEX    , INTEHEAD_METRIC_VALUE );
  ecl_kw_iset_int( intehead_kw , INTEHEAD_NX_INDEX      , ecl_grid_get_nx( ecl_grid ));
  ecl_kw_iset_int( intehead_kw , INTEHEAD_NY_INDEX      , ecl_grid_get_ny( ecl_grid ));
  ecl_kw_iset_int( intehead_kw , INTEHEAD_NZ_INDEX      , ecl_grid_get_nz( ecl_grid ));
  ecl_kw_iset_int( intehead_kw , INTEHEAD_NACTIVE_INDEX , ecl_grid_get_active_size( ecl_grid ));
  ecl_kw_iset_int( intehead_kw , INTEHEAD_PHASE_INDEX   , phases );
  {
    int mday,month,year;
    ecl_util_set_date_values( start_date , &mday , &month , &year );
    ecl_kw_iset_int( intehead_kw , INTEHEAD_DAY_INDEX    , mday );
    ecl_kw_iset_int( intehead_kw , INTEHEAD_MONTH_INDEX  , month );
    ecl_kw_iset_int( intehead_kw , INTEHEAD_YEAR_INDEX   , year );
  }
  ecl_kw_iset_int( intehead_kw , INTEHEAD_IPROG_INDEX , simulator);

  return intehead_kw;
}
Example #19
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 );
}
Example #20
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 );
}
Example #21
0
int main( int argc , char ** argv) {
    int num_kw  = 1000;       // Total file size should roughly exceed 2GB
    int kw_size = 600000;
    ecl_kw_type * kw = ecl_kw_alloc("KW" , kw_size , ECL_INT_TYPE );
    rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT );
    int i;
    offset_type file_size;
    for (i=0; i < kw_size; i++)
        ecl_kw_iset_int( kw , i , rng_get_int( rng , 912732 ));

    {
        fortio_type * fortio = fortio_open_writer( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP);
        for (i = 0; i < num_kw; i++) {
            printf("Writing keyword %d/%d to file:LARGE_FILE.UNRST \n",i+1 , num_kw );
            ecl_kw_fwrite( kw , fortio );
        }
        fortio_fclose( fortio );
    }

    /*{
      fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP);
      for (i = 0; i < num_kw - 1; i++) {
         printf("SKipping keyword %d/%d from file:LARGE_FILE.UNRST \n",i+1 , num_kw );
         ecl_kw_fskip( fortio );
      }
      {
         ecl_kw_type * file_kw = ecl_kw_fread_alloc( fortio );
         if (ecl_kw_equal( kw , file_kw ))
            printf("Keyword read back from file correctly :-) \n");
          else
            printf("Fatal error - keyword different on return ...\n");
         ecl_kw_free( file_kw );
      }
      fortio_fclose( fortio );
    }
    */
    file_size = util_file_size( "LARGE_FILE.UNRST" );
    printf("File size: %lld \n",file_size);
    {
        fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP);
        printf("Seeking to file end: ");
        fortio_fseek( fortio , file_size , SEEK_SET);
        fortio_fclose( fortio );
        printf("Seek OK \n");
    }


    printf("Doing ecl_file_open(..)\n");
    {
        ecl_file_type * file = ecl_file_open( "LARGE_FILE.UNRST" , 0);
        ecl_kw_type * file_kw = ecl_file_iget_named_kw( file , "KW" , num_kw - 1);
        if (ecl_kw_equal( kw , file_kw ))
            printf("Keyword read back from file correctly :-) \n");
        else
            printf("Fatal error - keyword different on return ...\n");
        ecl_file_close( file );
    }

    remove( "LARGE_FILE.UNRST" );

    exit(0);
}
Example #22
0
void ecl_rft_node_fwrite(const ecl_rft_node_type * rft_node, fortio_type * fortio, ert_ecl_unit_enum unit_set){
  ecl_rft_enum type = ecl_rft_node_get_type(rft_node);
  if (type != RFT)
    util_abort("%s: sorry - only writing of simple RFT is currently implemented",__func__);
  
  {
    ecl_kw_type * time = ecl_kw_alloc(TIME_KW, 1, ECL_FLOAT_TYPE);
    ecl_kw_iset_float(time, 0, ecl_rft_node_get_days(rft_node));
    ecl_kw_fwrite(time, fortio);
    ecl_kw_free(time);
  }

  {
    ecl_kw_type * datevalue = ecl_kw_alloc(DATE_KW, 3, ECL_INT_TYPE);
    time_t date = ecl_rft_node_get_date(rft_node);
    int day;
    int month;
    int year;
    ecl_util_set_date_values(date , &day , &month , &year);
    ecl_kw_iset_int(datevalue, 0, day);
    ecl_kw_iset_int(datevalue, 1, month);
    ecl_kw_iset_int(datevalue, 2, year);
    ecl_kw_fwrite(datevalue, fortio);
    ecl_kw_free(datevalue);
  }

  {
    ecl_kw_type * welletc = ecl_kw_alloc(WELLETC_KW, 16, ECL_CHAR_TYPE);
    ecl_rft_enum type = ecl_rft_node_get_type(rft_node);

    ecl_kw_iset_string8(welletc, 1, ecl_rft_node_get_well_name(rft_node));

    if(type == PLT) {
      ecl_kw_iset_string8(welletc, 5, "P");
    }else if(type == RFT){
      ecl_kw_iset_string8(welletc, 5, "R");
    }else if(type == SEGMENT){
      ecl_kw_iset_string8(welletc, 5, "S");
    }
    ecl_rft_node_fill_welletc(welletc, unit_set);
    ecl_kw_fwrite(welletc, fortio);
    ecl_kw_free(welletc);
  }

  {
    int size_cells = ecl_rft_node_get_size(rft_node);
    ecl_kw_type * conipos = ecl_kw_alloc(CONIPOS_KW, size_cells, ECL_INT_TYPE);
    ecl_kw_type * conjpos = ecl_kw_alloc(CONJPOS_KW, size_cells, ECL_INT_TYPE);
    ecl_kw_type * conkpos = ecl_kw_alloc(CONKPOS_KW, size_cells, ECL_INT_TYPE);
    ecl_kw_type * hostgrid = ecl_kw_alloc(HOSTGRID_KW, size_cells, ECL_CHAR_TYPE);
    ecl_kw_type * depth = ecl_kw_alloc(DEPTH_KW, size_cells, ECL_FLOAT_TYPE);
    ecl_kw_type * pressure = ecl_kw_alloc(PRESSURE_KW, size_cells, ECL_FLOAT_TYPE);
    ecl_kw_type * swat = ecl_kw_alloc(SWAT_KW, size_cells, ECL_FLOAT_TYPE);
    ecl_kw_type * sgas = ecl_kw_alloc(SGAS_KW, size_cells, ECL_FLOAT_TYPE);
    int i;

    for(i =0;i<size_cells;i++){
      const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , i);
      ecl_kw_iset_int(conipos, i, ecl_rft_cell_get_i(cell)+1);
      ecl_kw_iset_int(conjpos, i, ecl_rft_cell_get_j(cell)+1);
      ecl_kw_iset_int(conkpos, i, ecl_rft_cell_get_k(cell)+1);
      ecl_kw_iset_float(depth, i, ecl_rft_cell_get_depth(cell));
      ecl_kw_iset_float(pressure, i, ecl_rft_cell_get_pressure(cell));
      ecl_kw_iset_float(swat, i, ecl_rft_cell_get_swat(cell));
      ecl_kw_iset_float(sgas, i, ecl_rft_cell_get_sgas(cell));
    }
    ecl_kw_fwrite(conipos, fortio);
    ecl_kw_fwrite(conjpos, fortio);
    ecl_kw_fwrite(conkpos, fortio);
    ecl_kw_fwrite(hostgrid, fortio);
    ecl_kw_fwrite(depth, fortio);
    ecl_kw_fwrite(pressure, fortio);
    ecl_kw_fwrite(swat, fortio);
    ecl_kw_fwrite(sgas, fortio);

    ecl_kw_free(conipos);
    ecl_kw_free(conjpos);
    ecl_kw_free(conkpos);
    ecl_kw_free(hostgrid);
    ecl_kw_free(depth);
    ecl_kw_free(pressure);
    ecl_kw_free(swat);
    ecl_kw_free(sgas);
  }
}