Changeset 2031 for branches/newmole/source/mole_solve.cpp
- Timestamp:
- 05/07/08 16:29:10 (8 months ago)
- Files:
-
- 1 modified
-
branches/newmole/source/mole_solve.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 {
