solversamg.cpp

Go to the documentation of this file.
00001 /*
00002 %M Esse módulo contem as funções para utilização da biblioteca SAMG
00003  *     06-07 André Luis Muller
00004  *     
00005  *
00006  */
00007 #include <cstdio>
00008 #include <iostream>
00009 #include <fstream>
00010 
00011 #include "samg.h"
00012 
00013 /* the old C++ compiler on Alpha cannot handle using namespace std !*/
00014 #ifndef SAMG_OLDALPHA
00015 using namespace std;
00016 #endif
00017 
00018 #include "solversamg.h"
00019 #include "fem.h"
00020 
00021 
00022 int SamgSolver(int iversion, int nna, int nnu, int matrix, int nsys,
00023                int npnt,  int *ia, int *ja, double *a, double *f, double *u)
00024 {
00025 
00026 /* ===> Set primary parameters. Others can be set by access functions as shown below.*/
00027 
00028   int    ndiu      = 1;        /* dimension of (dummy) vector iu                            */
00029   int    ndip      = 1;        /* dimension of (dummy) vector ip                            */
00030                                /*                                                           */
00031   int    nsolve    = 2;        /* results in scalar approach (current system is scalar)     */
00032   int    ifirst    = 1;        /* first approximation = zero                                */
00033   double eps       = 1.0e-8;   /* required (relative) residual reduction                    */
00034   int    ncyc      = 110200;   /* V-cycle as pre-conditioner for GMRES; at most 200 iterations  */
00035                                /*                                                           */
00036   double a_cmplx   = 2.2;      /* estimated dimensioning                                    */
00037   double g_cmplx   = 1.7;      /* estimated dimensioning                                    */
00038   double w_avrge   = 2.4;      /* estimated dimensioning                                    */
00039   double p_cmplx   = 0.0;      /* estimated dimensioning (irrelevant for scalar case)       */
00040                                /*                                                           */
00041   double chktol    = -1.0;     /* input checking de-activated (we know it's ok!)            */
00042   int    idump     = 0;        /* minimum output during setup                               */
00043   int    iout      = -2;       /* no display residuals per iteration and work statistics    */
00044                                /*                                                           */
00045   int    n_default = 20;       /* select default settings for secondary parameters          */
00046                                /* CURRENTLY AVAILABLE: 10-13, 15-18, 20-23, 25-28           */
00047                                /* NOTE: the higher the respective SECOND digit, the         */
00048                                /* more aggressive the coarsening (--> lower memory at       */
00049                                /* the expense of slower convergence)                        */
00050   int    iswtch    = 5300+n_default; /* complete SAMG run ....*/
00051                                /* ... memory de-allocation upon return ....                 */                                   
00052                                /* ... memory extension feature activated ....               */
00053                                /* ... residuals measured in the L2-norm .....               */
00054                                /* ... secondary parameter default setting # n_default       */
00055 
00056 /* ===> Secondary parameters which have to be set if n_default=0
00057       (at the same time a demonstration of how to access secondary or hidden parameters)*/
00058       int intin;
00059       double dblin;
00060 
00061       if (n_default == 0) {
00062          intin=25;    SAMG_SET_LEVELX(&intin);
00063          intin=100;   SAMG_SET_NPTMN(&intin);
00064          intin=4;     SAMG_SET_NCG(&intin);
00065          intin=2;     SAMG_SET_NWT(&intin);
00066          intin=1;     SAMG_SET_NTR(&intin);
00067          intin=131;   SAMG_SET_NRD(&intin);
00068          intin=131;   SAMG_SET_NRU(&intin);
00069          intin=0;     SAMG_SET_NRC(&intin);
00070          intin=0;     SAMG_SET_NP_OPT(&intin);
00071 
00072          dblin=21.25; SAMG_SET_ECG(&dblin);
00073          dblin=0.20;  SAMG_SET_EWT(&dblin);
00074          dblin=12.20; SAMG_SET_ETR(&dblin);
00075       }
00076       int * iu     = new int[1];
00077       int * ip     = new int[1];
00078       int * iscale = new int[1];
00079 
00080       int ierr,ncyc_done;
00081       double res_out,res_in;
00082 
00083       float told,tnew,tamg;
00084       SAMG_CTIME(&told);
00085 
00086       SAMG(&nnu,&nna,&nsys,
00087            &ia[0],&ja[0],&a[0],&f[0],&u[0],&iu[0],&ndiu,&ip[0],&ndip,&matrix,&iscale[0],
00088            &res_in,&res_out,&ncyc_done,&ierr,
00089            &nsolve,&ifirst,&eps,&ncyc,&iswtch,
00090            &a_cmplx,&g_cmplx,&p_cmplx,&w_avrge,
00091            &chktol,&idump,&iout);
00092 
00093       if (ierr > 0) {
00094           cout << endl << " SAMG terminated with error code " 
00095                << ierr << " **** " << endl;
00096       }
00097       else if (ierr < 0) {
00098           cout << endl << " SAMG terminated with warning code " 
00099                << ierr << " **** " << endl;
00100       }
00101 
00102       SAMG_CTIME(&tnew);
00103       tamg=tnew-told;
00104       cout << endl << " ***** total run time: " << tamg << " ***** " << endl; 
00105       
00106       delete[] iu;
00107       delete[] ip;
00108       delete[] iscale;
00109 
00110       return ierr;
00111 }

Generated on Tue Oct 23 11:23:30 2007 for Relax by  doxygen 1.5.3