00001 #include "precond.h"
00002 #include "gmatrix.h"
00003 #include "aggregator.h"
00004
00005 precond::precond ()
00006 {
00007
00008 pt = noprecond;
00009
00010 n = 0;
00011
00012 incompltresh=0.0;
00013
00014 agg=NULL;
00015 agm=NULL;
00016 }
00017
00018 precond::~precond ()
00019 {
00020
00021 }
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 void precond::read (gtopology *gt,XFILE *in,long mespr)
00032 {
00033
00034 xfscanf (in,"%d",(int*)&pt);
00035
00036 switch (pt){
00037 case noprecond:{
00038 if (mespr==1) fprintf (stdout,"\n no preconditioner will be used");
00039 break;
00040 }
00041 case diagprec:{
00042 if (mespr==1) fprintf (stdout,"\n the diagonal (Jacobi) preconditioner will be used");
00043 break;
00044 }
00045 case ssorprec:{
00046 if (mespr==1) fprintf (stdout,"\n the SSOR preconditioner will be used");
00047 xfscanf (in,"%lf",&ssoromega);
00048 break;
00049 }
00050 case incomdec:{
00051 if (mespr==1) fprintf (stdout,"\n preconditioner based on incomplete factorization of matrix will be used");
00052 xfscanf (in,"%lf",&incompltresh);
00053 break;
00054 }
00055 case boss:{
00056 agg = new aggregator [1];
00057 if (mespr==1) fprintf (stdout,"\n preconditioner based on the BOSS (smoothed aggregations) will be used");
00058 agg->read (gt,in,mespr);
00059 break;
00060 }
00061 default:{
00062 print_err("unknown type of preconditioner of solver of linear equations is required",__FILE__,__LINE__,__func__);
00063 }
00064 }
00065
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075 void precond::print (FILE *out)
00076 {
00077
00078 fprintf (out,"%d\n",pt);
00079
00080 switch (pt){
00081 case noprecond:{
00082 break;
00083 }
00084 case diagprec:{
00085 break;
00086 }
00087 case ssorprec:{
00088 fprintf (out,"%lf\n",ssoromega);
00089 break;
00090 }
00091 case incomdec:{
00092 fprintf (out,"%lf\n",incompltresh);
00093 break;
00094 }
00095 case boss:{
00096 agg->print (out);
00097 break;
00098 }
00099 default:{
00100 print_err("unknown type of preconditioner of solver of linear equations is required",__FILE__,__LINE__,__func__);
00101 }
00102 }
00103
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 void precond::initiation (gtopology *gt,gmatrix *gm,FILE *out)
00120 {
00121
00122 n=gm->n;
00123
00124 switch (pt){
00125 case noprecond:{
00126 break;
00127 }
00128 case incomdec:{
00129 agm = new gmatrix [1];
00130 gm->copygm (*agm);
00131 agm->incomplete_fact (incompltresh);
00132 break;
00133 }
00134 case boss:{
00135
00136
00137 agg->prepare_boss (gt,gm,out);
00138 agm = new gmatrix;
00139 gm->copygm (*agm);
00140 break;
00141 }
00142 default:{
00143 print_err("unknown type of preconditioner of solver of linear equations is required",__FILE__,__LINE__,__func__);
00144 }
00145 }
00146
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 void precond::preconditioning (double *r,double *h,double *rhs)
00160 {
00161 long i;
00162
00163 switch (pt){
00164 case noprecond:{
00165 for (i=0;i<n;i++){
00166 h[i]=r[i];
00167 }
00168 break;
00169 }
00170 case boss:{
00171 agg->boss (agm,r,h);
00172 break;
00173 }
00174 case incomdec:{
00175 agm->back_incomplete_fact (h,r,incompltresh);
00176 break;
00177 }
00178 default:{
00179 print_err("unknown type of preconditioner of solver of linear equations is required",__FILE__,__LINE__,__func__);
00180 }
00181 }
00182 }