00001
00009 #ifndef BS_WELL_CONTROLLER_H_
00010 #define BS_WELL_CONTROLLER_H_
00011
00012 #include "well_type_helper.h"
00013 #include "rate_control_type.h"
00014 #include "well_rate_control_interface.h"
00015
00016 namespace blue_sky
00017 {
00018
00019 template <typename strategy_t>
00020 class well;
00021
00022 template <typename strategy_t>
00023 class calc_model;
00024
00025 template <typename strategy_t>
00026 struct calc_model_data;
00027
00032 template <typename strategy_t>
00033 struct rate_data
00034 {
00035 typedef typename strategy_t::item_t item_t;
00036
00042 struct rate_data_inner
00043 {
00044 item_t oil;
00045 item_t water;
00046 item_t gas;
00047 item_t liquid;
00048
00050 rate_data_inner ()
00051 : oil (0)
00052 , water (0)
00053 , gas (0)
00054 , liquid (0)
00055 {
00056 }
00057
00059 void
00060 operator= (item_t value)
00061 {
00062 oil = value;
00063 water = value;
00064 gas = value;
00065 liquid = value;
00066 }
00067
00069 void
00070 operator+= (const rate_data_inner &rhs)
00071 {
00072 oil += rhs.oil;
00073 water += rhs.water;
00074 gas += rhs.gas;
00075 liquid += rhs.liquid;
00076 }
00077
00083 rate_data_inner
00084 operator * (item_t mult) const
00085 {
00086 rate_data_inner r;
00087 r.oil = mult * oil;
00088 r.water = mult * water;
00089 r.gas = mult * gas;
00090 r.liquid = mult * liquid;
00091
00092 return r;
00093 }
00094 };
00095
00097 rate_data ()
00098 : liquid_inner (0)
00099 , free_gas (0)
00100 , solution_gas (0)
00101 {
00102 }
00103
00109 rate_data <strategy_t> &
00110 operator= (item_t value)
00111 {
00112 prod = value;
00113 inj = value;
00114 liquid_inner = value;
00115 free_gas = value;
00116 solution_gas = value;
00117
00118 return *this;
00119 }
00120
00125 void
00126 operator += (const rate_data <strategy_t> &rhs)
00127 {
00128 prod += rhs.prod;
00129 inj += rhs.inj;
00130 liquid_inner += rhs.liquid_inner;
00131 free_gas += rhs.free_gas;
00132 solution_gas += rhs.solution_gas;
00133 }
00134
00140 rate_data
00141 operator * (item_t mult) const
00142 {
00143 rate_data r;
00144 r.prod = prod * mult;
00145 r.inj = inj * mult;
00146 r.liquid_inner = liquid_inner * mult;
00147 r.free_gas = free_gas * mult;
00148 r.solution_gas = solution_gas * mult;
00149
00150 return r;
00151 }
00152
00153 rate_data_inner prod;
00154 rate_data_inner inj;
00155
00156 item_t liquid_inner;
00157 item_t free_gas;
00158 item_t solution_gas;
00159 };
00160
00161 namespace wells
00162 {
00163
00164 template <typename strategy_t>
00165 class well_controller;
00166
00167 template <typename strategy_t>
00168 class connection;
00169
00170 template <typename strategy_t>
00171 class well_rate_control;
00172
00174
00176
00180 enum rate_value_type
00181 {
00182 null_value = 0,
00183 oil_rate_value = 1,
00184 water_rate_value = 2,
00185 liquid_rate_value = 3,
00186 gas_rate_value = 4,
00187 rate_value = 5,
00188 bhp_value = 8,
00189 liquid_inner_rate_value = 9,
00190 };
00191
00197 bool
00198 is_oil_rate_value (rate_value_type type);
00199
00205 bool
00206 is_water_rate_value (rate_value_type type);
00207
00213 bool
00214 is_gas_rate_value (rate_value_type type);
00215
00223 bool
00224 is_liquid_rate_value (rate_value_type type);
00225
00232 rate_value_type
00233 rate_value_cast (const std::string &str);
00235
00237
00241 enum injection_type
00242 {
00243 injection_none,
00244 injection_water,
00245 injection_gas,
00246 injection_oil,
00247 };
00248
00255 injection_type
00256 injection_type_cast (const std::string &str);
00258
00263 template <typename strategy_t>
00264 class BS_API_PLUGIN well_controller : public objbase
00265 {
00266 public:
00267
00268 typedef typename strategy_t::item_t item_t;
00269 typedef typename strategy_t::index_t index_t;
00270 typedef typename strategy_t::item_array_t item_array_t;
00271 typedef typename strategy_t::index_array_t index_array_t;
00272 typedef well_rate_control <strategy_t> well_rate_control_t;
00273 typedef well <strategy_t> well_t;
00274 typedef connection <strategy_t> connection_t;
00275 typedef jacobian_matrix <strategy_t> jacobian_matrix_t;
00276 typedef well_controller <strategy_t> this_t;
00277 typedef calc_model <strategy_t> calc_model_t;
00278
00279 typedef rate_data <strategy_t> rate_data_t;
00280
00281 typedef smart_ptr <calc_model_t, true> sp_calc_model_t;
00282 typedef smart_ptr <jacobian_matrix_t, true> sp_jmatrix_t;
00283 typedef smart_ptr <well_t, true> sp_well_t;
00284
00285 typedef smart_ptr <well_rate_control_t, true> sp_rate_control_t;
00286 typedef smart_ptr <connection_t, true> sp_connection_t;
00287 typedef smart_ptr <jacobian_matrix_t, true> sp_jacobian_matrix_t;
00288 typedef smart_ptr <this_t, true> sp_this_t;
00289
00290 typedef wells::type_helper <strategy_t> helper_t;
00291
00292 typedef typename helper_t::item_rhs_block_t item_rhs_block_t;
00293 typedef typename helper_t::item_ww_block_t item_ww_block_t;
00294 typedef typename helper_t::item_q_rate_t item_q_rate_t;
00295 typedef typename helper_t::item_q_rate_inflow_t item_q_rate_inflow_t;
00296 typedef typename helper_t::item_gas_rate_t item_gas_rate_t;
00297
00298 public:
00300 virtual ~well_controller () {}
00301
00303 void
00304 clear_rate ();
00305
00311 void
00312 set_rate (rate_value_type rate_value, item_t value);
00313
00318 void
00319 set_bhp (item_t value);
00320
00325 void
00326 set_bhp_history (item_t value);
00327
00332 void
00333 add_bhp_control (const sp_rate_control_t &bhp_control);
00334
00339 void
00340 add_rate_control (const sp_rate_control_t &rate_control);
00341
00347 void
00348 set_main_control (const sp_well_t &well, rate_control_type control);
00349
00354 void
00355 set_injection_type (injection_type type);
00356
00361 const rate_data_t &
00362 rate () const;
00363
00368 const item_t &
00369 bhp () const;
00370
00375 const item_t &
00376 bhp_history () const;
00377
00382 const injection_type &
00383 injection () const;
00384
00389 bool
00390 is_bhp () const;
00391
00396 bool
00397 is_rate () const;
00398
00403 bool
00404 is_production () const;
00405
00412 bool
00413 is_valid_connection_bhp (item_t pressure, item_t bhp) const;
00414
00418 void
00419 save_control ();
00424 bool
00425 restore_control ();
00429 void
00430 save_niter_control ();
00435 bool
00436 restore_niter_control ();
00437
00442 void
00443 switch_to_bhp (sp_well_t &well);
00449 bool
00450 check (sp_well_t &well);
00451
00456 void
00457 calc_rate (const sp_calc_model_t &calc_model, sp_well_t &well, sp_jmatrix_t &jmatrix) const;
00462 void
00463 calc_derivs (const sp_calc_model_t &calc_model, sp_well_t &well, sp_jmatrix_t &jmatrix) const;
00464
00469 rate_control_type
00470 get_control_type () const;
00471
00473 BLUE_SKY_TYPE_DECL_T (well_controller);
00474
00475 public:
00476 rate_data_t rate_;
00477
00478 private:
00479 item_t bhp_;
00480 item_t bhp_history_;
00481
00482 injection_type injection_type_;
00483
00484 static sp_rate_control_t dummy_control_;
00485 sp_rate_control_t bhp_control_;
00486 sp_rate_control_t rate_control_;
00487
00488 sp_rate_control_t current_control_;
00489 sp_rate_control_t saved_control_;
00490 sp_rate_control_t saved_niter_control_;
00491 };
00492
00498 template <typename strategy_t>
00499 class BS_API_PLUGIN well_controller_factory : public objbase
00500 {
00501 public:
00502
00503 typedef calc_model <strategy_t> calc_model_t;
00504 typedef well_controller <strategy_t> well_controller_t;
00505 typedef well_rate_control <strategy_t> well_rate_control_t;
00506 typedef well_rate_control_factory <strategy_t> well_rate_control_factory_t;
00507
00508 typedef smart_ptr <calc_model_t, true> sp_calc_model_t;
00509 typedef smart_ptr <well_controller_t, true> sp_well_controller_t;
00510 typedef smart_ptr <well_rate_control_t, true> sp_rate_control_t;
00511 typedef smart_ptr <well_rate_control_factory_t, true> sp_well_rate_control_factory_t;
00512
00513 public:
00514
00516 virtual ~well_controller_factory () {};
00517
00522 void
00523 set_rate_control_factory (const sp_well_rate_control_factory_t &rate_control_factory);
00524
00529 virtual sp_well_controller_t
00530 create_controller () const;
00531
00539 virtual sp_rate_control_t
00540 create_control (rate_control_type rate_control, bool is_prod, const sp_calc_model_t &calc_model) const;
00541
00543 BLUE_SKY_TYPE_DECL_T (well_controller_factory);
00544
00545 private:
00546
00547 sp_well_rate_control_factory_t well_rate_control_factory_;
00548 };
00549
00555 bool
00556 well_controller_register_type (const blue_sky::plugin_descriptor &pd);
00557
00563 bool
00564 well_controller_factory_register_type (const blue_sky::plugin_descriptor &pd);
00565
00566
00567 }
00568 }
00569
00570
00571 #endif // #ifnded BS_WELL_CONTROLLER_H_
00572