Show
Ignore:
Timestamp:
05/07/08 16:29:10 (7 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.

Location:
branches/newmole/source
Files:
4 modified

Legend:

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

    r2023 r2031  
    130130        for( i=0; i<mole.num_calc; ++i ) 
    131131        { 
    132                 for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++)  
    133                 { 
    134                         if( dense.lgElmtOn[nelem] && mole.list[i]->location == NULL ) 
     132                if (mole.list[i]->location == NULL) 
     133                { 
     134                        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++)  
    135135                        { 
    136                                 realnum dens_elemsp = (realnum) mole.list[i]->den*mole.list[i]->nElem[nelem]; 
    137                                 if (    FracMoleMax*dense.gas_phase[nelem] < dens_elemsp )  
     136                                if( dense.lgElmtOn[nelem] ) 
    138137                                { 
    139                                         FracMoleMax = dens_elemsp/dense.gas_phase[nelem]; 
    140                                         ipMax = i; 
     138                                        realnum dens_elemsp = (realnum) mole.list[i]->den*mole.list[i]->nElem[nelem]; 
     139                                        if ( FracMoleMax*dense.gas_phase[nelem] < dens_elemsp )  
     140                                        { 
     141                                                FracMoleMax = dens_elemsp/dense.gas_phase[nelem]; 
     142                                                ipMax = i; 
     143                                        } 
    141144                                } 
    142145                        } 
     
    148151        for(i=0;i<mole.num_calc;++i) 
    149152        { 
    150                 OxyInGrains += (1 - mole.list[i]->lgGas_Phase)*mole.list[i]->den*mole.list[i]->nElem[ipOXYGEN];  
     153                if (! mole.list[i]->lgGas_Phase ) 
     154                        OxyInGrains += mole.list[i]->den*mole.list[i]->nElem[ipOXYGEN];  
    151155        } 
    152156        /* this is now fraction of O in ices */ 
  • branches/newmole/source/mole_eval_balance.cpp

    r1846 r2031  
    6464        } 
    6565 
    66         /* Call all the routines that set up the matrix  
    67          * CO_solve will call this routine, therefore all other matrix elements are 
    68          * included here so that, when CO_solve is called, everything is accounted for */        
    69  
    70         /* All now cross-validated with new treatment, switching causes only v. minor 
    71          * differences in results */ 
    72         /* Revised molecular network implementation */ 
    73         /* Fills matrix elements for passive species -- these can be used to 
    74                  derive sources & sinks resulting from this part of the network */ 
    7566        for(mole_reaction_i p=mole_priv.reactab.begin();  
    7667                        p != mole_priv.reactab.end(); p++)  
  • 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                        { 
  • branches/newmole/source/newton_step.cpp

    r2028 r2031  
    5454        error0 = 1; 
    5555        error1 = grad = 0.; 
    56         fstep = flast = 1.;                      
     56        fstep = 1.;                      
    5757 
    5858        for (loop=0;loop<20;loop++)