コード例 #1
0
ファイル: well_info_test.c プロジェクト: akva2/ResInsight
int main( int argc , char ** argv) {
  signal(SIGSEGV , util_abort_signal);    /* Segmentation violation, i.e. overwriting memory ... */
  signal(SIGTERM , util_abort_signal);    /* If killing the enkf program with SIGTERM (the default kill signal) you will get a backtrace. 
                                             Killing with SIGKILL (-9) will not give a backtrace.*/
  signal(SIGABRT , util_abort_signal);    /* Signal abort. */ 
  {
    well_info_type * well_info = well_info_alloc( NULL );
    int i;
    for (i=1; i < argc; i++) {
      printf("Loading file: %s \n",argv[i]);
      well_info_load_rstfile( well_info , argv[i]);
    }
    
    // List all wells:
    {
      int iwell;
      for (iwell = 0; iwell < well_info_get_num_wells( well_info ); iwell++) {
        well_ts_type * well_ts = well_info_get_ts( well_info , well_info_iget_well_name( well_info , iwell));
        well_state_type * well_state = well_ts_get_last_state( well_ts );
        
        well_state_summarize( well_state , stdout );
        printf("\n");
      }
    }
    well_info_free( well_info );
    exit(1);

    // Look at the timeseries for one well:
    {
      well_ts_type * well_ts = well_info_get_ts( well_info , well_info_iget_well_name( well_info , 0));
      int i;
      for (i =0; i < well_ts_get_size( well_ts ); i++) {
        well_state_type * well_state = well_ts_iget_state( well_ts , i );
        
        printf("Well:%s  report:%04d  state:",well_state_get_name( well_state ), well_state_get_report_nr( well_state ));
        if (well_state_is_open( well_state ))
          printf("OPEN\n");
        else
          printf("CLOSED\n");
      }
    }
    
    // Look at one well_state:
    {
      well_state_type * well_state = well_info_iiget_state( well_info , 0 , 0 );
      printf("Well:%s  report:%04d \n",well_state_get_name( well_state ), well_state_get_report_nr( well_state ));
      {
        const well_conn_type ** connections = well_state_get_connections( well_state , 0 );
        printf("Branches: %d \n",well_state_get_num_branches( well_state ));
        printf("num_connections: %d \n",well_state_get_num_connections( well_state , 0 ));
        { 
          int iconn;
          for (iconn = 0; iconn < well_state_get_num_connections( well_state , 0 ); iconn++) {
            well_conn_type * conn = connections[ iconn ];
            printf("Connection:%02d   i=%3d  j=%3d  k=%3d  State:",iconn , well_conn_get_i( conn ) , well_conn_get_j( conn ) , well_conn_get_k( conn ));
            if (well_conn_open( conn ) )
            printf("Open\n");
            else
              printf("Closed\n");
          }
        }
      }
    }
    well_info_free( well_info );
  }
}
コード例 #2
0
ファイル: well_conn.cpp プロジェクト: OPM/ResInsight
int main(int argc , char ** argv) {
  int i = 10;
  int j = 5;
  int k = 16;
  double CF = 0;
  bool open = true;
  test_install_SIGNALS();

  {
    well_conn_dir_enum dir = well_conn_dirX;
    well_conn_type * conn = well_conn_alloc(i,j,k,CF,dir,open);
    well_conn_type * conn2 = well_conn_alloc(i,j,k,CF,dir,open);
    well_conn_type * conn3 = well_conn_alloc(i,j,k+1,CF,dir,open);
    test_assert_not_NULL( conn );
    test_assert_true( well_conn_is_instance( conn ));
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_false( well_conn_MSW( conn ));
    test_assert_true( well_conn_matrix_connection( conn ));
    test_assert_true( well_conn_equal( conn , conn2 ));
    test_assert_false( well_conn_equal( conn , conn3 ));
    test_assert_double_equal( CF , well_conn_get_connection_factor( conn ));
    well_conn_free( conn3 );
    well_conn_free( conn2 );
    well_conn_free( conn );
  }

  {
    well_conn_dir_enum dir = well_conn_fracX;
    well_conn_type * conn = well_conn_alloc(i,j,k,CF,dir,open);
    test_assert_NULL( conn );
  }


  {
    well_conn_dir_enum dir = well_conn_fracX;
    well_conn_type * conn = well_conn_alloc_fracture(i,j,k,CF,dir,open);
    test_assert_not_NULL( conn );
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_false( well_conn_MSW( conn ));
    test_assert_false( well_conn_matrix_connection( conn ));
    test_assert_true( well_conn_fracture_connection( conn ));
    well_conn_free( conn );
  }


  {
    well_conn_dir_enum dir = well_conn_dirX;
    well_conn_type * conn = well_conn_alloc_fracture(i,j,k,CF,dir,open);
    test_assert_not_NULL( conn );
    well_conn_free( conn );
  }

  {
    int segment = 16;
    well_conn_dir_enum dir = well_conn_dirX;
    well_conn_type * conn = well_conn_alloc_MSW(i,j,k,CF,dir,open,segment);
    test_assert_not_NULL( conn );
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_int_equal( segment , well_conn_get_segment_id( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_true( well_conn_MSW( conn ));
    test_assert_true( well_conn_matrix_connection( conn ));
    well_conn_free( conn );
  }


  {
    int segment = 16;
    well_conn_dir_enum dir = well_conn_fracX;
    well_conn_type * conn = well_conn_alloc_fracture_MSW(i,j,k,CF,dir,open,segment);
    test_assert_not_NULL( conn );
    test_assert_int_equal( i , well_conn_get_i( conn ));
    test_assert_int_equal( j , well_conn_get_j( conn ));
    test_assert_int_equal( k , well_conn_get_k( conn ));
    test_assert_int_equal( segment , well_conn_get_segment_id( conn ));
    test_assert_bool_equal( open , well_conn_open( conn ));
    test_assert_int_equal( dir , well_conn_get_dir( conn ));
    test_assert_true( well_conn_MSW( conn ));
    test_assert_false( well_conn_matrix_connection( conn ));
    well_conn_free( conn );
  }

  test_conn_rate();

}
コード例 #3
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir)
{
    CVF_ASSERT(reservoir);

    if (m_dynamicResultsAccess.isNull()) return;

    well_info_type* ert_well_info = well_info_alloc(NULL);
    if (!ert_well_info) return;

    m_dynamicResultsAccess->readWellData(ert_well_info);

    RigMainGrid* mainGrid = reservoir->mainGrid();
    std::vector<RigGridBase*> grids;
    reservoir->allGrids(&grids);

    cvf::Collection<RigWellResults> wells;
    caf::ProgressInfo progress(well_info_get_num_wells(ert_well_info), "");

    int wellIdx;
    for (wellIdx = 0; wellIdx < well_info_get_num_wells(ert_well_info); wellIdx++)
    {
        const char* wellName = well_info_iget_well_name(ert_well_info, wellIdx);
        CVF_ASSERT(wellName);

        cvf::ref<RigWellResults> wellResults = new RigWellResults;
        wellResults->m_wellName = wellName;

        well_ts_type* ert_well_time_series = well_info_get_ts(ert_well_info , wellName);
        int timeStepCount = well_ts_get_size(ert_well_time_series);

        wellResults->m_wellCellsTimeSteps.resize(timeStepCount);

        int timeIdx;
        for (timeIdx = 0; timeIdx < timeStepCount; timeIdx++)
        {
            well_state_type* ert_well_state = well_ts_iget_state(ert_well_time_series, timeIdx);

            RigWellResultFrame& wellResFrame = wellResults->m_wellCellsTimeSteps[timeIdx];

            // Build timestamp for well
            // Also see RifEclipseOutputFileAccess::timeStepsText for accessing time_t structures
            {
                time_t stepTime = well_state_get_sim_time(ert_well_state);
                wellResFrame.m_timestamp = QDateTime::fromTime_t(stepTime);
            }

            // Production type
            well_type_enum ert_well_type = well_state_get_type(ert_well_state);
            if (ert_well_type == PRODUCER)
            {
                wellResFrame.m_productionType = RigWellResultFrame::PRODUCER;
            }
            else if (ert_well_type == WATER_INJECTOR)
            {
                wellResFrame.m_productionType = RigWellResultFrame::WATER_INJECTOR;
            }
            else if (ert_well_type == GAS_INJECTOR)
            {
                wellResFrame.m_productionType = RigWellResultFrame::GAS_INJECTOR;
            }
            else if (ert_well_type == OIL_INJECTOR)
            {
                wellResFrame.m_productionType = RigWellResultFrame::OIL_INJECTOR;
            }
            else
            {
                wellResFrame.m_productionType = RigWellResultFrame::UNDEFINED_PRODUCTION_TYPE;
            }

            wellResFrame.m_isOpen = well_state_is_open( ert_well_state );




            // Loop over all the grids in the model. If we have connections in one, we will discard
            // the maingrid connections as they are "duplicates"

            bool hasWellConnectionsInLGR = false;
            for (size_t gridNr = 1; gridNr < grids.size(); ++gridNr)
            {
                int branchCount = well_state_iget_lgr_num_branches(ert_well_state, static_cast<int>(gridNr));
                if (branchCount > 0)
                {
                    hasWellConnectionsInLGR = true;
                    break;
                }
            }
            size_t gridNr = hasWellConnectionsInLGR ? 1 : 0;
            for (; gridNr < grids.size(); ++gridNr)
            {

                // Wellhead. If several grids have a wellhead definition for this well, we use tha last one. (Possibly the innermost LGR)
                const well_conn_type* ert_wellhead = well_state_iget_wellhead(ert_well_state, static_cast<int>(gridNr));
                if (ert_wellhead)
                {
                    int cellI = well_conn_get_i( ert_wellhead );
                    int cellJ = well_conn_get_j( ert_wellhead );
                    int cellK = CVF_MAX(0, well_conn_get_k(ert_wellhead)); // Why this ?

                    // If a well is defined in fracture region, the K-value is from (cellCountK - 1) -> cellCountK*2 - 1
                    // Adjust K so index is always in valid grid region
                    if (cellK >= grids[gridNr]->cellCountK())
                    {
                        cellK -= static_cast<int>(grids[gridNr]->cellCountK());
                    }

                    wellResFrame.m_wellHead.m_gridCellIndex = grids[gridNr]->cellIndexFromIJK(cellI, cellJ, cellK);
                    wellResFrame.m_wellHead.m_gridIndex = gridNr;
                }


                int branchCount = well_state_iget_lgr_num_branches(ert_well_state, static_cast<int>(gridNr));
                if (branchCount > 0)
                {
                    if (static_cast<int>(wellResFrame.m_wellResultBranches.size()) < branchCount) wellResFrame.m_wellResultBranches.resize(branchCount);

                    for (int branchIdx = 0; branchIdx < branchCount; ++branchIdx )
                    {
                        // Connections
                        int connectionCount = well_state_iget_num_lgr_connections(ert_well_state, static_cast<int>(gridNr), branchIdx);
                        if (connectionCount > 0)
                        {

                            RigWellResultBranch& wellSegment = wellResFrame.m_wellResultBranches[branchIdx]; // Is this completely right? Is the branch index actually the same between lgrs ?
                            wellSegment.m_branchNumber = branchIdx;
                            size_t existingConnCount = wellSegment.m_wellCells.size();
                            wellSegment.m_wellCells.resize(existingConnCount + connectionCount);

                            int connIdx;
                            for (connIdx = 0; connIdx < connectionCount; connIdx++)
                            {
                                const well_conn_type* ert_connection = well_state_iget_lgr_connections( ert_well_state, static_cast<int>(gridNr), branchIdx)[connIdx];
                                CVF_ASSERT(ert_connection);

                                RigWellResultCell& data = wellSegment.m_wellCells[existingConnCount + connIdx];
                                data.m_gridIndex = gridNr;
                                {
                                    int cellI = well_conn_get_i( ert_connection );
                                    int cellJ = well_conn_get_j( ert_connection );
                                    int cellK = well_conn_get_k( ert_connection );
                                    bool open = well_conn_open( ert_connection );
                                    int branch = well_conn_get_branch( ert_connection );
                                    int segment = well_conn_get_segment( ert_connection );

                                    // If a well is defined in fracture region, the K-value is from (cellCountK - 1) -> cellCountK*2 - 1
                                    // Adjust K so index is always in valid grid region
                                    if (cellK >= grids[gridNr]->cellCountK())
                                    {
                                        cellK -= static_cast<int>(grids[gridNr]->cellCountK());
                                    }

                                    data.m_gridCellIndex = grids[gridNr]->cellIndexFromIJK(cellI , cellJ , cellK);

                                    data.m_isOpen    = open;
                                    data.m_branchId  = branch;
                                    data.m_segmentId = segment;
                                }
                            }
                        }
                    }
                }
            }
        }

        wellResults->computeMappingFromResultTimeIndicesToWellTimeIndices(m_timeSteps);

        wells.push_back(wellResults.p());

        progress.incrementProgress();
    }

    well_info_free(ert_well_info);

    reservoir->setWellResults(wells);
}
コード例 #4
0
void verifyWellState(const std::string& rst_filename,
                     Opm::EclipseGridConstPtr ecl_grid,
                     Opm::ScheduleConstPtr schedule) {

  well_info_type * well_info = well_info_alloc(ecl_grid->c_ptr());
  well_info_load_rstfile(well_info, rst_filename.c_str(), false);

  //Verify numwells
  int numwells = well_info_get_num_wells(well_info);
  BOOST_CHECK(numwells == (int)schedule->numWells());

  std::vector<Opm::WellConstPtr> wells = schedule->getWells();

  for (int i = 0; i < numwells; ++i) {

    //Verify wellnames
    const char * wellname = well_info_iget_well_name(well_info, i);
    Opm::WellConstPtr well = wells.at(i);
    BOOST_CHECK(wellname == well->name());

    // Verify well-head position data
    well_ts_type * well_ts = well_info_get_ts(well_info , wellname);
    well_state_type * well_state = well_ts_iget_state(well_ts, 0);
    const well_conn_type * well_head = well_state_get_wellhead(well_state, ECL_GRID_GLOBAL_GRID);
    BOOST_CHECK(well_conn_get_i(well_head) == well->getHeadI());
    BOOST_CHECK(well_conn_get_j(well_head) == well->getHeadJ());

    for (int j = 0; j < well_ts_get_size(well_ts); ++j) {
      well_state = well_ts_iget_state(well_ts, j);

      //Verify welltype
      int ert_well_type = well_state_get_type(well_state);
      WellType welltype = well->isProducer(j) ? PRODUCER : INJECTOR;
      Opm::WellInjector::TypeEnum injectortype = well->getInjectionProperties(j).injectorType;
      int ecl_converted_welltype = Opm::EclipseWriter::eclipseWellTypeMask(welltype, injectortype);
      int ert_converted_welltype = well_state_translate_ecl_type_int(ecl_converted_welltype);
      BOOST_CHECK(ert_well_type == ert_converted_welltype);

      //Verify wellstatus
      int ert_well_status = well_state_is_open(well_state) ? 1 : 0;

      Opm::WellCommon::StatusEnum status = well->getStatus(j);
      int wellstatus = Opm::EclipseWriter::eclipseWellStatusMask(status);

      BOOST_CHECK(ert_well_status == wellstatus);

      //Verify number of completion connections
      const well_conn_collection_type * well_connections = well_state_get_global_connections( well_state );
      size_t num_wellconnections = well_conn_collection_get_size(well_connections);

      int report_nr = well_state_get_report_nr(well_state);
      Opm::CompletionSetConstPtr completions_set = well->getCompletions((size_t)report_nr);

      BOOST_CHECK(num_wellconnections == completions_set->size());

      //Verify coordinates for each completion connection
      for (size_t k = 0; k < num_wellconnections; ++k) {
          const well_conn_type * well_connection = well_conn_collection_iget_const(well_connections , k);

          Opm::CompletionConstPtr completion = completions_set->get(k);

          BOOST_CHECK(well_conn_get_i(well_connection) == completion->getI());
          BOOST_CHECK(well_conn_get_j(well_connection) == completion->getJ());
          BOOST_CHECK(well_conn_get_k(well_connection) == completion->getK());
      }
    }
  }

  well_info_free(well_info);
}
コード例 #5
0
ファイル: segment_info.c プロジェクト: agchitu/ert
int main(int argc , char ** argv) {
  const char * Xfile = argv[1];
  ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
  ecl_rsthead_type * rst_head = ecl_rsthead_alloc( ecl_file_get_global_view(rst_file) , ecl_util_filename_report_nr(Xfile));
  const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 );
  const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 );
  well_rseg_loader_type * rseg_loader = well_rseg_loader_alloc(ecl_file_get_global_view(rst_file));
  const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
  const ecl_kw_type * scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0 );
  const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( rst_file , ZWEL_KW , 0 );

  { 
    int well_nr;
    for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) {
      const int zwel_offset  = rst_head->nzwelz * well_nr;
      char * well_name       = util_alloc_strip_copy(ecl_kw_iget_ptr( zwel_kw , zwel_offset ));  
      
      printf("=================================================================\n");
      printf("Well: %s ",well_name);
      {
        well_conn_collection_type * connections = well_conn_collection_alloc();
        well_segment_collection_type * segments = well_segment_collection_alloc();
        bool load_segment_information = true;
        bool is_MSW_well = false;
                
        if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_loader , rst_head , load_segment_information , &is_MSW_well)) {
          well_branch_collection_type * branches = well_branch_collection_alloc();

          well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , scon_kw , well_nr , rst_head);
          well_segment_collection_link( segments );
          well_segment_collection_add_branches( segments , branches );
          well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); 
          
          printf("\n");
          printf("Segments:\n");
          {
            int is;
            for (is=0; is < well_segment_collection_get_size( segments ); is++) {
              well_segment_type * segment = well_segment_collection_iget( segments , is );
              printf("-----------------------------------------------------------------\n");
              printf("ID          : %d \n",well_segment_get_id( segment ));
              printf("Outlet      : %d \n",well_segment_get_outlet_id( segment ));
              printf("Branch      : %d \n",well_segment_get_branch_id( segment ));
              printf("Connections : [");
              {
                const well_conn_collection_type * connections = well_segment_get_global_connections( segment );
                if (connections) {
                  int ic;
                  for (ic = 0; ic < well_conn_collection_get_size( connections ); ic++) {
                    const well_conn_type * conn = well_conn_collection_iget( connections , ic );
                    printf("(%d , %d , %d)  ",well_conn_get_i( conn ), well_conn_get_j( conn ), well_conn_get_k( conn ));
                  }
                }
              }
              
              printf("]\n");
            }
          }
          well_branch_collection_free( branches );
        } else
          printf("not MSW well\n\n");

        well_conn_collection_free( connections );
        well_segment_collection_free( segments );
      }
    }
  }

  ecl_file_close( rst_file );
  ecl_rsthead_free( rst_head );
}