コード例 #1
0
ファイル: ecl_rsthead.c プロジェクト: Ensembles/ert
void test_file( const char * filename , int occurence , bool exists , const ecl_rsthead_type * true_header) {
  int report_step = ecl_util_filename_report_nr( filename );
  ecl_file_type * rst_file = ecl_file_open( filename , 0);
  ecl_file_enum file_type = ecl_util_get_file_type( filename , NULL , NULL );
  ecl_file_view_type * rst_view;
  ecl_rsthead_type * rst_head;

  if (file_type == ECL_RESTART_FILE)
    rst_view = ecl_file_get_global_view( rst_file );
  else
    rst_view = ecl_file_get_restart_view( rst_file , occurence , -1 , -1 , -1 );

  if (exists) {
    test_assert_not_NULL( rst_view );
    rst_head = ecl_rsthead_alloc( rst_view , report_step);
    test_assert_not_NULL( rst_head );

    if (occurence == 0) {
      ecl_rsthead_type * rst_head0 = ecl_rsthead_alloc( rst_view , report_step );

      test_assert_true( ecl_rsthead_equal( rst_head , rst_head0 ));
      ecl_rsthead_free( rst_head0 );
    }
    test_assert_true( ecl_rsthead_equal( rst_head , true_header ));

    ecl_rsthead_free( rst_head );
  } else
    test_assert_NULL( rst_view );

}
コード例 #2
0
ファイル: well_state.c プロジェクト: JacobStoren/ResInsight
static void well_state_add_connections__( well_state_type * well_state ,
                                          const ecl_file_type * rst_file ,
                                          const char * grid_name ,
                                          int grid_nr,
                                          int well_nr ) {

  ecl_rsthead_type  * header   = ecl_rsthead_alloc( rst_file );
  const ecl_kw_type * icon_kw  = ecl_file_iget_named_kw( rst_file , ICON_KW   , 0);
  const ecl_kw_type * iwel_kw  = ecl_file_iget_named_kw( rst_file , IWEL_KW   , 0);

  
  well_state_add_wellhead( well_state , header , iwel_kw , well_nr , grid_name , grid_nr );

  if (!well_state_has_grid_connections( well_state , grid_name ))
    hash_insert_hash_owned_ref( well_state->connections , grid_name, well_conn_collection_alloc( ) , well_conn_collection_free__ );

  {
    ecl_kw_type * scon_kw = NULL;
    well_conn_collection_type * wellcc = hash_get( well_state->connections , grid_name );
    if (ecl_file_has_kw( rst_file , SCON_KW))
      scon_kw = ecl_file_iget_named_kw( rst_file , SCON_KW , 0);
    
    well_conn_collection_load_from_kw( wellcc , iwel_kw , icon_kw , scon_kw , well_nr , header );
  }
  ecl_rsthead_free( header );
}
コード例 #3
0
ファイル: well_state.c プロジェクト: JacobStoren/ResInsight
static int well_state_get_lgr_well_nr( const well_state_type * well_state , const ecl_file_type * ecl_file) {
  int well_nr = -1;

  if (ecl_file_has_kw( ecl_file , ZWEL_KW)) {
    ecl_rsthead_type  * header  = ecl_rsthead_alloc( ecl_file );
    const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW  , 0 );
    int num_wells               = header->nwells;
    well_nr = 0;
    while (true) {
      bool found = false;
      {
        char * lgr_well_name = util_alloc_strip_copy( ecl_kw_iget_ptr( zwel_kw , well_nr * header->nzwelz) );

        if ( strcmp( well_state->name , lgr_well_name) == 0)
          found = true;
        else
          well_nr++;

        free( lgr_well_name );
      }

      if (found)
        break;
      else if (well_nr == num_wells) {
        // The well is not in this LGR at all.
        well_nr = -1;
        break;
      }

    }
    ecl_rsthead_free( header );
  }
  return well_nr;
}
コード例 #4
0
ファイル: well_info.c プロジェクト: Ensembles/ert
void well_info_add_wells2( well_info_type * well_info , ecl_file_view_type * rst_view , int report_nr, bool load_segment_information) {
  bool close_stream = ecl_file_view_drop_flag( rst_view , ECL_FILE_CLOSE_STREAM );
  ecl_rsthead_type * global_header = ecl_rsthead_alloc( rst_view , report_nr );
  int well_nr;
  for (well_nr = 0; well_nr < global_header->nwells; well_nr++) {
    well_state_type * well_state = well_state_alloc_from_file2( rst_view , well_info->grid , report_nr , well_nr , load_segment_information );
    if (well_state != NULL)
      well_info_add_state( well_info , well_state );
  }
  ecl_rsthead_free( global_header );
  if (close_stream)
    ecl_file_view_add_flag(rst_view, ECL_FILE_CLOSE_STREAM);
}
コード例 #5
0
ファイル: well_state.c プロジェクト: JacobStoren/ResInsight
bool well_state_add_MSW( well_state_type * well_state ,
                         const ecl_file_type * rst_file ,
                         int well_nr,
                         bool load_segment_information) {

  if (ecl_file_has_kw( rst_file , ISEG_KW)) {
    ecl_rsthead_type  * rst_head  = ecl_rsthead_alloc( rst_file );
    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 = NULL;
    
    int segment_count;

    if (ecl_file_has_kw( rst_file , RSEG_KW )) {
      if (load_segment_information)
        rseg_loader = well_rseg_loader_alloc(rst_file);
        
      segment_count = well_segment_collection_load_from_kw( well_state->segments ,
                                                            well_nr ,
                                                            iwel_kw ,
                                                            iseg_kw ,
                                                            rseg_loader ,
                                                            rst_head,
                                                            load_segment_information , 
                                                            &well_state->is_MSW_well);
      
      
      if (segment_count > 0) {
        hash_iter_type * grid_iter = hash_iter_alloc( well_state->connections );
        while (!hash_iter_is_complete( grid_iter )) {
          const char * grid_name = hash_iter_get_next_key( grid_iter );
          const well_conn_collection_type * connections = hash_get( well_state->connections , grid_name );
          well_segment_collection_add_connections( well_state->segments , grid_name , connections );
        }
        hash_iter_free( grid_iter );

        well_segment_collection_link( well_state->segments );
        well_segment_collection_add_branches( well_state->segments , well_state->branches );
      }
      ecl_rsthead_free( rst_head );
      
      if (rseg_loader != NULL) {
        well_rseg_loader_free(rseg_loader);
      }
      
      return true;
    }
  } else
    return false;
}
コード例 #6
0
ファイル: well_state.c プロジェクト: JacobStoren/ResInsight
well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_nr ,  int global_well_nr ,bool load_segment_information) {
  if (ecl_file_has_kw( ecl_file , IWEL_KW)) {
    well_state_type   * well_state = NULL;
    ecl_rsthead_type  * global_header  = ecl_rsthead_alloc( ecl_file );
    const ecl_kw_type * global_iwel_kw = ecl_file_iget_named_kw( ecl_file , IWEL_KW   , 0);
    const ecl_kw_type * global_zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW   , 0);

    const int iwel_offset = global_header->niwelz * global_well_nr;
    {
      char * name;
      bool open;
      well_type_enum type = UNDOCUMENTED_ZERO;
      {
        int int_state = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_STATUS_ITEM );
        if (int_state > 0)
          open = true;
        else
          open = false;
      }

      {
        int int_type = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_TYPE_ITEM);
        type = well_state_translate_ecl_type_int( int_type );
      }

      {
        const int zwel_offset         = global_header->nzwelz * global_well_nr;
        name = util_alloc_strip_copy(ecl_kw_iget_ptr( global_zwel_kw , zwel_offset ));  // Hardwired max 8 characters in Well Name
      }

      well_state = well_state_alloc(name , global_well_nr , open , type , report_nr , global_header->sim_time);
      free( name );

      well_state_add_connections( well_state , grid , ecl_file , global_well_nr);
      if (ecl_file_has_kw( ecl_file , ISEG_KW))
        well_state_add_MSW( well_state , ecl_file , global_well_nr , load_segment_information);
      

    }
    ecl_rsthead_free( global_header );
    return well_state;
  } else
    /* This seems a bit weird - have come over E300 restart files without the IWEL keyword. */
    return NULL;
}
コード例 #7
0
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( rst_file );
  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 );
  const ecl_kw_type * rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0 );
  const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );

  test_install_SIGNALS();
  test_assert_not_NULL( rst_file );
  test_assert_not_NULL( rst_head );
  {
    int well_nr;
    for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) {
      well_conn_collection_type * connections = well_conn_collection_alloc();
      well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , well_nr , rst_head);
      {
        well_segment_collection_type * segments = well_segment_collection_alloc();

        if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_kw , rst_head )) {
          well_branch_collection_type * branches = well_branch_collection_alloc();

          test_assert_true( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head));
          well_segment_collection_link( segments );
          {
            int is;
            for (is=0; is < well_segment_collection_get_size( segments ); is++) {
              well_segment_type * segment = well_segment_collection_iget( segments , is );

              if (well_segment_nearest_wellhead( segment ))
                test_assert_NULL( well_segment_get_outlet( segment ));
              else
                test_assert_not_NULL( well_segment_get_outlet( segment ));

              test_assert_ptr_not_equal( segment , well_segment_get_outlet( segment ));
            }
          }

          well_segment_collection_add_branches( segments , branches );
          {
            int ib;
            for (ib = 0; ib < well_branch_collection_get_size( branches ); ib++) {
              const well_segment_type * start_segment = well_branch_collection_iget_start_segment( branches , ib );
              const well_segment_type * segment = start_segment;

              printf("Branch %d/%d " , ib , well_branch_collection_get_size( branches ) );
              while (segment) {
                printf("[%p]%d -> \n",segment , well_segment_get_id( segment ));
                segment = well_segment_get_outlet( segment );
              }
              printf("\n");
              sleep(1);
            }
          }
          well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections );
          well_branch_collection_free( branches );
        } else
          test_assert_false( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head ));

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

  ecl_file_close( rst_file );
  ecl_rsthead_free( rst_head );
  exit(0);
}
コード例 #8
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::createReportStepsMetaData(std::vector<ecl_file_type*> ecl_files, std::vector<RifRestartReportStep>* reportSteps)
{
    if (!reportSteps) return;

    for (auto ecl_file : ecl_files)
    {
        if (!ecl_file) continue;

        int reportStepCount = ecl_file_get_num_named_kw(ecl_file, INTEHEAD_KW);
        for (int reportStepIndex = 0; reportStepIndex < reportStepCount; reportStepIndex++)
        {
            ecl_file_view_type* rst_view = ecl_file_get_global_view(ecl_file);
            if (!rst_view) continue;

            ecl_rsthead_type* restart_header = ecl_rsthead_alloc(rst_view, reportStepIndex);
            if (restart_header)
            {
                ecl_file_push_block(ecl_file);

                {
                    ecl_file_select_block(ecl_file, INTEHEAD_KW, reportStepIndex);

                    RifRestartReportStep reportStep;

                    // Set Date
                    {
                        QDateTime reportDateTime(QDate(restart_header->year, restart_header->month, restart_header->day));
                        reportStep.dateTime = reportDateTime;
                    }

                    // Find number of keywords withing this report step
                    int numKeywords = ecl_file_get_num_distinct_kw(ecl_file);
                    for (int iKey = 0; iKey < numKeywords; iKey++)
                    {
                        const char* kw = ecl_file_iget_distinct_kw(ecl_file, iKey);

                        int namedKeywordCount = ecl_file_get_num_named_kw(ecl_file, kw);
                        for (int iOcc = 0; iOcc < namedKeywordCount; iOcc++)
                        {
                            ecl_data_type dataType = ecl_file_iget_named_data_type(ecl_file, kw, iOcc);
                            ecl_type_enum dataTypeEmum = ecl_type_get_type(dataType);
                            if (dataTypeEmum != ECL_DOUBLE_TYPE && dataTypeEmum != ECL_FLOAT_TYPE && dataTypeEmum != ECL_INT_TYPE)
                            {
                                continue;
                            }

                            int itemCount = ecl_file_iget_named_size(ecl_file, kw, iOcc);
                            reportStep.m_keywords.appendKeyword(kw, itemCount, iOcc);
                        }
                    }

                    reportSteps->push_back(reportStep);
                }

                ecl_file_pop_block(ecl_file);

                ecl_rsthead_free(restart_header);
            }
        }
    }
}
コード例 #9
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 );
}
コード例 #10
0
int main(int argc , char ** argv) {
  const char * Xfile = argv[1];
  ecl_file_type * rst_file = ecl_file_open( Xfile , 0 );
  ecl_file_view_type * rst_view = ecl_file_get_active_view( rst_file );
  ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_view , 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(rst_view);
  const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 );
  const ecl_kw_type * scon_kw = NULL;
  const ecl_kw_type * xcon_kw = NULL;

  test_install_SIGNALS();
  test_assert_not_NULL( rst_file );
  test_assert_not_NULL( rst_head );
  { 
    int well_nr;
    for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) {
      well_conn_collection_type * connections = well_conn_collection_alloc();
      well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , scon_kw, xcon_kw, well_nr , rst_head);
      {
        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();
          
          test_assert_true( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head));
          well_segment_collection_link( segments );
          {
            int is;
            for (is=0; is < well_segment_collection_get_size( segments ); is++) {
              well_segment_type * segment = well_segment_collection_iget( segments , is );
              
              if (well_segment_nearest_wellhead( segment )) 
                test_assert_NULL( well_segment_get_outlet( segment ));
              else
                test_assert_not_NULL( well_segment_get_outlet( segment ));

              test_assert_int_not_equal( well_segment_get_id( segment ) , well_segment_get_outlet_id( segment ));
              test_assert_ptr_not_equal( segment , well_segment_get_outlet( segment ));
            }
          }
          well_segment_collection_add_branches( segments , branches );
          {
            int ib;
            for (ib = 0; ib < well_branch_collection_get_size( branches ); ib++) {
              const well_segment_type * start_segment = well_branch_collection_iget_start_segment( branches , ib );
              const well_segment_type * segment = start_segment;
              
              printf("Branch %d " , ib );
              while (segment) {
                printf("%d -> ",well_segment_get_id( segment ));
                segment = well_segment_get_outlet( segment );
              }
              printf(" X \n");
            } 
          }
          well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); 
          well_branch_collection_free( branches );
        } else
          test_assert_false( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head ));

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

  ecl_file_close( rst_file );
  ecl_rsthead_free( rst_head );
  exit(0);
}