00001
00011 #ifndef BS_WELLS_WELL_RATE_CONTROL_CONNECTION_LOOP_H_
00012 #define BS_WELLS_WELL_RATE_CONTROL_CONNECTION_LOOP_H_
00013
00014 namespace blue_sky
00015 {
00016
00017 template <typename params_t, typename inj_inner_loop_t, typename prod_inner_loop_t>
00018 inline void
00019 connection_loop (params_t ¶ms, const inj_inner_loop_t &inj_inner_loop, const prod_inner_loop_t &prod_inner_loop)
00020 {
00021 BS_ASSERT (!params.well_->is_shut ()) (params.well_->name ());
00022 if (!params.well_->get_connections_count ())
00023 {
00024 BOSOUT (section::wells, level::debug)
00025 << "[" << params.well_->name () << "] connection loop: connection list is empty"
00026 << bs_end;
00027
00028 return ;
00029 }
00030
00031 typedef typename params_t::sp_connection_t sp_connection_t;
00032 typedef typename params_t::data_t data_t;
00033
00034 params.depth = params.well_->get_connection (0)->connection_depth;
00035 for (size_t i = 0, cnt = params.well_->get_connections_count (); i < cnt; ++i)
00036 {
00037 const sp_connection_t &c (params.well_->get_connection (i));
00038 if (c->is_shut ())
00039 {
00040 params.depth = c->connection_depth;
00041 continue;
00042 }
00043
00044 params.n_block = c->n_block ();
00045 params.perf_bhp = c->cur_bhp;
00046 params.diff_depth = c->connection_depth - params.depth;
00047 params.depth = c->connection_depth;
00048 params.rho = c->density;
00049 params.gw = c->get_fact ();
00050 params.main_var = params.main_vars[params.n_block];
00051 const data_t &data = params.data_array[params.n_block];
00052
00053
00054 compute_potentials (data, params);
00055
00056
00057
00058 if (is_prod_potential (params))
00059 {
00060 prod_inner_loop (c, data, params);
00061 }
00062 else
00063 {
00064 params.compute_perf_vars (data, params.inj_params_);
00065 inj_inner_loop (c, data, params);
00066 }
00067 }
00068 }
00069
00070 template <typename params_t, typename inner_loop_t>
00071 inline void
00072 update_wr_connection_loop (params_t ¶ms, const inner_loop_t &inner_loop)
00073 {
00074 BS_ASSERT (!params.well_->is_shut ()) (params.well_->name ());
00075 if (!params.well_->get_connections_count ())
00076 {
00077 BOSOUT (section::wells, level::debug)
00078 << "[" << params.well_->name () << "] connection loop: connection list is empty"
00079 << bs_end;
00080
00081 return ;
00082 }
00083
00084 typedef typename params_t::sp_connection_t sp_connection_t;
00085 typedef typename params_t::item_t item_t;
00086
00087
00088 item_t ww = params.ww_value[0];
00089 if (fabs (ww) >= 10e-16)
00090 {
00091 ww = 1.0 / ww;
00092 }
00093
00094 for (size_t i = 0, cnt = params.well_->get_connections_count (); i < cnt; ++i)
00095 {
00096 const sp_connection_t &c (params.well_->get_connection (i));
00097 if (c->is_shut ())
00098 continue;
00099
00100 inner_loop (c, ww);
00101 }
00102 }
00103
00104 template <typename params_t, typename inner_loop_t>
00105 inline void
00106 apply_wefac_connection_loop (params_t ¶ms, const inner_loop_t &inner_loop)
00107 {
00108 BS_ASSERT (!params.well_->is_shut ()) (params.well_->name ());
00109 if (!params.well_->get_connections_count ())
00110 {
00111 BOSOUT (section::wells, level::debug)
00112 << "[" << params.well_->name () << "] connection loop: connection list is empty"
00113 << bs_end;
00114
00115 return ;
00116 }
00117
00118 typedef typename params_t::sp_connection_t sp_connection_t;
00119 typedef typename params_t::item_t item_t;
00120
00121 for (size_t i = 0, cnt = params.well_->get_connections_count (); i < cnt; ++i)
00122 {
00123 const sp_connection_t &c (params.well_->get_connection (i));
00124 if (c->is_shut ())
00125 continue;
00126
00127 inner_loop (c, params);
00128 }
00129
00130 }
00131
00132 }
00133
00134
00135 #endif // #ifndef BS_WELLS_WELL_RATE_CONTROL_CONNECTION_LOOP_H_
00136