00001
00009 #ifndef CALC_MODEL_H
00010 #define CALC_MODEL_H
00011
00012 #include BS_FORCE_PLUGIN_IMPORT ()
00013 #include "convert_units.h"
00014 #include "constants.h"
00015 #include "prvd_table.h"
00016 #include "arrays.h"
00017 #include "rocktab_table.h"
00018 #include BS_STOP_PLUGIN_IMPORT ()
00019
00020 #include "fi_params.h"
00021 #include "well_type_helper.h"
00022 #include "norm_calc.h"
00023 #include "array_ext.h"
00024 #include "jacobian.h"
00025
00026 #include "calc_model_data.h"
00027
00028 namespace blue_sky
00029 {
00030
00036 enum restore_solution_return_type
00037 {
00038 SMALL_TIME_STEP_FAIL = -1,
00039 SMALL_TIME_STEP_OK = 0,
00040 SMALL_TIME_STEP_CHOP = 256,
00041 };
00042
00043 template <typename strategy_t>
00044 class calc_model;
00045
00046 template <typename strategy_t>
00047 class well;
00048
00049 template <typename strategy_t>
00050 class reservoir;
00051
00052 namespace wells
00053 {
00054 template <typename strategy_t>
00055 class connection;
00056 }
00057
00058 class well_results_storage;
00059 class fip_results_storage;
00061
00062
00068 template <typename strategy_t>
00069 struct BS_API_PLUGIN calc_model_data_tmp_holder
00070 {
00071 typedef typename strategy_t::item_t item_t;
00072 typedef typename strategy_t::item_array_t item_array_t;
00073
00074 typedef typename strategy_t::template vec <main_var_type>::type main_var_array_t;
00075 typedef calc_model <strategy_t> calc_model_t;
00076 typedef smart_ptr <calc_model_t, true> sp_calc_model_t;
00077
00078 public:
00079
00084 void
00085 save (const sp_calc_model_t &calc_model);
00086
00091 void
00092 restore (sp_calc_model_t &calc_model);
00093
00094 public:
00095 item_array_t pressure;
00096 item_array_t saturation_3p;
00097 item_array_t gas_oil_ratio;
00098 main_var_array_t main_var;
00099 };
00100
00102
00106 template <class strategy_t>
00107 class BS_API_PLUGIN calc_model : public bs_node
00108 {
00109 public:
00110
00111 typedef strategy_t strategy_type;
00112
00113 typedef calc_model<strategy_t> this_t;
00114 typedef smart_ptr<this_t, true> sp_this_t;
00115
00116 typedef jacobian<strategy_t> jacobian_t;
00117 typedef smart_ptr <jacobian_t, true> sp_jacobian_t;
00118 typedef jacobian_matrix <strategy_t> jacobian_matrix_t;
00119 typedef smart_ptr <jacobian_matrix_t, true> sp_jacobian_matrix_t;
00120
00121 typedef idata idata_t;
00122 typedef smart_ptr<idata_t, true> sp_idata_t;
00123
00124 typedef rs_mesh_iface <strategy_t> mesh_iface_t;
00125 typedef smart_ptr <mesh_iface_t, true> sp_mesh_iface_t;
00126
00127 typedef rs_smesh_iface <strategy_t> smesh_iface_t;
00128 typedef smart_ptr <smesh_iface_t, true> sp_smesh_iface_t;
00129
00130 typedef reservoir <strategy_t> reservoir_t;
00131 typedef smart_ptr <reservoir_t, true> sp_reservoir_t;
00132
00133 typedef typename strategy_t::item_array_t item_array_t;
00134 typedef typename strategy_t::index_array_t index_array_t;
00135 typedef typename strategy_t::item_t item_t;
00136 typedef typename strategy_t::index_t index_t;
00137
00138 typedef typename strategy_t::csr_matrix_t csr_matrix_t;
00139 typedef smart_ptr <csr_matrix_t, true> sp_csr_matrix_t;
00140
00141 typedef calc_model_data <strategy_t> data_t;
00142 typedef typename strategy_t::template vec <data_t>::type data_array_t;
00143
00144 typedef scal_3p<strategy_t> scal_3p_t;
00145 typedef scale_array_holder <strategy_t> scale_array_holder_t;
00146
00147 typedef wells::connection <strategy_t> connection_t;
00148 typedef well <strategy_t> well_t;
00149
00150 typedef smart_ptr< scal_3p_t, true> sp_scal3p;
00151 typedef smart_ptr <scale_array_holder_t, true> sp_scale_array_holder_t;
00152
00153 typedef smart_ptr< rock_grid< strategy_t >, true> sp_rock_grid;
00154 typedef smart_ptr< fi_params, true> sp_fi_params;
00155 typedef smart_ptr <connection_t, true> sp_connection_t;
00156 typedef smart_ptr <well_t, true> sp_well_t;
00157
00158 typedef smart_ptr<well_results_storage, true> sp_well_results_storage;
00159 typedef smart_ptr<fip_results_storage, true> sp_fip_results_storage;
00160
00161 typedef pvt_base< strategy_t > pvt_base_t;
00162 typedef pvt_oil < strategy_t > pvt_oil_t;
00163 typedef pvt_dead_oil< strategy_t > pvt_dead_oil_t;
00164 typedef pvt_gas< strategy_t > pvt_gas_t;
00165 typedef pvt_water< strategy_t > pvt_water_t;
00166
00167 typedef smart_ptr <pvt_base_t, true> sp_pvt_t;
00168 typedef smart_ptr <pvt_dead_oil_t, true> sp_pvt_oil;
00169 typedef smart_ptr <pvt_dead_oil_t, true> sp_pvt_dead_oil;
00170 typedef smart_ptr <pvt_gas_t, true> sp_pvt_gas;
00171 typedef smart_ptr <pvt_water_t, true> sp_pvt_water;
00172
00173 typedef std::vector< sp_pvt_t > sp_pvt_array_t;
00174 typedef std::vector< sp_pvt_oil > sp_pvt_oil_array_t;
00175 typedef std::vector< sp_pvt_dead_oil > sp_pvt_dead_oil_array_t;
00176 typedef std::vector< sp_pvt_gas > sp_pvt_gas_array_t;
00177 typedef std::vector< sp_pvt_water > sp_pvt_water_array_t;
00178
00179 typedef std::vector< int > vec_i;
00180
00181 typedef boost::array <index_t, FI_PHASE_TOT> phase_d_t;
00182 typedef boost::array <index_t, FI_PHASE_TOT> sat_d_t;
00183 typedef norms_storage <strategy_t> norms_storage_t;
00184 typedef boost::array <item_t, FI_PHASE_TOT> invers_fvf_avgerage_t;
00185
00187 typedef typename strategy_t::template vec <main_var_type>::type main_var_array_t;
00188
00190 typedef calc_model_data_tmp_holder <strategy_t> calc_model_data_tmp_holder_t;
00191
00192 public:
00193
00197 ~calc_model();
00198
00202 void
00203 init();
00204
00211 const this_t &
00212 operator=(const this_t &src);
00213
00221 int
00222 init_main_arrays (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00223
00231 int
00232 init_calcul_arrays (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00233
00241 int
00242 set_initial_data (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00243
00251 int
00252 calc_equil (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00253
00271 int
00272 equil_calc_pressure (item_t prev_press, item_t cur_d, item_t h, index_t phase, index_t i_pvt,
00273 double rs_type, item_t depth_goc, item_t rs_dat,
00274 val_vs_depth *rsvd, val_vs_depth *pbvd,
00275 item_t &p, item_t *rs = 0);
00276
00284 int
00285 init_pressure (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00286
00294 int
00295 init_saturation (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00296
00304 int
00305 init_rs (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00306
00307
00311 void
00312 init_scal ();
00313
00322 void
00323 init_pvt_arrays (sp_pvt_oil_array_t &pvto_,
00324 sp_pvt_gas_array_t &pvtg_,
00325 sp_pvt_water_array_t &pvtw_,
00326 const sp_idata_t &idata_);
00327
00334 static bool
00335 is_water_phase (int phases)
00336 {
00337 return FI_CHK_WATER (phases);
00338 }
00345 static bool
00346 is_gas_phase (int phases)
00347 {
00348 return FI_CHK_GAS (phases);
00349 }
00356 static bool
00357 is_oil_phase (int phases)
00358 {
00359 return FI_CHK_OIL (phases);
00360 }
00361
00367 const data_t &
00368 get_data (index_t n_block) const
00369 {
00370 return data[n_block];
00371 }
00372
00376 item_t
00377 get_initial_rho (item_t height) const;
00378
00382 void
00383 update_min_pressure_range (item_t min_range);
00384
00388 void
00389 update_max_pressure_range (item_t max_range);
00390
00396 void
00397 calc_prev_fluid_volume (bool istart, const sp_mesh_iface_t &mesh);
00398
00405 restore_solution_return_type
00406 restore_solution (const sp_mesh_iface_t &mesh, const sp_jacobian_matrix_t &jacobian_mx);
00407
00416 restore_solution_return_type
00417 apply_newton_correction (item_t mult, index_t istart_line_search, const sp_mesh_iface_t &mesh, const sp_jacobian_matrix_t &jacobian_mx);
00418
00425 item_t
00426 new_simple_get_cell_solution_mult (const sp_mesh_iface_t &mesh, const sp_jacobian_matrix_t &jacobian_mx);
00427
00434 item_t
00435 new_simple_get_cell_solution_mult_2 (const sp_mesh_iface_t &mesh, const sp_jacobian_matrix_t &jmatrix) const;
00436
00444 int
00445 new_simple_get_cell_solution (const double mult, int istart_linear_search, const sp_mesh_iface_t &msh, const sp_jacobian_matrix_t &jacobian_mx);
00446
00462 int
00463 calc_approx_so_sg_ro (const item_t mo_in, const item_t mg_in, const item_t poro,
00464 const item_t ifvf_o, const item_t ifvf_g, const item_t max_ro,
00465
00466 item_t &so, item_t &sg, item_t &ro,
00467 main_var_type &m_var);
00468
00474 void
00475 init_jacobian (const sp_jacobian_t &input_data, const sp_mesh_iface_t &mesh);
00476
00477
00483 bool
00484 is_water () const;
00485
00491 bool
00492 is_gas () const;
00493
00499 bool
00500 is_oil () const;
00501
00506 index_t
00507 water_shift () const;
00508
00513 index_t
00514 gas_shift () const;
00515
00520 index_t
00521 oil_shift () const;
00522
00523
00525 BLUE_SKY_TYPE_DECL_T (calc_model);
00526
00527 private:
00528
00532 void
00533 init_boundary_connections (const sp_idata_t &input_data, const sp_mesh_iface_t &mesh);
00534
00535
00536 public:
00537
00538 main_var_array_t main_variable;
00539 auto_value <well_model_var_type, WELL_MODEL_3VAR> well_model_var_;
00540 auto_value <well_model_type, BLACK_OIL> well_model_type_;
00541 norms_storage_t norm;
00542
00543 sp_pvt_dead_oil_array_t pvt_oil_array;
00544 sp_pvt_water_array_t pvt_water_array;
00545 sp_pvt_gas_array_t pvt_gas_array;
00546
00547 data_array_t data;
00548
00549 item_array_t workspace;
00550
00551 calc_model_data_tmp_holder_t old_data_;
00552 calc_model_data_tmp_holder_t prev_niter_data_;
00553
00555 item_array_t bconn_pressure;
00556 item_array_t bconn_saturation;
00557 item_array_t bconn_gor;
00558 index_array_t bconn_mainvar;
00559
00560 auto_value <item_t> linear_search_mult;
00561 auto_value <bool> lsearch_force_newton_step;
00562
00563 auto_value <int> b_w_w;
00564 auto_value <int> b_w_g;
00565 auto_value <int> b_w_p;
00566 auto_value <int> b_g_w;
00567 auto_value <int> b_g_g;
00568 auto_value <int> b_g_p;
00569 auto_value <int> b_o_w;
00570 auto_value <int> b_o_g;
00571 auto_value <int> b_o_p;
00572 index_array_t iwksp;
00573 auto_value <int> multi_well_in_cell_flag;
00574
00575 auto_value <double> ave_volume;
00576
00577 index_array_t max_norm_counter;
00578
00580 public:
00581
00582 auto_value <int> n_comps;
00583 auto_value <int> n_phases;
00584 auto_value <int> n_sec_vars;
00585 auto_value <FI_PHASE_ENUM> phases;
00586 auto_value <int> n_HCcomps;
00587 auto_value <int> n_HCphases;
00588 auto_value <int> n_pri;
00589 auto_value <int> n_sec;
00590 auto_value <int> n_vars;
00591
00592 phase_d_t phase_d;
00593 sat_d_t sat_d;
00594
00595 auto_value <int> n_pvt_regions;
00596 auto_value <int> n_sat_regions;
00597 auto_value <int> n_fip_regions;
00598
00599 physical_constants internal_constants;
00600
00601 index_array_t pvt_regions;
00602 index_array_t sat_regions;
00603 index_array_t fip_regions;
00604 index_array_t rock_regions;
00605
00606 auto_value <RPO_MODEL_ENUM, RPO_DEFAULT_MODEL> rpo_model;
00607 sp_scal3p scal_prop;
00608 sp_rock_grid rock_grid_prop;
00609
00610 std::vector<rocktab_table <base_strategy_fi> > rocktab;
00611
00612
00613 auto_value <double> last_c_norm;
00614 auto_value <int> approx_flag;
00615
00616 sp_fi_params ts_params;
00617 invers_fvf_avgerage_t invers_fvf_average;
00618
00619 item_array_t plane_flow_rate;
00620 item_array_t full_step_plane_flow_rate;
00621
00622 item_array_t pressure;
00623 item_array_t saturation_3p;
00624 item_array_t gas_oil_ratio;
00625
00626 sp_csr_matrix_t mat;
00627 sp_well_results_storage well_res;
00628 sp_fip_results_storage fip_res;
00629 };
00630 }
00631
00632 #endif // CALC_MODEL_H