00001
00009 #ifndef BS_CALC_WELL_H_
00010 #define BS_CALC_WELL_H_
00011
00012 #include "facility_base.h"
00013 #include "well_controller.h"
00014 #include "well_limit_operation.h"
00015 #include "fi_params.h"
00016 #include "well_type_helper.h"
00017
00018
00019 #include "calc_well_pressure.h"
00020 #include "calc_rho.h"
00021 #include "calc_perf_bhp_base.h"
00022 #include "calc_perf_density_base.h"
00023 #include "well_rate_control.h"
00024 #include "array_ext.h"
00025
00026 namespace blue_sky
00027 {
00028
00030
00031 class physical_constants;
00032
00033 template <typename strategy_t>
00034 class calc_model;
00035
00036 namespace wells
00037 {
00038 template <typename strategy_t>
00039 class connection;
00040
00041 namespace compute_factors
00042 {
00043 template <typename strategy_t>
00044 struct peaceman_model;
00045
00046 template <typename strategy_t>
00047 struct baby_odeh_model;
00048 }
00049 }
00051
00053
00057 enum well_state_type
00058 {
00059 well_open,
00060 well_shut,
00061
00062 well_state_total,
00063 };
00064
00065 well_state_type
00066 well_state_cast (const std::string &str);
00068
00073 template <typename strategy_t>
00074 struct well_state
00075 {
00076 auto_value <well_state_type, well_open> state;
00077 auto_value <bool, false> is_work;
00078 };
00079
00084 template <typename strategy_t>
00085 class BS_API_PLUGIN well : public facility_base<strategy_t>
00086 {
00087 public:
00088
00089 typedef well <strategy_t> well_t;
00090 typedef typename strategy_t::item_array_t item_array_t;
00091 typedef typename strategy_t::rhs_item_array_t rhs_item_array_t;
00092 typedef typename strategy_t::index_array_t index_array_t;
00093 typedef typename strategy_t::index_t index_t;
00094 typedef typename strategy_t::item_t item_t;
00095 typedef typename strategy_t::rhs_item_t rhs_item_t;
00096
00097 typedef rate_data <strategy_t> rate_data_t;
00098 typedef typename rate_data_t::rate_data_inner rate_data_inner_t;
00099 typedef well_state <strategy_t> well_state_t;
00100
00101 typedef wells::well_controller <strategy_t> well_controller_t;
00102 typedef wells::well_rate_control <strategy_t> well_rate_control_t;
00103 typedef calc_model <strategy_t> calc_model_t;
00104 typedef calc_model_data <strategy_t> calc_model_data_t;
00105 typedef wells::connection <strategy_t> connection_t;
00106 typedef rs_mesh_iface <strategy_t> mesh_iface_t;
00107 typedef jacobian_matrix <strategy_t> jacobian_matrix_t;
00108
00109 typedef pvt_oil <strategy_t> pvt_oil_t;
00110 typedef pvt_dead_oil <strategy_t> pvt_dead_oil_t;
00111 typedef pvt_gas <strategy_t> pvt_gas_t;
00112 typedef pvt_water <strategy_t> pvt_water_t;
00113
00114 typedef calc_well_pressure_base <strategy_t> calc_well_pressure_t;
00115 typedef calc_rho_base <strategy_t> calc_rho_base_t;
00116 typedef calc_perf_density_base <strategy_t> calc_perf_density_t;
00117 typedef calc_perf_bhp_base <strategy_t> calc_perf_bhp_t;
00118
00119 typedef smart_ptr <well_controller_t, true> sp_well_controller_t;
00120 typedef smart_ptr <wells::well_limit_operation, true> sp_well_limit_operation_t;
00121 typedef smart_ptr <calc_model_t, true> sp_calc_model_t;
00122 typedef smart_ptr <mesh_iface_t, true> sp_mesh_iface_t;
00123 typedef smart_ptr <well_t, true> sp_well_t;
00124
00125 typedef smart_ptr <pvt_oil_t, true> sp_pvt_oil_t;
00126 typedef smart_ptr <pvt_dead_oil_t, true> sp_pvt_dead_oil_t;
00127 typedef smart_ptr <pvt_gas_t, true> sp_pvt_gas_t;
00128 typedef smart_ptr <pvt_water_t, true> sp_pvt_water_t;
00129
00130 typedef smart_ptr <jacobian_matrix_t, true> sp_jmatrix_t;
00131 typedef smart_ptr <connection_t, true> sp_connection_t;
00132
00133 typedef smart_ptr <calc_well_pressure_t, true> sp_calc_well_pressure_t;
00134 typedef smart_ptr <calc_rho_base_t, true> sp_calc_rho_t;
00135 typedef smart_ptr <calc_perf_density_t, true> sp_calc_perf_density_t;
00136 typedef smart_ptr <calc_perf_bhp_t, true> sp_calc_perf_bhp_t;
00137
00138 typedef smart_ptr <fi_params, true> sp_params_t;
00139
00140 public:
00149 virtual sp_connection_t
00150 add_connection (index_t i_coord, index_t j_coord, index_t k_coord, index_t n_block)
00151 {
00152 bs_throw_exception ("PURE CALL");
00153 }
00159 virtual sp_connection_t
00160 get_connection (index_t idx) const
00161 {
00162 bs_throw_exception ("PURE CALL");
00163 }
00169 virtual sp_connection_t
00170 get_connection_map (index_t n_block) const
00171 {
00172 bs_throw_exception ("PURE CALL");
00173 }
00178 virtual size_t
00179 get_connections_count () const
00180 {
00181 bs_throw_exception ("PURE CALL");
00182 }
00183
00189 void
00190 set_coord (index_t i_coord, index_t j_coord);
00191
00196 void
00197 set_bhp_depth (item_t bhp_depth);
00198
00204 void
00205 set_state (well_state_type well_state, const sp_calc_model_t &calc_model);
00206
00212 void
00213 set_exploitation_factor (item_t exploitation_factor);
00214
00219 void
00220 set_controller (sp_well_controller_t controller);
00221
00227 void
00228 set_limit_operation (sp_well_limit_operation_t limit_operation);
00229
00234 sp_well_controller_t
00235 get_controller () const;
00236
00241 sp_well_limit_operation_t
00242 get_limit_operation () const;
00243
00248 const std::string &
00249 get_name () const;
00250
00255 void
00256 set_name (const std::string &name);
00257
00262 item_t
00263 get_bhp_depth () const
00264 {
00265 return bhp_depth_;
00266 }
00267
00272 item_t
00273 bhp () const
00274 {
00275 return bhp_;
00276 }
00277
00282 const rate_data_t &
00283 rate () const
00284 {
00285 return rate_;
00286 }
00291 const rate_data_t &
00292 rate_total () const
00293 {
00294 return rate_total_;
00295 }
00296
00301 const rate_data_inner_t &
00302 rate_prod () const
00303 {
00304 return rate_.prod;
00305 }
00310 const rate_data_inner_t &
00311 rate_inj () const
00312 {
00313 return rate_.inj;
00314 }
00315
00320 bool
00321 is_open () const
00322 {
00323 if (well_state_.state == well_open)
00324 return true;
00325 return false;
00326 }
00327
00332 const std::string &
00333 name () const;
00334
00339 void
00340 set_bhp (item_t bhp);
00341
00345 bool
00346 fi_check_limits () const;
00347
00353 item_t
00354 get_reference_depth (const sp_mesh_iface_t &mesh) const;
00355
00360 item_t
00361 get_reference_pressure () const;
00362
00368 bool
00369 check_connections_bhp (const item_array_t &pressure) const;
00370
00375 bool
00376 is_bhp () const;
00377
00382 bool
00383 is_rate () const;
00384
00389 bool
00390 is_shut () const;
00391
00396 const sp_well_controller_t &
00397 get_well_controller () const;
00398
00403 item_t
00404 get_input_rate () const;
00405
00412 bool
00413 check_shut (const sp_calc_model_t &calc_model);
00414
00418 void
00419 reset_init_approx ();
00420
00425 virtual array_ext <item_t>
00426 get_ww_value ();
00427
00432 virtual array_ext <item_t>
00433 get_bw_value ();
00434
00443 virtual void
00444 eliminate (rhs_item_t *array, index_t rw_index, index_t wr_index, double dt, index_t block_size) const;
00445
00455 virtual void
00456 process (bool is_start, double dt, const sp_calc_model_t &calc_model, const sp_mesh_iface_t &mesh, sp_jmatrix_t &jmatrix);
00457
00461 virtual void
00462 clear_data ();
00463
00468 virtual void
00469 fill_rows (index_array_t &rows) const;
00470
00481 virtual void
00482 fill_jacobian (double dt, index_t block_size, const index_array_t &rows, index_array_t &cols, rhs_item_array_t &values, index_array_t &markers) const;
00483
00493 virtual void
00494 fill_rhs (double dt, index_t n_phases, bool is_g, bool is_o, bool is_w, rhs_item_array_t &rhs) const;
00495
00503 virtual void
00504 restore_solution (double dt, const item_array_t &p_sol, const item_array_t &s_sol, index_t block_size);
00505
00511 virtual void
00512 custom_init (const sp_calc_model_t &mdl);
00513
00519 virtual void
00520 pre_large_step (const sp_calc_model_t &calc_model, const sp_mesh_iface_t &mesh);
00521
00525 virtual void
00526 pre_small_step ();
00527
00531 virtual void
00532 pre_newton_step ();
00533
00537 virtual void
00538 restart_small_step ();
00539
00543 virtual void
00544 restart_newton_step ();
00545
00549 virtual ~well ();
00550
00556 well (const std::string &well_name);
00557
00558 public:
00560 BLUE_SKY_TYPE_DECL_T (well <strategy_t>);
00561
00562 protected:
00563
00570 void
00571 shut_well (const sp_calc_model_t &well);
00572
00582 void
00583 compute_connection_factor (const physical_constants &internal_constants,
00584 const sp_params_t ¶ms,
00585 const sp_mesh_iface_t &mesh,
00586 const item_array_t &perm,
00587 const item_array_t &ntg,
00588 bool ro_calc_flag);
00589
00590 public:
00591
00592 std::string name_;
00593
00594 auto_value <index_t, -1> i_coord_;
00595 auto_value <index_t, -1> j_coord_;
00596
00597 sp_well_controller_t well_controller_;
00598
00599
00600 public:
00601 auto_value <item_t, -1> bhp_depth_;
00602 auto_value <item_t, 1> exploitation_factor_;
00603
00604 well_state_t well_state_;
00605 well_state_t saved_well_state_;
00606 well_state_t saved_niter_well_state_;
00607
00608 sp_well_limit_operation_t well_limit_operation_;
00609
00610 rate_data_t rate_;
00611 rate_data_t rate_total_;
00612 rate_data_t rate_rc_;
00613
00614 item_t bhp_;
00615 item_t gor_;
00616
00617 protected:
00618
00619 auto_value <bool, false> init_approx_is_calc_;
00620 auto_value <item_t> input_reference_depth_;
00621
00622 sp_calc_well_pressure_t calc_well_pressure_;
00623 sp_calc_rho_t calc_rho_;
00624 sp_calc_perf_density_t calc_perf_density_;
00625 sp_calc_perf_bhp_t calc_perf_bhp_;
00626
00627 protected:
00628 index_array_t open_connections_;
00629 };
00630
00637 template <typename strategy_t>
00638 class BS_API_PLUGIN well_factory : public objbase
00639 {
00640 public:
00641
00642 typedef well <strategy_t> well_t;
00643 typedef wells::connection <strategy_t> connection_t;
00644 typedef smart_ptr <well_t> sp_well_t;
00645 typedef smart_ptr <connection_t, true> sp_connection_t;
00646
00647 public:
00648
00652 virtual ~well_factory () {}
00653
00660 virtual sp_well_t
00661 create_well (const std::string &group_name, const std::string &well_name) const;
00662
00666 virtual sp_connection_t
00667 create_connection () const;
00668
00670 BLUE_SKY_TYPE_DECL_T (well_factory <strategy_t>);
00671 };
00672
00678 bool
00679 calc_well_register_types (const blue_sky::plugin_descriptor &pd);
00680
00686 bool
00687 well_factory_register_type (const blue_sky::plugin_descriptor &pd);
00688
00689 }
00690
00691
00692 #endif // #ifndef BS_CALC_WELL_H_