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; }
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); }