Changeset 2426 for branches/newmole

Show
Ignore:
Timestamp:
10/27/08 15:50:47 (2 months ago)
Author:
rjrw
Message:

Fix for limit_lte_he1_ste.in -- increase size of initial guess on
rlimit in newton_step.cpp. This may well need further tuning to
balance robustness and speed (or generally an improved approach).

Also add template to deal with problems on VS/Sun compilers getting
pointer-to-const from const valarray.

Location:
branches/newmole/source
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/newmole/source/mole.h

    r2356 r2426  
    192192extern struct chem_element_s *element_list[LIMELM]; 
    193193 
     194template<class T> const T* get_const_address(const valarray<T> v) 
     195{ 
     196        return const_cast<const T*>(&const_cast<valarray<T>&>(v)[0]); 
     197} 
     198 
    194199#endif /* _MOLE_H_ */ 
  • branches/newmole/source/mole_solve.cpp

    r2420 r2426  
    4646#define SMALLABUND 1e-24 
    4747 
    48 static double molnum[LIMELM]; 
     48static double molElems[LIMELM],molElemsNew[LIMELM]; 
    4949 
    5050double mole_solve() 
     
    106106 
    107107                MoleMap.setup(&oldmols[0]); 
     108 
     109                grouped_elems(&oldmols[0],molElems); 
    108110                 
    109111                long j; 
     
    113115                        newton_step(oldmols, newmols, &error, mole.num_compacted, &rlimit, escale, funjac);  
    114116                         
     117                        if (0) 
     118                        { 
     119                                grouped_elems(&newmols[0],molElemsNew); 
     120                                for (long nelem=0; nelem <LIMELM; nelem++) 
     121                                { 
     122                                        if (molElems[nelem] > 0.0) 
     123                                        { 
     124                                                fprintf(ioQQQ,"StepChg %ld %g %g\n",nelem,molElems[nelem],molElemsNew[nelem]); 
     125                                        } 
     126                                } 
     127                        } 
     128                 
    115129                        /* check for negative populations */ 
    116130                        nBad = 0;  
     
    418432                } 
    419433        } 
     434 
     435        if (0) 
     436        { 
     437                for (nelem=ipHYDROGEN;nelem<=ipHELIUM;nelem++) 
     438                { 
     439                        double sum1 = 0., sum2 = 0.; 
     440                        for(i=0;i<mole.num_calc;i++) 
     441                        { 
     442                                sum1 += b[i]*mole.list[i]->nElem[nelem]; 
     443                                sum2 += fabs( b[i]*mole.list[i]->nElem[nelem] ); 
     444                        } 
     445                        fprintf(ioQQQ,"Elem ungroup %ld cons %g %g %g\n",nelem,sum1,dense.gas_phase[nelem],sum2); 
     446                } 
     447        } 
    420448         
    421449        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     
    436464        } 
    437465         
     466        if (0) 
     467        { 
     468                for (nelem=ipHYDROGEN;nelem<=ipHELIUM;nelem++) 
     469                { 
     470                        double sum1 = 0.; 
     471                        for(i=0;i<mole.num_calc;i++) 
     472                        { 
     473                                sum1 += b[i]*mole.list[i]->nElem[nelem]; 
     474                        } 
     475                        fprintf(ioQQQ,"Elem group %ld cons %g %g\n",nelem,sum1,dense.gas_phase[nelem]); 
     476                } 
     477        } 
     478 
    438479        /* Species are now grouped -- only mole.num_compacted elements now active */ 
    439480 
    440481        /* For Newton-Raphson method, want the change in populations to be zero, 
    441482         * so the conserved component must also be zero */ 
    442         if (lgConserve) 
    443         { 
    444                 if (0) 
    445                 { 
    446                         for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
    447                         { 
    448                                 double sum1 = 0.; 
     483        if (0) 
     484        { 
     485                for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     486                { 
     487                        double sum1 = 0.; 
     488                        for(i=0;i<mole.num_compacted;i++) 
     489                        { 
     490                                sum1 += b[groupspecies[i]->index]*groupspecies[i]->nElem[nelem]; 
     491                        } 
     492                        fprintf(ioQQQ,"Elem %ld cons %g %g\n",nelem,sum1,dense.gas_phase[nelem]); 
     493                        if (lgJac) 
     494                        { 
    449495                                for(i=0;i<mole.num_compacted;i++) 
    450496                                { 
    451                                         sum1 += b[groupspecies[i]->index]*groupspecies[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_compacted;j++) 
    460                                                 { 
    461                                                         sum1 += c[groupspecies[i]->index][groupspecies[j]->index]* 
    462                                                                 groupspecies[j]->nElem[nelem]; 
    463                                                 } 
    464                                                 fprintf(ioQQQ,"Eqn %ld error %g\n",i,sum1); 
    465                                         } 
     497                                        sum1 = 0.; 
     498                                        for (long j=0;j<mole.num_compacted;j++) 
     499                                        { 
     500                                                sum1 += c[groupspecies[i]->index][groupspecies[j]->index]* 
     501                                                        groupspecies[j]->nElem[nelem]; 
     502                                        } 
     503                                        fprintf(ioQQQ,"Eqn %ld error %g\n",i,sum1); 
    466504                                } 
    467505                        } 
     
    480518                        double molnow[LIMELM]; 
    481519 
    482                         grouped_elems(&b2vec[0], molnow); 
    483                         for ( nelem=ipHYDROGEN; nelem<LIMELM; nelem++) 
    484                         { 
    485                                 molnow[nelem] = 0.; 
    486                         } 
    487                         for( i=0; i < mole.num_compacted; i++ ) 
    488                         { 
    489                                 for ( nelem=ipHYDROGEN; nelem<LIMELM; nelem++) 
    490                                 { 
    491                                         molnow[nelem] += b2vec[i]*groupspecies[i]->nElem[nelem]; 
    492                                 } 
    493                         } 
     520                        grouped_elems(get_const_address(b2vec), molnow); 
     521 
    494522                        iamax = 0; 
    495523                        for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
     
    534562                                                } 
    535563                                        } 
    536                                         b[ncons[nelem]] = (molnow[nelem]-molnum[nelem]); 
     564                                        b[ncons[nelem]] = (molnow[nelem]-molElems[nelem]); 
    537565                                        //fprintf(ioQQQ,"Elem %ld err %g\n",nelem,b[ncons[nelem]]); 
    538566                                } 
     
    568596                                for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 
    569597                                { 
    570                                         u[i][nelem] = mole.list[groupspecies[i]->index]->nElem[nelem]; 
     598                                        u[i][nelem] = groupspecies[i]->nElem[nelem]; 
    571599                                } 
    572600                        } 
     
    698726                                ervals[i] = b[groupspecies[i]->index]; 
    699727                        } 
    700                          
     728 
    701729                        if (lgJac)  
    702730                        { 
     
    711739                } 
    712740        } 
     741 
     742        if (0)  
     743        { 
     744                grouped_elems(&ervals[0],molElemsNew); 
     745                for ( long nelem=0; nelem<LIMELM; nelem++) 
     746                { 
     747                        if (molElemsNew[nelem] != 0.0) 
     748                                fprintf(ioQQQ,"Newmole errs nelem %ld %g\n",nelem,molElemsNew[nelem]); 
     749                }                
     750        } 
     751 
    713752} 
    714753 
     
    799838                b0vec[i] = calcv[groupspecies[i]->index]; 
    800839        } 
    801         grouped_elems(&b0vec[0],molnum); 
    802840} 
    803841 
  • branches/newmole/source/newton_step.cpp

    r2123 r2426  
    8686                                        } 
    8787                                } 
    88                                 *rlimit *= 1e-11; 
     88                                *rlimit *= 1e-8; 
    8989                        } 
    9090                        for( i=0; i < n; i++ )