Exemplo n.º 1
0
ecl_kw_type * ecl_nnc_export_get_tranll_kw( const ecl_grid_type * grid , const ecl_file_type * init_file ,  int lgr_nr1, int lgr_nr2 ) {
  const char * lgr_name1 = ecl_grid_get_lgr_name( grid , lgr_nr1 );
  const char * lgr_name2 = ecl_grid_get_lgr_name( grid , lgr_nr2 );

  ecl_kw_type * tran_kw = NULL;
  const int file_num_kw = ecl_file_get_size( init_file );
  int global_kw_index = 0;

  while (true) {
    if (global_kw_index >= file_num_kw)
      break;
    {
      ecl_kw_type * ecl_kw = ecl_file_iget_kw( init_file , global_kw_index );
      if (strcmp( LGRJOIN_KW , ecl_kw_get_header( ecl_kw)) == 0) {

        if (ecl_kw_icmp_string( ecl_kw , 0 , lgr_name1) && ecl_kw_icmp_string( ecl_kw , 1 , lgr_name2)) {
          tran_kw = ecl_file_iget_kw( init_file , global_kw_index + 1);
          break;
        }
      }
      global_kw_index++;
    }
  }

  return tran_kw;
}
Exemplo n.º 2
0
static void ecl_file_kw_assert_kw( const ecl_file_kw_type * file_kw ) {
  if (file_kw->ecl_type != ecl_kw_get_type( file_kw->kw )) 
    util_abort("%s: type mismatch between header and file.\n",__func__);

  if (file_kw->kw_size != ecl_kw_get_size( file_kw->kw )) 
    util_abort("%s: size mismatch between header and file.\n",__func__);

  if (strcmp( file_kw->header , ecl_kw_get_header( file_kw->kw )) != 0 )
    util_abort("%s: name mismatch between header and file.\n",__func__);
}
void ecl_kw_fprintf_grdecl__(const ecl_kw_type * ecl_kw , const char * special_header , FILE * stream) { 
  if (special_header)
    fprintf(stream,"%s\n" , special_header); 
  else 
    fprintf(stream,"%s\n" , ecl_kw_get_header(ecl_kw));

  {
    fortio_type * fortio = fortio_alloc_FILE_wrapper(NULL , false , true , stream);   /* Endian flip should *NOT* be used */
    ecl_kw_fwrite_data(ecl_kw , fortio);
    fortio_free_FILE_wrapper( fortio );
  }
  fprintf(stream,"/\n"); 
}
Exemplo n.º 4
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.º 5
0
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;
}
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
0
void checkInitFile()
{
    // use ERT directly to inspect the INIT file produced by EclipseWriter
    auto initFile = fortio_open_reader("FOO.INIT", /*isFormated=*/0, ECL_ENDIAN_FLIP);

    ecl_kw_type *eclKeyword;
    // yes, that's an assignment!
    while ((eclKeyword = ecl_kw_fread_alloc(initFile))) {
        std::string keywordName(ecl_kw_get_header(eclKeyword));

        if (keywordName == "PORO") {
            const std::vector<double> &sourceData = deck->getKeyword("PORO")->getSIDoubleData();
            std::vector<double> resultData;
            getErtData(eclKeyword, resultData);

            compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4);
        }

        if (keywordName == "PERMX") {
            std::vector<double> sourceData = deck->getKeyword("PERMX")->getSIDoubleData();
            std::vector<double> resultData;
            getErtData(eclKeyword, resultData);

            // convert the data from ERT from Field to SI units (mD to m^2)
            for (size_t i = 0; i < resultData.size(); ++i) {
                resultData[i] *= 9.869233e-16;
            }

            compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4);
        }

        ecl_kw_free(eclKeyword);
    }

    fortio_fclose(initFile);
}
Exemplo n.º 10
0
void checkRestartFile(int timeStepIdx)
{
    size_t numCells = ourFineGridManagerPtr->c_grid()->number_of_cells;

    Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
    int numActivePhases = phaseUsage.num_phases;
    int waterPhaseIdx = phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua];
    int gasPhaseIdx = phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour];

    for (int i = 0; i <= timeStepIdx; ++i) {
        createBlackoilState(i);

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

        int curSeqnum = -1;
        ecl_kw_type *eclKeyword;
        // yes, that's an assignment!
        while ((eclKeyword = ecl_kw_fread_alloc(rstFile))) {
            std::string keywordName(ecl_kw_get_header(eclKeyword));

            if (keywordName == "SEQNUM") {
                curSeqnum = *static_cast<int*>(ecl_kw_iget_ptr(eclKeyword, 0));
            }
            if (curSeqnum != i)
                continue;

            if (keywordName == "PRESSURE") {
                std::vector<double> sourceData = blackoilState->pressure();
                std::vector<double> resultData;
                getErtData(eclKeyword, resultData);

                // convert the data from ERT from Metric to SI units (bar to Pa)
                for (size_t i = 0; i < resultData.size(); ++i) {
                    resultData[i] *= 1e5;
                }

                compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4);
            }

            if (keywordName == "SWAT") {
                std::vector<double> sourceData;
                std::vector<double> resultData;
                getErtData(eclKeyword, resultData);

                // extract the water saturation from the black-oil state
                sourceData.resize(numCells);
                for (size_t i = 0; i < sourceData.size(); ++i) {
                    // again, fun with direct index manipulation...
                    sourceData[i] = blackoilState->saturation()[i*numActivePhases + waterPhaseIdx];
                }

                compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4);
            }

            if (keywordName == "SGAS") {
                std::vector<double> sourceData;
                std::vector<double> resultData;
                getErtData(eclKeyword, resultData);

                // extract the water saturation from the black-oil state
                sourceData.resize(numCells);
                for (size_t i = 0; i < sourceData.size(); ++i) {
                    // again, fun with direct index manipulation...
                    sourceData[i] = blackoilState->saturation()[i*numActivePhases + gasPhaseIdx];
                }

                compareErtData(sourceData, resultData, /*percentTolerance=*/1e-4);
            }
        }

        fortio_fclose(rstFile);
    }
}
Exemplo n.º 11
0
ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , offset_type offset ) {
  return ecl_file_kw_alloc0( ecl_kw_get_header( ecl_kw ) , ecl_kw_get_data_type( ecl_kw ) , ecl_kw_get_size( ecl_kw ) , offset );
}