Show
Ignore:
Timestamp:
05/07/08 16:29:10 (8 months ago)
Author:
rjrw
Message:

Stubs for using minpack routines (they don't improve things, possibly
due to the Jacobian fix for species conservation).

Re-order a loop in conv_init_solution.

Remove some out of date comments.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/newmole/source/mole_solve.cpp

    r2028 r2031  
    4040 
    4141#define SMALLABUND 1e-24 
     42#ifdef MINPACK 
     43#include <minpack.h> 
     44STATIC void fcn(const int *n, const double *x, double *fvec, double *fjac, 
     45                                                                const int *ldfjac, int *iflag ); 
     46#endif 
    4247 
    4348double mole_solve() 
     
    95100 
    96101                MoleMap.setup(&oldmols[0]); 
    97                 newton_step(oldmols, newmols, &error, mole.num_compacted, funjac); 
     102                if (1) 
     103                { 
     104                        newton_step(oldmols, newmols, &error, mole.num_compacted, funjac);  
     105                } 
     106                else 
     107                { 
     108#ifdef MINPACK 
     109                        int info, lwa = (mole.num_compacted*(mole.num_compacted+13))/2; 
     110                        valarray<double> fvec(mole.num_compacted), 
     111                                fjac(mole.num_compacted*mole.num_compacted), 
     112                                wa(lwa); 
     113                        double tol = 1e-7; 
     114                        for ( long i=0; i < mole.num_compacted; i++ ) 
     115                        { 
     116                                newmols[i] = oldmols[i]; 
     117                        } 
     118                        hybrj1_(fcn, &mole.num_compacted, &newmols[0], &fvec[0], &fjac[0], 
     119                                                        &mole.num_compacted, &tol, &info, &wa[0], &lwa); 
     120                        fprintf(ioQQQ,"hybrj1_ returns info %d\n",info); 
     121#else 
     122                        ; 
     123#endif 
     124                } 
    98125 
    99126                /* check for negative populations */ 
     
    117144                MoleMap.updateMolecules( &newmols[0] ); 
    118145                 
    119                 //fprintf(stdout,"Mole zone %ld -- %7.2f loop %d error %15.8g nBad %d\n",nzone,fnzone,i,error,nBad); 
     146                // fprintf(stdout,"Mole zone %ld -- %7.2f error %15.8g nBad %d\n",nzone,fnzone,error,nBad); 
    120147         
    121148                if (error < BIGERROR && nBad == 0 && nPrevBad == 0) /* Stop early if good enough */ 
     
    283310GroupMap MoleMap; 
    284311 
     312#ifdef MINPACK 
     313STATIC void fcn(const int *n, const double *x, double *fvec, double *fjac, 
     314                                                                const int *ldfjac, int *iflag ) 
     315{ 
     316        /* Function to interface funjac with MINPACK routines */ 
     317        ASSERT (*ldfjac == *n); 
     318        valarray<double> b2vec(*n), tmpvec(*n); 
     319        for (long i=0; i < *n; i++)  
     320        { 
     321                b2vec[i] = x[i]; 
     322        } 
     323        if (*iflag == 1) 
     324                funjac(b2vec, fvec, &tmpvec[0], false); 
     325        else if (*iflag == 2) 
     326                funjac(b2vec, &tmpvec[0], fjac, true); 
     327} 
     328#endif 
     329 
    285330STATIC void funjac(const valarray<double> &b2vec, double * const ervals, double * const amat, const bool lgJac) 
    286331{ 
     
    334379         
    335380        if (lgJac) { 
    336                 // c[i][i] can be positive for auto-catalytic reactions 
    337                 //for(i=0;i<mole.num_calc;i++)  
    338                 //{ 
    339                 //      ASSERT (c[i][i] <= 0.); 
    340                 //} 
    341381                for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
    342382                { 
     
    401441        if (lgConserve) 
    402442        { 
     443                if (0) 
     444                { 
     445                        double sum1; 
     446                        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     447                        { 
     448                                sum1 = 0.; 
     449                                for(i=0;i<mole.num_calc;i++) 
     450                                { 
     451                                        sum1 += b[i]*mole.list[i]->nElem[nelem]; 
     452                                } 
     453                                fprintf(ioQQQ,"Elem %ld cons %g %g\n",nelem,sum1,dense.gas_phase[nelem]); 
     454                                if (lgJac) 
     455                                { 
     456                                        for(i=0;i<mole.num_calc;i++) 
     457                                        { 
     458                                                sum1 = 0.; 
     459                                                for (long j=0;j<mole.num_calc;j++) 
     460                                                { 
     461                                                        sum1 += c[i][j]*mole.list[j]->nElem[nelem]; 
     462                                                } 
     463                                                fprintf(ioQQQ,"Eqn %ld error %g\n",i,sum1); 
     464                                        } 
     465                                } 
     466                        } 
     467                } 
     468 
    403469                double scale; 
    404470                for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     
    415481                                } 
    416482                                else 
     483                                { 
    417484                                        scale = c[element_list[nelem]->ipMl[0]][element_list[nelem]->ipMl[0]]; 
    418                                  
     485                                }                                
     486 
    419487                                b[element_list[nelem]->ipMl[0]] = 0.; 
    420488                        } 
     
    459527                for( i=0; i < mole.num_compacted; i++ ) 
    460528                { 
    461                         // c[i][i] can be +ve for (effectively) autocatalytic reactions, 
    462                         // e.g. H-,H+=>H,H 
    463                         //ASSERT (c[groupspecies[i]->index][groupspecies[i]->index] <= 0.); 
    464529                        for( j=0; j < mole.num_compacted; j++ ) 
    465530                        {