Changeset 2031 for branches/newmole/source
- Timestamp:
- 05/07/08 16:29:10 (7 months ago)
- Location:
- branches/newmole/source
- Files:
-
- 4 modified
-
conv_init_solution.cpp (modified) (2 diffs)
-
mole_eval_balance.cpp (modified) (1 diff)
-
mole_solve.cpp (modified) (8 diffs)
-
newton_step.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/newmole/source/conv_init_solution.cpp
r2023 r2031 130 130 for( i=0; i<mole.num_calc; ++i ) 131 131 { 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++) 135 135 { 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] ) 138 137 { 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 } 141 144 } 142 145 } … … 148 151 for(i=0;i<mole.num_calc;++i) 149 152 { 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]; 151 155 } 152 156 /* this is now fraction of O in ices */ -
branches/newmole/source/mole_eval_balance.cpp
r1846 r2031 64 64 } 65 65 66 /* Call all the routines that set up the matrix67 * CO_solve will call this routine, therefore all other matrix elements are68 * 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. minor71 * differences in results */72 /* Revised molecular network implementation */73 /* Fills matrix elements for passive species -- these can be used to74 derive sources & sinks resulting from this part of the network */75 66 for(mole_reaction_i p=mole_priv.reactab.begin(); 76 67 p != mole_priv.reactab.end(); p++) -
branches/newmole/source/mole_solve.cpp
r2028 r2031 40 40 41 41 #define SMALLABUND 1e-24 42 #ifdef MINPACK 43 #include <minpack.h> 44 STATIC void fcn(const int *n, const double *x, double *fvec, double *fjac, 45 const int *ldfjac, int *iflag ); 46 #endif 42 47 43 48 double mole_solve() … … 95 100 96 101 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 } 98 125 99 126 /* check for negative populations */ … … 117 144 MoleMap.updateMolecules( &newmols[0] ); 118 145 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); 120 147 121 148 if (error < BIGERROR && nBad == 0 && nPrevBad == 0) /* Stop early if good enough */ … … 283 310 GroupMap MoleMap; 284 311 312 #ifdef MINPACK 313 STATIC 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 285 330 STATIC void funjac(const valarray<double> &b2vec, double * const ervals, double * const amat, const bool lgJac) 286 331 { … … 334 379 335 380 if (lgJac) { 336 // c[i][i] can be positive for auto-catalytic reactions337 //for(i=0;i<mole.num_calc;i++)338 //{339 // ASSERT (c[i][i] <= 0.);340 //}341 381 for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 342 382 { … … 401 441 if (lgConserve) 402 442 { 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 403 469 double scale; 404 470 for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) … … 415 481 } 416 482 else 483 { 417 484 scale = c[element_list[nelem]->ipMl[0]][element_list[nelem]->ipMl[0]]; 418 485 } 486 419 487 b[element_list[nelem]->ipMl[0]] = 0.; 420 488 } … … 459 527 for( i=0; i < mole.num_compacted; i++ ) 460 528 { 461 // c[i][i] can be +ve for (effectively) autocatalytic reactions,462 // e.g. H-,H+=>H,H463 //ASSERT (c[groupspecies[i]->index][groupspecies[i]->index] <= 0.);464 529 for( j=0; j < mole.num_compacted; j++ ) 465 530 { -
branches/newmole/source/newton_step.cpp
r2028 r2031 54 54 error0 = 1; 55 55 error1 = grad = 0.; 56 fstep = flast =1.;56 fstep = 1.; 57 57 58 58 for (loop=0;loop<20;loop++)
