/[escript]/trunk/paso/src/GMRES2.cpp
ViewVC logotype

Diff of /trunk/paso/src/GMRES2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/doubleplusgood/paso/src/GMRES2.c revision 4257 by jfenwick, Wed Feb 27 03:42:40 2013 UTC trunk/paso/src/GMRES2.cpp revision 4657 by jfenwick, Thu Feb 6 06:12:20 2014 UTC
# Line 1  Line 1 
1    
2  /*****************************************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2013 by University of Queensland  * Copyright (c) 2003-2014 by University of Queensland
5  * http://www.uq.edu.au  * http://www.uq.edu.au
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
# Line 9  Line 9 
9  * http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
10  *  *
11  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12  * Development since 2012 by School of Earth Sciences  * Development 2012-2013 by School of Earth Sciences
13    * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
# Line 36  err_t Paso_Solver_GMRES2( Line 37  err_t Paso_Solver_GMRES2(
37    const dim_t n=F->n;    const dim_t n=F->n;
38    const double rel_tol=*tolerance;    const double rel_tol=*tolerance;
39    double abs_tol, normf0, normv, normv2, hh, hr, nu, norm_of_residual=0.;    double abs_tol, normf0, normv, normv2, hh, hr, nu, norm_of_residual=0.;
40    bool_t breakFlag=FALSE, maxIterFlag=FALSE, convergeFlag=FALSE;    bool breakFlag=FALSE, maxIterFlag=FALSE, convergeFlag=FALSE;
41    double *h=NULL, **v=NULL, *c=NULL,*s=NULL,*g=NULL, *work=NULL;    double *h=NULL, **v=NULL, *c=NULL,*s=NULL,*g=NULL, *work=NULL;
42    err_t Status=SOLVER_NO_ERROR;    err_t Status=SOLVER_NO_ERROR;
43    
# Line 48  err_t Paso_Solver_GMRES2( Line 49  err_t Paso_Solver_GMRES2(
49    /*        /*    
50     *  allocate memory:     *  allocate memory:
51     */     */
52    h=TMPMEMALLOC(l*l,double);    h=new double[l*l];
53    v=TMPMEMALLOC(l,double*);    v=new double*[l];
54    c=TMPMEMALLOC(l,double);    c=new double[l];
55    s=TMPMEMALLOC(l,double);    s=new double[l];
56    g=TMPMEMALLOC(l,double);    g=new double[l];
57    work=TMPMEMALLOC(n,double);    work=new double[n];
58    
59    if (h==NULL || v ==NULL || c== NULL || s == NULL || g== NULL || work==NULL) {    if (h==NULL || v ==NULL || c== NULL || s == NULL || g== NULL || work==NULL) {
60       Status=SOLVER_MEMORY_ERROR;       Status=SOLVER_MEMORY_ERROR;
# Line 69  err_t Paso_Solver_GMRES2( Line 70  err_t Paso_Solver_GMRES2(
70        if (! convergeFlag) {        if (! convergeFlag) {
71            abs_tol=rel_tol*normf0;            abs_tol=rel_tol*normf0;
72            printf("GMRES2 initial residual norm %e (rel. tol=%e)\n",normf0,rel_tol);            printf("GMRES2 initial residual norm %e (rel. tol=%e)\n",normf0,rel_tol);
73            v[0]=TMPMEMALLOC(n,double);            v[0]=new double[n];
74            if (v[0]==NULL) {            if (v[0]==NULL) {
75               Status=SOLVER_MEMORY_ERROR;               Status=SOLVER_MEMORY_ERROR;
76            } else {            } else {
# Line 79  err_t Paso_Solver_GMRES2( Line 80  err_t Paso_Solver_GMRES2(
80            }            }
81            while( (! (breakFlag || maxIterFlag || convergeFlag)) && (Status ==SOLVER_NO_ERROR) ) {            while( (! (breakFlag || maxIterFlag || convergeFlag)) && (Status ==SOLVER_NO_ERROR) ) {
82                 k++;                 k++;
83                 v[k]=TMPMEMALLOC(n,double);                 v[k]=new double[n];
84                 if (v[k]==NULL) {                 if (v[k]==NULL) {
85                    Status=SOLVER_MEMORY_ERROR;                    Status=SOLVER_MEMORY_ERROR;
86                 } else {                 } else {
# Line 168  err_t Paso_Solver_GMRES2( Line 169  err_t Paso_Solver_GMRES2(
169    *  clean up:    *  clean up:
170    */    */
171    if ( v !=NULL) {    if ( v !=NULL) {
172      for (i=0;i<iter_max;i++) TMPMEMFREE(v[i]);      for (i=0;i<iter_max;i++) delete[] v[i];
173    }    }
174    TMPMEMFREE(h);    delete[] h;
175    TMPMEMFREE(v);    delete[] v;
176    TMPMEMFREE(c);    delete[] c;
177    TMPMEMFREE(s);    delete[] s;
178    TMPMEMFREE(g);    delete[] g;
179    TMPMEMFREE(work);    delete[] work;
180    *iter=k;    *iter=k;
181    *tolerance=norm_of_residual;    *tolerance=norm_of_residual;
182    return Status;    return Status;

Legend:
Removed from v.4257  
changed lines
  Added in v.4657

  ViewVC Help
Powered by ViewVC 1.1.26