00001
00009 #ifndef JACOBIAN_H_
00010 #define JACOBIAN_H_
00011
00012 #include "fi_params.h"
00013 #include BS_FORCE_PLUGIN_IMPORT ()
00014 #include "linear_solvers.h"
00015 #include BS_STOP_PLUGIN_IMPORT ()
00016
00017 #include "make_me_happy.h"
00018
00019 namespace blue_sky
00020 {
00021
00026 template <class strategy_t>
00027 class BS_API_PLUGIN jacobian : public bs_node
00028 {
00029 public:
00030 typedef typename strategy_t::matrix_t matrix_t;
00031 typedef typename strategy_t::item_array_t item_array_t;
00032 typedef typename strategy_t::rhs_item_array_t rhs_item_array_t;
00033 typedef typename strategy_t::item_t item_t;
00034 typedef typename strategy_t::index_t index_t;
00035 typedef typename strategy_t::index_array_t index_array_t;
00036 typedef typename strategy_t::barrier_t barrier_t;
00037 typedef rs_mesh_iface < strategy_t > mesh_iface_t;
00038 typedef typename strategy_t::csr_matrix_t bcsr_matrix_t;
00039 typedef linear_solver_base<strategy_t> linear_solver_base_t;
00040
00041 typedef smart_ptr <matrix_t> sp_matrix_t;
00042 typedef smart_ptr <bcsr_matrix_t, true> sp_bcsr_matrix_t;
00043 typedef smart_ptr <jacobian_matrix<strategy_t>, true> sp_jmatrix;
00044 typedef smart_ptr <linear_solver_base<strategy_t>, true> sp_lsolver;
00045 typedef smart_ptr <fi_params, true> sp_fi_params;
00046
00047 typedef smart_ptr <mesh_iface_t, true> sp_mesh_iface_t;
00048
00049 typedef jacobian <strategy_t> this_t;
00050
00051 public:
00053 void
00054 set_solver(const sp_lsolver &s)
00055 {
00056 solver = s;
00057 }
00059 void
00060 set_prec (const sp_lsolver &p)
00061 {
00062 preconditioner = p;
00063 }
00065 void
00066 set_jmatrix (const sp_jmatrix &mx)
00067 {
00068 jm = mx;
00069 }
00070
00072 const sp_jmatrix &
00073 get_jmatrix() const
00074 {
00075 return jm;
00076 }
00077
00079 const sp_lsolver &
00080 get_solver () const;
00081
00083 const sp_lsolver &
00084 get_prec () const;
00085
00087 int
00088 setup_solver_params (well_model_type model_type, int n_phases, const sp_fi_params &ts_params);
00089
00091 int
00092 setup ();
00093
00095 void
00096 begin ();
00097
00099 void
00100 end ();
00101
00103 item_t
00104 solve (index_t &n_lin_iters);
00105
00110 struct jacob_traits : bs_node::sort_traits
00111 {
00112 struct jacob_key : bs_node::sort_traits::key_type
00113 {
00114 virtual bool sort_order (const key_ptr & ) const
00115 {
00116 return true;
00117 }
00118 };
00119
00120 virtual const char * sort_name () const
00121 {
00122 return "jacob trait";
00123 };
00124
00125 virtual key_ptr key_generator (const sp_link& ) const
00126 {
00127 return new jacob_key ();
00128 }
00129
00130 virtual bool accepts (const sp_link& l)
00131 {
00132 return smart_ptr< this_t, true >(l->data(), bs_dynamic_cast());
00133 }
00134 };
00135
00136 public:
00140 virtual ~jacobian()
00141 {
00142 }
00143
00145 BLUE_SKY_TYPE_DECL_T (jacobian);
00146
00147 private:
00152 void
00153 setup_solver (const sp_fi_params &ts_params);
00154
00156 void
00157 setup_preconditioner (const sp_fi_params &ts_params);
00158
00159 protected:
00160
00161 sp_jmatrix jm;
00162 sp_lsolver solver;
00163 sp_lsolver preconditioner;
00164 auto_value <int> solver_is_gmres_flag;
00165 auto_value <int> prec_is_cpr_flag;
00166 };
00167
00168 }
00169 #endif // JACOBIAN_H_