Changeset 1676 for branches/newmole/source
- Timestamp:
- 12/15/07 08:24:13 (11 months ago)
- Location:
- branches/newmole/source
- Files:
-
- 5 modified
-
cddrive.cpp (modified) (1 diff)
-
mole.h (modified) (1 diff)
-
mole_co_solve.cpp (modified) (7 diffs)
-
mole_newton_step.cpp (modified) (18 diffs)
-
prt_final.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/newmole/source/cddrive.cpp
r1610 r1676 2102 2102 fflush( ioQQQ ); 2103 2103 /* stderr is always unbuffered */ 2104 ioQQQ = stderr; 2104 //ioQQQ = stderr; 2105 setvbuf( ioQQQ, NULL, _IONBF, 0); 2105 2106 /* will be used to generate comment at end */ 2106 input.lgSetNoBuffering = false;2107 input.lgSetNoBuffering = true; 2107 2108 } 2108 2109 } -
branches/newmole/source/mole.h
r1658 r1676 42 42 43 43 /** Take one Newton step of the chemical network 44 \param *n Fixup44 \param *nBad 45 45 \param *error 46 46 */ 47 void mole_newton_step(int *n Fixup, realnum *error, realnum numelem[]);47 void mole_newton_step(int *nBad, realnum *error, realnum numelem[]); 48 48 49 49 /** \verbatim >>chng 03 feb 09, rm ipH3P_hev, since not used, and decrement NUM_HEAVY_MOLEC to 17 -
branches/newmole/source/mole_co_solve.cpp
r1658 r1676 36 36 static void mole_h_fixup(void); 37 37 /**hmole determine populations of hydrogen molecules */ 38 STATIC double hmole( bool *lgNegPop, bool *lgZerPop);38 STATIC double hmole( void ); 39 39 40 40 … … 62 62 ASSERT(lgElemsConserved()); 63 63 64 error = hmole( lgNegPop, lgZerPop);64 error = hmole(); 65 65 66 66 ASSERT(lgElemsConserved()); … … 196 196 * For conditions of distribution and use see copyright notice in license.txt */ 197 197 /*hmole determine populations of hydrogen molecules */ 198 STATIC double hmole( bool *lgNegPop, bool *lgZerPop)198 STATIC double hmole( void ) 199 199 { 200 int n Fixup, i, nelem;200 int nBad, i, nelem; 201 201 realnum error, 202 202 numelem[LIMELM], … … 227 227 /* loop until run to limit, or no fix ups needed and error is small */ 228 228 /* will be used to keep track of neg solns */ 229 n Fixup= 0;229 nBad = 0; 230 230 error = -1.; 231 231 for(i=0; i < LIM_LOOP;i++) … … 247 247 } 248 248 } 249 /* nFixup is number of times negative abundances were fixed, should be zero 250 * at return for valid soln */ 251 nFixup = 0; 252 253 mole_newton_step(&nFixup, &error, numelem); 249 /* nBad returns number of times negative abundances were fixed 250 * for latest step, should be zero at return for valid soln */ 251 252 mole_newton_step(&nBad, &error, numelem); 254 253 255 //fprintf(stdout,"Hmole zone %ld -- %7.2f loop %d error %15.8g fixup %d\n",nzone,fnzone,i,error,n Fixup);254 //fprintf(stdout,"Hmole zone %ld -- %7.2f loop %d error %15.8g fixup %d\n",nzone,fnzone,i,error,nBad); 256 255 257 256 { … … 284 283 } 285 284 } 286 if (error < BIGERROR && !nFixup) /* Stop early if good enough */ 285 286 if (error < BIGERROR && nBad == 0) /* Stop early if good enough */ 287 287 break; 288 288 } 289 289 290 if( (i == LIM_LOOP && error > BIGERROR) || n Fixup!= 0 )290 if( (i == LIM_LOOP && error > BIGERROR) || nBad != 0 ) 291 291 { 292 292 /* most of these failures occur just one time during search phase - … … 294 294 conv.lgConvPops = false; 295 295 296 if( !conv.lgSearch && called.lgTalk )296 if( 1||!conv.lgSearch && called.lgTalk ) 297 297 { 298 298 fprintf(ioQQQ," PROBLEM hmole, zone %li: %d iters, %d bad; final error: %g lgSearch %i\n", 299 299 nzone, 300 300 i, 301 n Fixup,301 nBad, 302 302 error, 303 303 conv.lgSearch); -
branches/newmole/source/mole_newton_step.cpp
r1658 r1676 40 40 /* mole_newton_step -- improve balance in chemical network along 41 41 * descent direction, step limited to ensure improvement */ 42 void mole_newton_step(int *n Fixup, realnum *error, realnum numelem[])42 void mole_newton_step(int *nBad, realnum *error, realnum numelem[]) 43 43 { 44 44 enum {PRINTSOL = false}; … … 76 76 *calcv=NULL, 77 77 *b=NULL, 78 **c=NULL, 79 *scalev; 78 **c=NULL; 80 79 int32 merror; 81 80 double maxrate = 0., … … 96 95 b1vec = ((double*)MALLOC( (size_t)(mole.num_compacted)*sizeof(double) )); 97 96 b2vec = ((double*)MALLOC( (size_t)(mole.num_compacted)*sizeof(double) )); 98 scalev = ((double*)MALLOC( (size_t)(mole.num_compacted)*sizeof(double) ));99 97 if (mole.num_calc != 0) 100 98 { … … 180 178 error1 = grad = 0.; 181 179 fstep = flast = 1.; 182 *n Fixup= 0;180 *nBad = 0; 183 181 184 182 lgNegPop = false; … … 196 194 197 195 /* add positive ions and neutral atoms: ratios are set by ion_solver, 198 * we determine abundance of the group as a wholehere */196 * we determine sum of two here */ 199 197 200 198 if (loop == 0) { … … 237 235 } 238 236 } 239 maxrate = 0.0;240 for(i=0;i<mole.num_compacted;i++)241 {242 if (-c[groupspecies[i]->index][groupspecies[i]->index] > maxrate)243 maxrate = -c[groupspecies[i]->index][groupspecies[i]->index];244 }245 for(i=0;i<mole.num_compacted;i++)246 {247 //ASSERT (c[COmole[i]->index][COmole[i]->index] < 0);248 scalev[groupspecies[i]->index] = 1./(1e-6*maxrate-c[groupspecies[i]->index][groupspecies[i]->index]);249 for (j=0;j<mole.num_compacted;j++)250 {251 c[groupspecies[j]->index][groupspecies[i]->index] *= scalev[groupspecies[i]->index];252 }253 }254 237 } 255 238 … … 271 254 } 272 255 273 for (i=0;i<mole.num_compacted;++i)274 {275 b[groupspecies[i]->index] *= scalev[groupspecies[i]->index];276 }277 278 256 /* For Newton-Raphson method, want the change in populations to be zero, 279 257 * so the conserved component must also be zero */ … … 308 286 for( i=0; i < mole.num_compacted; i++ ) 309 287 { 310 etmp = (b[groupspecies[i]->index]-scalerate*(b2vec[i]-b0vec[i])); 288 /* Smooth the error mode tailoff */ 289 etmp = (b[groupspecies[i]->index]-scalerate*(b2vec[i]-b0vec[i]))/ 290 ((ABSLIM+b0vec[i])*(-c[groupspecies[i]->index][groupspecies[i]->index])); 311 291 etmp *= etmp; 312 292 if (etmp > emax) … … 321 301 } 322 302 323 // fprintf(stdout,"Loop %ld error %15.8g fstep %15.8g; worst species %s abund %gerror %g\n",324 // loop,error0,fstep,groupspecies[iworst]->label,groupspecies[iworst]->hevmol, emax);303 // fprintf(stdout,"Loop %ld error %15.8g fstep %15.8g; worst species %s abund %g error %g\n", 304 // loop,error0,fstep,groupspecies[iworst]->label,groupspecies[iworst]->hevmol,,emax); 325 305 326 306 /*------------------------------------------------------------------ */ … … 397 377 groupspecies[i]->hevmol, 398 378 -b1vec[i]); */ 379 if(b0vec[i] > 1e-12) 380 { 381 fixit(); /* Nadger low populations -- magic number */ 399 382 400 if (b0vec[i]-b1vec[i] < 0) 401 fprintf(stdout,"Bad NR step for %s wants %g step %g orig %g\n",groupspecies[i]->label,b0vec[i]-b1vec[i],b1vec[i],b0vec[i]); 402 if (fstep*(1e-24+b1vec[i]) > 0.9*(1e-24+b0vec[i])) 403 { 404 fstep = 0.9*(1e-24+b0vec[i])/(1e-24+b1vec[i]); 405 iworst = i; 406 fprintf(stdout,"Limiting %s %g %g %g\n",groupspecies[i]->label,b0vec[i],b1vec[i],fstep); 407 } 408 } 409 // if (fstep < 0.1*flast) 410 // fstep = 0.1*flast; 383 if (b0vec[i]-b1vec[i] < 0) 384 fprintf(stdout,"Bad NR step for %s %g %g\n",groupspecies[i]->label,b0vec[i],b1vec[i]); 385 if (fstep*b1vec[i] > 0.9*(ABSLIM+b0vec[i])) 386 { 387 fstep = 0.9*(ABSLIM+b0vec[i])/(b1vec[i]); 388 iworst = i; 389 } 390 } 391 392 } 393 if (fstep < 0.1*flast) 394 fstep = 0.1*flast; 411 395 } 412 396 //fprintf(ioQQQ,"Step factor %g bad species %s abund %g step %g\n", … … 420 404 // iworst!=-1?-b1vec[iworst]:0.); 421 405 //fprintf(stdout,"Grads %g %g (%g %g)\n",grad,(error0-error1)/fstep,error0,error1); 422 if ( (error0 < (1-2e-4*fstep)*error1 || error0 < 1e-20))406 if (!lgNegPop && (error0 < (1-2e-4*fstep)*error1 || error0 < 1e-20)) 423 407 { 424 408 // fprintf(stdout,"OK %g %g\n",error0,error1); 425 409 break; 426 }427 else428 {429 // fprintf(ioQQQ,"Continuing: tests %c %g %g\n",TorF(lgNegPop),error0,(1-2e-4*fstep)*error1-error0);430 410 } 431 411 fstep = -0.5*grad*fstep*fstep/SDIV(error0-error1-grad*fstep); … … 518 498 /* check for negative populations */ 519 499 lgNegPop = false; 520 *n Fixup= 0;500 *nBad = 0; 521 501 fracneg = 0.; 522 502 iworst = -1; … … 525 505 if( b2vec[i] < 0. ) 526 506 { 527 // fprintf(stdout,"Species %s negative at %g from %g\n",groupspecies[i]->label,b2vec[i],b0vec[i]);507 // fprintf(stdout,"Species %s negative at %g from %g\n",groupspecies[i]->label,b2vec[i],b0vec[i]); 528 508 /* largest relative change in solution for neg soln */ 529 509 /* this can only occur for negative solutions since fracneg starts … … 534 514 iworst = i; 535 515 } 536 if (b2vec[i] < -SMALLABUND) 537 lgNegPop = true; 538 b2vec[i] = 0.; 539 } 540 } 516 //if (b2vec[i] < -SMALLABUND) 517 // lgNegPop = true; 518 //b2vec[i] = 0.; 519 } 520 } 521 541 522 542 523 # if 0 … … 566 547 { 567 548 if (b0vec[i] > SMALLABUND) 568 ++*n Fixup;549 ++*nBad; 569 550 } 570 551 } … … 578 559 { 579 560 if (b0vec[i] > SMALLABUND) 580 ++*n Fixup;561 ++*nBad; 581 562 if (0) 582 563 b2vec[i] = 0.; … … 586 567 /* very common to obtain negative solution on very first try - 587 568 * don't print in this case */ 588 if( 0 && *nFixup> 0)569 if(*nBad > 0) 589 570 { 590 571 fprintf( ioQQQ, " PROBLEM hmole_step finds negative H molecule, in zone %.2f, loop %ld step %g.\n",fnzone,loop,fstep ); … … 882 863 if ( merror != 0 ) 883 864 { 884 fprintf( ioQQQ, " CO_solve getrf_wrapper error %ld\n", merror );865 fprintf( ioQQQ, " CO_solve getrf_wrapper error %ld\n",(long int) merror ); 885 866 puts( "[Stop in CO_solve]" ); 886 867 cdEXIT(EXIT_FAILURE); -
branches/newmole/source/prt_final.cpp
r1610 r1676 1940 1940 /* print input title for model */ 1941 1941 fprintf( ioQQQ, "%s\n\n", input.chTitle ); 1942 fflush(ioQQQ); 1942 1943 return; 1943 1944 }
