00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011
00012
00013
00014
00015 #ifndef _LINEARSOLVER_H_
00016 #define _LINEARSOLVER_H_
00017
00018 #include "REAL.H"
00019 #include "Box.H"
00020 #include <cmath>
00021 #include "NamespaceHeader.H"
00022
00023
00024
00025
00026
00027 template <class T>
00028 class LinearOp
00029 {
00030 public:
00031
00032 virtual ~LinearOp()
00033 {
00034 }
00035
00036
00037
00038
00039
00040
00041 virtual void residual( T& a_lhs, const T& a_phi, const T& a_rhs, bool a_homogeneous = false) = 0;
00042
00043
00044
00045
00046
00047 virtual void preCond( T& a_cor, const T& a_residual) = 0;
00048
00049
00050
00051
00052
00053
00054 virtual void applyOp( T& a_lhs, const T& a_phi, bool a_homogeneous = false) = 0;
00055
00056
00057
00058
00059
00060
00061 virtual void create( T& a_lhs, const T& a_rhs) = 0;
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 virtual void clear(T& a_lhs)
00072 {
00073 }
00074
00075
00076
00077
00078
00079
00080 virtual void assign( T& a_lhs, const T& a_rhs) = 0;
00081
00082 virtual void assignLocal(T& a_lhs, const T& a_rhs)
00083 {
00084 this->assign(a_lhs, a_rhs);
00085 }
00086
00087
00088
00089
00090
00091 virtual Real dotProduct(const T& a_1, const T& a_2) = 0;
00092
00093 virtual void mDotProduct(const T& a_1, const int a_sz, const T a_2[], Real a_mdots[])
00094 {
00095 for (int j=0; j<a_sz; j++)
00096 {
00097 a_mdots[j] = dotProduct(a_1, a_2[j]);
00098 }
00099 }
00100
00101
00102
00103
00104
00105 virtual void incr ( T& a_lhs, const T& a_x, Real a_scale) = 0;
00106
00107
00108
00109
00110
00111 virtual void axby( T& a_lhs, const T& a_x, const T& a_y, Real a_a, Real a_b) = 0;
00112
00113
00114
00115
00116
00117 virtual void scale( T& a_lhs, const Real& a_scale) = 0;
00118
00119
00120
00121
00122
00123
00124 virtual Real norm(const T& a_rhs, int a_ord) = 0;
00125
00126
00127
00128
00129
00130 virtual Real dx() const
00131 {
00132 MayDay::Warning(" calling dx on base class\n");
00133 return 0.;
00134 }
00135
00136
00137
00138
00139 virtual void setToZero(T& a_lhs) = 0;
00140
00141
00142
00143
00144
00145
00146 virtual void write(const T* a, const char* filename)
00147 {
00148 MayDay::Warning("LinearOp::write not implemented");
00149 }
00150
00151 };
00152
00153
00154
00155
00156
00157 template <class T>
00158 class LinearSolver
00159 {
00160 public:
00161 virtual ~LinearSolver()
00162 {
00163 }
00164
00165
00166
00167
00168
00169 virtual void setHomogeneous(bool a_homogeneous) = 0;
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 virtual void define(LinearOp<T>* a_operator, bool a_homogeneous = false) = 0;
00182
00183
00184
00185
00186
00187 virtual void solve(T& a_phi, const T& a_rhs) = 0;
00188
00189
00190
00191
00192
00193
00194
00195 virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
00196 {
00197 }
00198 };
00199
00200 #include "NamespaceFooter.H"
00201 #endif