예제 #1
0
파일: grdecl_grid.c 프로젝트: bramirex/ert
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 );
}
예제 #2
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 );
}
예제 #3
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;
}