Changeset 2054 for branches/newmole/source
- Timestamp:
- 05/13/08 16:02:39 (8 months ago)
- Location:
- branches/newmole/source
- Files:
-
- 2 modified
-
mole_solve.cpp (modified) (1 diff)
-
newton_step.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/newmole/source/mole_solve.cpp
r2050 r2054 19 19 #include "newton_step.h" 20 20 #include "householder.h" 21 /* Nick Abel between July and October of 2003 assisted Dr. Ferland in improving the heavy element 22 * molecular network in Cloudy. Before this routine would predict negative abundances if 23 * the fraction of carbon in the form of molecules came close to 100%. A reorganizing of 24 * the reaction network detected several bugs. Treatment of "coupled reactions", 25 * in which both densities in the reaction rate were being predicted by Cloudy, were also 26 * added. Due to these improvements, Cloudy can now perform calculations 27 * where 100% of the carbon is in the form of CO without predicting negative abundances 21 /* Nick Abel between July and October of 2003 assisted Dr. Ferland in 22 * improving the heavy element molecular network in Cloudy. Before 23 * this routine would predict negative abundances if the fraction of 24 * carbon in the form of molecules came close to 100%. A reorganizing 25 * of the reaction network detected several bugs. Treatment of 26 * "coupled reactions", in which both densities in the reaction rate 27 * were being predicted by Cloudy, were also added. Due to these 28 * improvements, Cloudy can now perform calculations where 100% of the 29 * carbon is in the form of CO without predicting negative abundances 28 30 * 29 31 * Additional changes were made in November of 2003 so that our reaction -
branches/newmole/source/newton_step.cpp
r2031 r2054 32 32 etmp, 33 33 emax, 34 fstep, 35 flast, 34 f1, 35 f2, 36 error2, 36 37 error1, 37 38 error0, … … 52 53 } 53 54 54 error0 = 1; 55 error1 = grad = 0.; 56 fstep = 1.; 55 error0 = error2 = grad = f1 = f2 = 0.; 57 56 58 57 for (loop=0;loop<20;loop++) 59 58 { 60 flast = fstep;61 62 59 jacobn(b2vec,&ervals[0],&amat[0],loop==0); 63 60 … … 70 67 } 71 68 72 error 0= emax = 0.;69 error1 = emax = 0.; 73 70 iworst = -1; 74 71 for( i=0; i < n; i++ ) … … 82 79 iworst = i; 83 80 } 84 error 0+= etmp;81 error1 += etmp; 85 82 } 86 83 … … 92 89 } 93 90 merror = solve_system(amat,b1vec,n); 94 error1 = error0; 95 grad = -2*error1; 91 error0 = error1; 92 grad = -2*error0; 93 f1 = 1.0; 96 94 } else { 97 if (error 0 < (1-2e-4*fstep)*error1 || error0< 1e-20)95 if (error1 < (1-2e-4*f1)*error0 || error1 < 1e-20) 98 96 { 99 97 break; 98 } 99 if (loop == 1) 100 { 101 f2 = 1.; 102 f1 = -0.5*grad/SDIV(error1-error0-grad); 100 103 } 101 fstep = -0.5*grad*fstep*fstep/SDIV(error0-error1-grad*fstep); 102 if (fstep > 0.9*flast || fstep < 0.) 103 fstep = 0.5*flast; 104 if (fstep < 0.1*flast) 105 fstep = 0.1*flast; 104 else 105 { 106 // Update using cubic fit, ref Dennis & Schnabel 1996 107 double a1 = error1-error0-grad*f1; 108 double b1 = error2-error0-grad*f2; 109 double a = (a1/(f1*f1)-b1/(f2*f2)); 110 double b = (-f2*a1/(f1*f1)+f1*b1/(f2*f2)); 111 double ft = f1; 112 f1 = (-b+sqrt(b*b-3*a*grad*(f1-f2)))/(3*a); 113 f2 = ft; 114 } 115 error2 = error1; 116 if (f1 > 0.5*f2 || f1 < 0.) 117 f1 = 0.5*f2; 118 else if (f1 < 0.1*f2) 119 f1 = 0.1*f2; 106 120 } 107 121 … … 113 127 for( i=0; i < n; i++ ) 114 128 { 115 b2vec[i] = b0vec[i]-b1vec[i]*f step;129 b2vec[i] = b0vec[i]-b1vec[i]*f1; 116 130 } 117 131 } 118 132 119 *error = (realnum) MIN2(error 0,1e30);133 *error = (realnum) MIN2(error1,1e30); 120 134 121 135 return;
