00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(CG_HPP)
00012 #define CG_HPP
00013
00014 #include "diagop.hpp"
00015 #include "identityop.hpp"
00016 #include "glop.hpp"
00017 #include "gttlist.hpp"
00018 #include "gtlist.hpp"
00019 #include "glinoplist.hpp"
00020 #include "gelemlist.hpp"
00021 #include "gtbuffer.hpp"
00022 #include "gs.hpp"
00023
00024 enum CGType {CG_STANDARD, CG_REDUCED_VAR1, CG_REDUCED_VAR2};
00025 extern char *s_cgerror_[] ;
00026
00027
00028 class CG
00029 {
00030 public:
00031 enum CGERRNO {CGERR_NONE=0 , CGERR_NULLOP , CGERR_LISTSZERR,
00032 CGERR_BADITERNUM, CGERR_CONVERGE, CGERR_SOLVE };
00033
00034
00035 CG(CGType itype, GBOOL isNested=FALSE);
00036 CG(GElemList *e, GLinOpList *A, GLinOpList *ROP, GVecList *x, GVecList *b, GS *comm,
00037 CGType itype=CG_STANDARD, GBOOL isNested=FALSE);
00038 ~CG();
00039 CG(const CG &a);
00040 void operator=(const CG &);
00041 void operator()(GElemList *e, GLinOpList *A, GLinOpList *ROP, GVecList *x, GVecList *b, GS *c) ;
00042
00043 void Quiet(GBOOL b);
00044 void SetNoDSS(GVecList *rb);
00045 void SetTolerance(GDOUBLE);
00046 void SetMaxIterations(GINT );
00047 void SetResidualChkNum(GINT );
00048 void SetSolveType(CGType);
00049 void SetPreconditioner(GLinOpList *op);
00050 void SetComm(GS *op);
00051 GCHandle InitComm(GDWBuffer *n, GINT nTotal);
00052 GCHandle SetCommHandle(GCHandle hIn=NULL);
00053 GCHandle SetIntermedCommHandle(GCHandle hIn);
00054 void SetIntermedMask(GLinOpList *in);
00055 void SetBdyValues (GVecList *bdy_vals);
00056 void SetElems(GElemList *gelems);
00057 GDOUBLE GetTolerance();
00058 GINT GetMaxIterations();
00059 GINT GetResidualChkNum();
00060 GINT GetNumIterations();
00061 GDOUBLE GetError();
00062 GDOUBLE GetMinError();
00063 GDOUBLE GetMaxError();
00064 GVector *GetEucResidualHistory();
00065 GVector *GetL2ResidualHistory();
00066 GINT ErrNo();
00067 char *ErrString();
00068
00069 GVecList &GetBdyValues ();
00070
00071 GBOOL SolveCG();
00072
00073
00074
00075 private:
00076
00077 GINT SolveStandard();
00078 GBOOL OpVec_prod(GVecList &in, GVecList &out);
00079 GINT SolveReduced(CGType itype);
00080
00081 GBOOL DoDotProducts(GVecList &a1, GVecList a2[], GDOUBLE *ldot, GDOUBLE *dots, const GINT ndot);
00082 void ResetExpandables(GLinOpList *AA, GLinOpList *ROp);
00083
00084
00085
00086
00087 GINT MaxIterations;
00088 GINT nResidualChk;
00089 GINT numIterations;
00090 GINT nIntermedProd;
00091 GINT iErrType;
00092 GINT nTotalNodes;
00093 GINT bad_iter_number;
00094 GINT nops;
00095 GINT nprecon;
00096 GBOOL bQuiet;
00097 GBOOL bNested;
00098 GBOOL bMaskAlloc;
00099 CGType iSolveType;
00100 GDOUBLE tolerance;
00101 GDOUBLE minErr;
00102 GDOUBLE maxErr;
00103 GDOUBLE finErr;
00104 GVector EucResidual_;
00105 GVector L2Residual_;
00106 GDWBuffer *glob_ids;
00107 GDBuffer *imultiplicity;
00108 GCHandle hDSOp;
00109 GCHandle hDSOp_Intermed;
00110 GLinOpList mask_Intermed;
00111 GS *gsop;
00112 GElemList *gelems_;
00113 GLinOpList *A;
00114 GLinOpList *ROp;
00115 GVecList *x;
00116 GVecList *b;
00117 GLinOpList precon;
00118 GVecList xb;
00119 GVecList bnodss;
00120 GVecList intermed_soln;
00121 GVecList intermed_vecp;
00122 GVecList ytmp ;
00123 GLinOpList intermed_op;
00124 CG **cg_intermed;
00125
00126
00127
00128 GVecList rk;
00129 GVecList wk;
00130 GVecList qk;
00131 GVecList sk;
00132 GVecList zk;
00133 GVecList msk;
00134 GVecList mqk;
00135 GVecList vk;
00136
00137 };
00138 #endif
00139