Changeset 2426 for branches/newmole
- Timestamp:
- 10/27/08 15:50:47 (2 months ago)
- Location:
- branches/newmole/source
- Files:
-
- 3 modified
-
mole.h (modified) (1 diff)
-
mole_solve.cpp (modified) (11 diffs)
-
newton_step.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/newmole/source/mole.h
r2356 r2426 192 192 extern struct chem_element_s *element_list[LIMELM]; 193 193 194 template<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 194 199 #endif /* _MOLE_H_ */ -
branches/newmole/source/mole_solve.cpp
r2420 r2426 46 46 #define SMALLABUND 1e-24 47 47 48 static double mol num[LIMELM];48 static double molElems[LIMELM],molElemsNew[LIMELM]; 49 49 50 50 double mole_solve() … … 106 106 107 107 MoleMap.setup(&oldmols[0]); 108 109 grouped_elems(&oldmols[0],molElems); 108 110 109 111 long j; … … 113 115 newton_step(oldmols, newmols, &error, mole.num_compacted, &rlimit, escale, funjac); 114 116 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 115 129 /* check for negative populations */ 116 130 nBad = 0; … … 418 432 } 419 433 } 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 } 420 448 421 449 for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) … … 436 464 } 437 465 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 438 479 /* Species are now grouped -- only mole.num_compacted elements now active */ 439 480 440 481 /* For Newton-Raphson method, want the change in populations to be zero, 441 482 * 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 { 449 495 for(i=0;i<mole.num_compacted;i++) 450 496 { 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); 466 504 } 467 505 } … … 480 518 double molnow[LIMELM]; 481 519 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 494 522 iamax = 0; 495 523 for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) … … 534 562 } 535 563 } 536 b[ncons[nelem]] = (molnow[nelem]-mol num[nelem]);564 b[ncons[nelem]] = (molnow[nelem]-molElems[nelem]); 537 565 //fprintf(ioQQQ,"Elem %ld err %g\n",nelem,b[ncons[nelem]]); 538 566 } … … 568 596 for (nelem=ipHYDROGEN;nelem<LIMELM;nelem++) 569 597 { 570 u[i][nelem] = mole.list[groupspecies[i]->index]->nElem[nelem];598 u[i][nelem] = groupspecies[i]->nElem[nelem]; 571 599 } 572 600 } … … 698 726 ervals[i] = b[groupspecies[i]->index]; 699 727 } 700 728 701 729 if (lgJac) 702 730 { … … 711 739 } 712 740 } 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 713 752 } 714 753 … … 799 838 b0vec[i] = calcv[groupspecies[i]->index]; 800 839 } 801 grouped_elems(&b0vec[0],molnum);802 840 } 803 841 -
branches/newmole/source/newton_step.cpp
r2123 r2426 86 86 } 87 87 } 88 *rlimit *= 1e- 11;88 *rlimit *= 1e-8; 89 89 } 90 90 for( i=0; i < n; i++ )
