00001
00010 #ifndef BS_RESERVOIR_H_
00011 #define BS_RESERVOIR_H_
00012
00013 #include "calc_well.h"
00014 #include "event_filter.h"
00015 #include "jacobian.h"
00016
00017 #ifdef _HDF5
00018 #include "bs_hdf5_storage.h"
00019 #include "rs_smesh_iface.h"
00020 #endif
00021
00022 namespace blue_sky
00023 {
00024
00025 template <typename strategy_t>
00026 class calc_model;
00027
00028 template <typename strategy_t>
00029 class reservoir_simulator;
00030
00031 template <typename strategy_t>
00032 class facility_manager;
00033
00034 template <typename strategy_t>
00035 class well;
00036
00037 template <typename strategy_t>
00038 class well_factory;
00039
00040 class data_storage_interface;
00041
00042 class fi_params;
00043
00044 namespace wells
00045 {
00046 template <typename strategy_t>
00047 class well_controller;
00048
00049 template <typename strategy_t>
00050 class well_rate_control;
00051
00052 template <typename strategy_t>
00053 class connection;
00054
00055 template <typename strategy_t>
00056 class well_controller_factory;
00057
00058 class well_limit_operation_factory;
00059
00060 class well_limit_operation;
00061 }
00062
00068 template <typename strategy_t>
00069 class BS_API_PLUGIN reservoir : public objbase
00070 {
00071 public:
00072
00073 typedef typename strategy_t::item_t item_t;
00074 typedef typename strategy_t::index_t index_t;
00075 typedef typename strategy_t::item_array_t item_array_t;
00076 typedef typename strategy_t::rhs_item_array_t rhs_item_array_t;
00077 typedef typename strategy_t::index_array_t index_array_t;
00078
00079 typedef facility_base <strategy_t> facility_t;
00080 typedef well <strategy_t> well_t;
00081 typedef wells::well_controller <strategy_t> well_controller_t;
00082 typedef wells::well_limit_operation well_limit_operation_t;
00083 typedef wells::well_rate_control <strategy_t> well_rate_control_t;
00084 typedef wells::connection <strategy_t> connection_t;
00085 typedef facility_manager <strategy_t> facility_manager_t;
00086 typedef wells::well_controller_factory <strategy_t> controller_factory_t;
00087 typedef wells::well_limit_operation_factory limit_operation_factory_t;
00088 typedef well_factory <strategy_t> well_factory_t;
00089 typedef calc_model <strategy_t> calc_model_t;
00090 typedef rs_mesh_iface <strategy_t> mesh_iface_t;
00091 typedef jacobian <strategy_t> jacobian_t;
00092 typedef jacobian_matrix <strategy_t> jacobian_matrix_t;
00093
00094 typedef reservoir_simulator <strategy_t> reservoir_simulator_t;
00095 typedef rate_data <strategy_t> rate_data_t;
00096 typedef typename rate_data_t::rate_data_inner rate_data_inner_t;
00097
00098 typedef smart_ptr <reservoir_simulator_t, true> sp_top_t;
00099
00100 typedef smart_ptr <well_t, true> sp_well_t;
00101 typedef smart_ptr <well_controller_t, true> sp_well_controller_t;
00102 typedef smart_ptr <well_limit_operation_t, true> sp_well_limit_operation_t;
00103 typedef smart_ptr <well_rate_control_t, true> sp_rate_control_t;
00104 typedef smart_ptr <connection_t, true> sp_connection_t;
00105 typedef smart_ptr <mesh_iface_t, true> sp_mesh_iface_t;
00106 typedef smart_ptr <calc_model_t, true> sp_calc_model_t;
00107 typedef smart_ptr <jacobian_t, true> sp_jacobian_t;
00108 typedef smart_ptr <jacobian_matrix_t, true> sp_jacobian_matrix_t;
00109 typedef smart_ptr <jacobian_matrix_t, true> sp_jmatrix_t;
00110
00111 typedef smart_ptr <facility_manager_t, true> sp_facility_manager_t;
00112 typedef smart_ptr <data_storage_interface, true> sp_storage_t;
00113
00114 typedef smart_ptr <controller_factory_t, true> sp_well_controller_factory_t;
00115 typedef smart_ptr <limit_operation_factory_t, true> sp_well_limit_operation_factory_t;
00116 typedef smart_ptr <well_factory_t, true> sp_well_factory_t;
00117
00118 typedef smart_ptr <fi_params, true> sp_params_t;
00119 typedef smart_ptr <event_filter, true> sp_event_filter_t;
00120
00121 #ifdef _HDF5
00122 typedef smart_ptr <bs_hdf5_storage, true> sp_bs_hdf5_storage;
00123 #endif
00124
00125 public:
00126
00128 BLUE_SKY_TYPE_DECL_T (reservoir <strategy_t>);
00129
00133 ~reservoir ();
00134
00135 public:
00136
00143 sp_well_t
00144 get_well (const std::string &group_name, const std::string &well_name) const;
00145
00151 sp_well_t
00152 get_well (const std::string &well_name) const;
00153
00160 sp_well_t
00161 create_well (const std::string &group_name, const std::string &well_name);
00162
00168 sp_well_controller_t
00169 create_well_controller (const sp_well_t &owner_well);
00170
00177 sp_well_limit_operation_t
00178 create_well_limit_operation (const sp_well_t &owner_well, wells::limit_operation_type operation);
00179
00184 sp_connection_t
00185 create_connection ();
00186
00193 sp_rate_control_t
00194 create_bhp_control (bool is_prod, const sp_calc_model_t &calc_model);
00195
00203 sp_rate_control_t
00204 create_rate_control (bool is_prod, wells::rate_control_type control_type, const sp_calc_model_t &calc_model);
00205
00210 void
00211 save_data (const sp_storage_t &storage) const;
00212
00216 item_t
00217 pressure () const;
00218
00222 bool
00223 check_limits (const sp_params_t ¶ms) const;
00224
00230 void
00231 pre_large_step (const sp_calc_model_t &calc_model, const sp_mesh_iface_t &mesh);
00232
00236 void
00237 pre_small_step ();
00238
00242 void
00243 pre_newton_step ();
00244
00248 void
00249 restart_small_step ();
00250
00254 void
00255 restart_newton_step ();
00256
00262 void
00263 init_jacobian (const sp_jmatrix_t &jmx, index_t n_cells);
00264
00272 void
00273 end_jacobian (item_t dt, const sp_calc_model_t &calc_model, sp_jacobian_t &jacobian);
00274
00282 void
00283 restore_wells_solution (double dt, const item_array_t &p_sol, const item_array_t &s_sol, index_t block_size);
00284
00294 void
00295 calc_wells (int istart, double dt, const sp_calc_model_t &calc_model, const sp_mesh_iface_t &mesh, sp_jmatrix_t &jmatrix);
00296
00304 void
00305 fill_rhs_wells (double dt, const sp_calc_model_t &calc_model, rhs_item_array_t &rhs, bool update_after_gauss_elimination) const;
00306
00311 sp_facility_manager_t
00312 get_facility_list () const;
00313
00318 size_t
00319 get_connections_count () const;
00320
00325 void
00326 add_filter_well (const std::string &well_name);
00327
00332 const sp_event_filter_t &
00333 get_event_filter () const;
00334
00339 sp_well_factory_t
00340 get_well_factory () const;
00341
00346 sp_well_controller_factory_t
00347 get_well_controller_factory () const;
00348
00353 sp_well_limit_operation_factory_t
00354 get_well_limit_operation_factory () const;
00355
00360 void
00361 set_well_factory (const sp_well_factory_t &factory);
00362
00367 void
00368 set_well_controller_factory (const sp_well_controller_factory_t &factory);
00369
00374 void
00375 set_well_limit_operation_factory (const sp_well_limit_operation_factory_t &factory);
00376
00377 #ifdef _HDF5
00378
00381 void
00382 open_hdf5_file (const std::string &filename) const;
00383
00387 void
00388 close_hdf5_file () const;
00389
00393 void
00394 write_step_to_hdf5 (const sp_calc_model_t &calc_model, const sp_mesh_iface_t &mesh, const sp_jmatrix_t &jmx, int, int, item_t time) const;
00395
00399 void
00400 write_mesh_to_hdf5 (const smart_ptr <rs_mesh_iface<strategy_t>, true> &mesh) const;
00401
00405 const smart_ptr<bs_hdf5_storage, true>
00406 get_hdf5_file () const {return hdf5;}
00407 #endif
00408
00413 const rate_data_t &
00414 rate () const
00415 {
00416 return rate_;
00417 }
00418
00419 private:
00424 void
00425 init_rows (index_array_t &rows) const;
00426
00427 public:
00428
00429 rate_data_t rate_;
00430 rate_data_t rate_rc_;
00431 rate_data_t rate_wefac_;
00432 rate_data_t rate_rc_wefac_;
00433 rate_data_t rate_initial_;
00434 rate_data_t rate_total_;
00435
00436 private:
00437
00438 sp_facility_manager_t facility_list_;
00439 sp_well_factory_t well_factory_;
00440 sp_well_controller_factory_t well_controller_factory_;
00441 sp_well_limit_operation_factory_t well_limit_operation_factory_;
00442
00443 sp_event_filter_t event_filter_;
00444
00445 index_array_t markers_;
00446
00447 #ifdef _HDF5
00448 sp_bs_hdf5_storage hdf5;
00449 #endif
00450 };
00451
00452
00453 }
00454
00455 #endif // #ifndef BS_RESERVOIR_H_
00456