Changeset 6e72989 in sasmodels
- Timestamp:
- Oct 3, 2017 9:21:07 AM (7 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 3a220e6
- Parents:
- b76191e
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
explore/precision.py
r487e695 r6e72989 321 321 np_function=lambda x: np.fmod(x, 2*np.pi), 322 322 ocl_function=make_ocl("return fmod(q, 2*M_PI);", "sas_fmod"), 323 ) 324 add_function( 325 name="debye", 326 mp_function=lambda x: 2*(mp.exp(-x**2) + x**2 - 1)/x**4, 327 np_function=lambda x: 2*(np.exp(-x**2) + x**2 - 1)/x**4, 328 ocl_function=make_ocl(""" 329 const double qsq = q*q; 330 if (qsq < 0.1) { 331 const double x = qsq; 332 const double C0 = +1.; 333 const double C1 = -1./3.; 334 const double C2 = +1./12.; 335 const double C3 = -1./60.; 336 const double C4 = +1./360.; 337 const double C5 = -1./2520.; 338 const double C6 = +1./20160.; 339 const double C7 = -1./181440.; 340 //return ((((C5*x + C4)*x + C3)*x + C2)*x + C1)*x + C0; 341 return (((((C6*x + C5)*x + C4)*x + C3)*x + C2)*x + C1)*x + C0; 342 //return ((((((C7*x + C6)*x + C5)*x + C4)*x + C3)*x + C2)*x + C1)*x + C0; 343 } /* else if (qsq < 1.0) { 344 // taylor series around q^2 = 0.5 345 const double x = qsq - 0.5; 346 const double sqrt_e = sqrt(M_E); 347 const double C0 = 8./sqrt_e - 4.; 348 const double C1 = 24. - 40./sqrt_e; 349 const double C2 = 132./sqrt_e - 80.; 350 const double C3 = 224. - 1108./(3.*sqrt_e); 351 const double C4 = 2849./(3.*sqrt_e) - 576.; 352 const double C5 = 1408 - 11607./(5.*sqrt_e); 353 return ((((C5*x + C4)*x + C3)*x + C2)*x + C1)*x + C0; 354 } */ else { 355 return 2.*(exp(-qsq) + qsq - 1.)/(qsq*qsq); 356 } 357 """, "sas_debye"), 323 358 ) 324 359 -
sasmodels/models/lib/wrc_cyl.c
r92ce163 r6e72989 2 2 Functions for WRC implementation of flexible cylinders 3 3 */ 4 double Sk_WR(double q, double L, double b); 5 6 7 static double 8 AlphaSquare(double x) 9 { 10 // Potentially faster. Needs proper benchmarking. 11 // add native_powr to kernel_template 12 //double t = native_powr( (1.0 + (x/3.12)*(x/3.12) + 13 // (x/8.67)*(x/8.67)*(x/8.67)),(0.176/3.0) ); 14 //return t; 15 16 return pow(1.0+square(x/3.12)+cube(x/8.67), 0.176/3.0); 17 } 18 19 // 20 static double 21 Rgsquarezero(double q, double L, double b) 4 5 static double 6 Rgsquare(double L, double b) 7 { 8 const double x = L/b; 9 // Use Horner's method to evaluate: 10 // pow(1.0+square(x/3.12)+cube(x/8.67), 0.176/3.0) 11 // Too many digits on the coefficients, but necessary for consistency 12 const double alphasq = 13 pow(1.0 + square(x)*(1.534414548417740e-03*x + 1.027284681130835e-01), 14 5.866666666666667e-02); 15 return alphasq*L*b/6.0; 16 } 17 18 static double 19 Rgsquareshort(double L, double b) 22 20 { 23 21 const double r = b/L; 24 return (L*b/6.0) * (1.0 + r*(-1.5 + r*(1.5 + r*0.75*expm1(-2.0/r)))); 25 26 } 27 28 // 29 static double 30 Rgsquareshort(double q, double L, double b) 31 { 32 return AlphaSquare(L/b) * Rgsquarezero(q,L,b); 33 } 34 35 // 36 static double 37 Rgsquare(double q, double L, double b) 38 { 39 return AlphaSquare(L/b)*L*b/6.0; 40 } 41 42 static double 43 sech_WR(double x) 44 { 45 return(1/cosh(x)); 46 } 47 48 static double 49 a1long(double q, double L, double b, double p1, double p2, double q0) 50 { 51 double C; 52 53 if( L/b > 10.0) { 54 C = 3.06/pow((L/b),0.44); 55 } else { 56 C = 1.0; 57 } 22 return Rgsquare(L, b) * (1.0 + r*(-1.5 + r*(1.5 + r*0.75*expm1(-2.0/r)))); 23 } 24 25 static double 26 a_long(double qp, double L, double b/*, double p1, double p2, double q0*/) 27 { 28 // Note: caller sends p1, p2, q0 in as constants. 29 const double p1 = 4.12; 30 const double p2 = 4.42; 31 const double q0 = 3.1; 58 32 59 33 const double C1 = 1.22; … … 64 38 const double miu = 0.585; 65 39 66 const double Rg2 = Rgsquare(q,L,b); 67 const double Rg22 = Rg2*Rg2; 68 const double Rg = sqrt(Rg2); 69 const double Rgb = Rg*q0/b; 70 71 const double b2 = b*b; 40 41 const double C = (L/b>10.0 ? 3.06*pow(L/b, -0.44) : 1.0); 42 const double r2 = Rgsquare(L,b); 43 const double r = sqrt(r2); 44 const double qr_b = q0*r/b; 45 const double qr_b_sq = qr_b*qr_b; 46 const double qr_b_4 = qr_b_sq*qr_b_sq; 47 const double qr_b_miu = pow(qr_b, -1.0/miu); 48 const double em1_qr_b_sq = expm1(-qr_b_sq); 49 const double sech2 = 1.0/square(cosh((qr_b-C4)/C5)); 50 const double tanh1m = 1.0 - tanh(-C4 + qr_b/C5); 51 52 const double t1 = pow(q0, 1.0 + p1 + p2)/(b*(p1-p2)); 53 const double t2 = C/(15.0*L) * ( 54 + 14.0*b*b*em1_qr_b_sq/(q0*qr_b_sq) 55 + 2.0*q0*r2*exp(-qr_b_sq)*(11.0 + 7.0/qr_b_sq)); 56 const double t11 = ((C3*qr_b_miu + C2)*qr_b_miu + C1)*qr_b_miu; 57 const double t3 = r*sech2/(2.*C5)*t11; 58 const double t4 = r*(em1_qr_b_sq + qr_b_sq)*sech2 / (C5*qr_b_4); 59 const double t5 = -2.0 * r*qr_b*em1_qr_b_sq * tanh1m / qr_b_4; 60 const double t10 = (em1_qr_b_sq + qr_b_sq) * tanh1m / qr_b_4; 61 const double t6 = 4.0*b/q0 * t10; 62 const double t7 = r*((-3.0*C3*qr_b_miu -2.0*C2)*qr_b_miu -1.0*C1)*qr_b_miu/(miu*qr_b); 63 const double t8 = 2.0 - tanh1m; 64 const double t9 = b*C/(15.0*L) * (4.0 - exp(-qr_b_sq) * (11.0 + 7.0/qr_b_sq) + 7.0/qr_b_sq); 65 const double t12 = b*b*M_PI/(L*q0*q0) + t2 + t3 - t4 + t5 - t6 + 0.5*t7*t8; 66 const double t13 = -b*M_PI/(L*q0) + t9 + t10 + 0.5*t11*t8; 67 68 const double a1 = pow(q0,p1)*t13 - t1*pow(q0,-p2)*(t12 + b*p1/q0*t13); 69 const double a2 = t1*pow(q0,-p1)*(t12 + b*p1/q0*t13); 70 71 const double ans = a1*pow(qp*b, -p1) + a2*pow(qp*b, -p2) + M_PI/(qp*L); 72 return ans; 73 } 74 75 static double 76 _short(double r2, double exp_qr_b, double L, double b, double p1short, 77 double p2short, double q0) 78 { 79 const double qr2 = q0*q0 * r2; 72 80 const double b3 = b*b*b; 73 const double b4 = b3*b; 74 const double q02 = q0*q0; 75 const double q03 = q0*q0*q0; 76 const double q04 = q03*q0; 77 const double q05 = q04*q0; 78 79 const double Rg02 = Rg2*q02; 80 81 const double t1 = (b*C*((4.0/15.0 - pow((double)M_E,(-(Rg02/b2))) * 82 ((11.0/15.0 + (7.0*b2)/(15.0*Rg02))) + 83 (7.0*b2)/(15.0*Rg02)))); 84 85 const double t2 = (2.0*b4*(((-1.0) + pow((double)M_E,(-(Rg02/b2))) + 86 Rg02/b2))*((1.0 + 0.5*(((-1.0) - 87 tanh((-C4 + Rgb/C5))))))); 88 89 const double t3 = ((C3*pow(Rgb,((-3.0)/miu)) + 90 C2*pow(Rgb,((-2.0)/miu)) + 91 C1*pow(Rgb,((-1.0)/miu)))); 92 93 const double t4 = ((1.0 + tanh(((-C4) + Rgb)/C5))); 94 95 const double t5 = (1.0/(b*p1*pow(q0,((-1.0) - p1 - p2)) - 96 b*p2*pow(q0,((-1.0) - p1 - p2)))); 97 98 const double t6 = (b*C*(((-((14.0*b3)/(15.0*q03*Rg2))) + 99 (14.0*b3*pow((double)M_E,(-(Rg02/b2))))/(15.0*q03*Rg2) + 100 (2.0*pow((double)M_E,(-(Rg02/b2)))*q0*((11.0/15.0 + 101 (7.0*b2)/(15.0*Rg02)))*Rg2)/b))); 102 103 const double t7 = (Rg*((C3*pow(((Rgb)),((-3.0)/miu)) + 104 C2*pow(((Rgb)),((-2.0)/miu)) + 105 C1*pow(((Rgb)),((-1.0)/miu))))*pow(sech_WR(((-C4) + 106 Rgb)/C5),2)); 107 108 const double t8 = (b4*Rg*(((-1.0) + pow((double)M_E,(-(Rg02/b2))) + 109 Rg02/b2))*pow(sech_WR(((-C4) + Rgb)/C5),2)); 110 111 const double t9 = (2.0*b4*(((2.0*q0*Rg2)/b - 112 (2.0*pow((double)M_E,(-(Rg02/b2)))*q0*Rg2)/b))*((1.0 + 0.5*(((-1.0) - 113 tanh(((-C4) + Rgb)/C5)))))); 114 115 const double t10 = (8.0*b4*b*(((-1.0) + pow((double)M_E,(-(Rg02/b2))) + 116 Rg02/b2))*((1.0 + 0.5*(((-1.0) - tanh(((-C4) + 117 Rgb)/C5)))))); 118 119 const double t11 = (((-((3.0*C3*Rg*pow(((Rgb)),((-1.0) - 120 3.0/miu)))/miu)) - (2.0*C2*Rg*pow(((Rgb)),((-1.0) - 121 2.0/miu)))/miu - (C1*Rg*pow(((Rgb)),((-1.0) - 122 1.0/miu)))/miu)); 123 124 const double t12 = ((1.0 + tanh(((-C4) + Rgb)/C5))); 125 126 const double t13 = (b*C*((4.0/15.0 - pow((double)M_E,(-(Rg02/b2)))*((11.0/15.0 + 127 (7.0*b2)/(15.0*q02* Rg2))) + 128 (7.0*b2)/(15.0*Rg02)))); 129 130 const double t14 = (2.0*b4*(((-1.0) + pow((double)M_E,(-(Rg02/b2))) + 131 Rg02/b2))*((1.0 + 0.5*(((-1.0) - tanh(((-C4) + 132 Rgb)/C5)))))); 133 134 const double t15 = ((C3*pow(((Rgb)),((-3.0)/miu)) + 135 C2*pow(((Rgb)),((-2.0)/miu)) + 136 C1*pow(((Rgb)),((-1.0)/miu)))); 137 138 139 double yy = (pow(q0,p1)*(((-((b*M_PI)/(L*q0))) +t1/L +t2/(q04*Rg22) + 140 0.5*t3*t4)) + (t5*((pow(q0,(p1 - p2))* 141 (((-pow(q0,(-p1)))*(((b2*M_PI)/(L*q02) +t6/L +t7/(2.0*C5) - 142 t8/(C5*q04*Rg22) + t9/(q04*Rg22) -t10/(q05*Rg22) + 0.5*t11*t12)) - 143 b*p1*pow(q0,((-1.0) - p1))*(((-((b*M_PI)/(L*q0))) + t13/L + 144 t14/(q04*Rg22) + 0.5*t15*((1.0 + tanh(((-C4) + 145 Rgb)/C5))))))))))); 146 147 return (yy); 148 } 149 150 static double 151 a2long(double q, double L, double b, double p1, double p2, double q0) 152 { 153 double C; 154 155 if( L/b > 10.0) { 156 C = 3.06/pow((L/b),0.44); 81 const double q0p = pow(q0, -4.0 + p1short); 82 83 double yy = 1.0/(L*r2*r2) * b/exp_qr_b*q0p 84 * (8.0*b3*L 85 - 8.0*b3*exp_qr_b*L 86 + 2.0*b3*exp_qr_b*L*p2short 87 - 2.0*b*exp_qr_b*L*p2short*qr2 88 + 4.0*b*exp_qr_b*L*qr2 89 - 2.0*b3*L*p2short 90 + 4.0*b*L*qr2 91 - M_PI*exp_qr_b*qr2*q0*r2 92 + M_PI*exp_qr_b*p2short*qr2*q0*r2); 93 94 return yy; 95 } 96 static double 97 a_short(double qp, double L, double b 98 /*double p1short, double p2short*/, double q0) 99 { 100 const double p1short = 5.36; 101 const double p2short = 5.62; 102 103 const double r2 = Rgsquareshort(L,b); 104 const double exp_qr_b = exp(r2*square(q0/b)); 105 const double pdiff = p1short - p2short; 106 const double a1 = _short(r2,exp_qr_b,L,b,p1short,p2short,q0)/pdiff; 107 const double a2= -_short(r2,exp_qr_b,L,b,p2short,p1short,q0)/pdiff; 108 const double ans = a1*pow(qp*b, -p1short) + a2*pow(qp*b, -p2short) + M_PI/(qp*L); 109 return ans; 110 } 111 112 //WR named this w (too generic) 113 static double 114 w_WR(double x) 115 { 116 return 0.5*(1 + tanh((x - 1.523)/0.1477)); 117 } 118 119 static double 120 Sdebye(double qsq) 121 { 122 #if FLOAT_SIZE>4 123 #define DEBYE_CUTOFF 0.01 // 1e-13 error 124 #else 125 #define DEBYE_CUTOFF 1.0 // 1e-7 error 126 #endif 127 128 if (qsq < DEBYE_CUTOFF) { 129 const double x = qsq; 130 const double C0 = +1.; 131 const double C1 = -1./3.; 132 const double C2 = +1./12.; 133 const double C3 = -1./60.; 134 const double C4 = +1./360.; 135 const double C5 = -1./2520.; 136 const double C6 = +1./20160.; 137 const double C7 = -1./181440.; 138 return ((((((C7*x + C6)*x + C5)*x + C4)*x + C3)*x + C2)*x + C1)*x + C0; 139 /* failed attempt to improve double precision better than 1e-13 140 } else if (qsq < 1.0) { 141 // taylor series around q^2 = 0.5 142 const double x = qsq - 0.5; 143 const double sqrt_e = sqrt(M_E); 144 const double C0 = 8./sqrt_e - 4.; 145 const double C1 = 24. - 40./sqrt_e; 146 const double C2 = 132./sqrt_e - 80.; 147 const double C3 = 224. - 1108./(3.*sqrt_e); 148 const double C4 = 2849./(3.*sqrt_e) - 576.; 149 const double C5 = 1408 - 11607./(5.*sqrt_e); 150 return ((((C5*x + C4)*x + C3)*x + C2)*x + C1)*x + C0; 151 */ 157 152 } else { 158 C = 1.0;153 return 2.*(exp(-qsq) + qsq - 1.)/(qsq*qsq); 159 154 } 160 161 const double C1 = 1.22; 162 const double C2 = 0.4288; 163 const double C3 = -1.651; 164 const double C4 = 1.523; 165 const double C5 = 0.1477; 166 const double miu = 0.585; 167 168 const double Rg2 = Rgsquare(q,L,b); 169 const double Rg22 = Rg2*Rg2; 170 const double b2 = b*b; 171 const double b3 = b*b*b; 172 const double b4 = b3*b; 173 const double q02 = q0*q0; 174 const double q03 = q0*q0*q0; 175 const double q04 = q03*q0; 176 const double q05 = q04*q0; 177 const double Rg = sqrt(Rg2); 178 const double Rgb = Rg*q0/b; 179 const double Rg02 = Rg2*q02; 180 181 const double t1 = (1.0/(b* p1*pow(q0,((-1.0) - p1 - p2)) - 182 b*p2*pow(q0,((-1.0) - p1 - p2)) )); 183 184 const double t2 = (b*C*(((-1.0*((14.0*b3)/(15.0*q03*Rg2))) + 185 (14.0*b3*pow((double)M_E,(-(Rg02/b2))))/(15.0*q03*Rg2) + 186 (2.0*pow((double)M_E,(-(Rg02/b2)))*q0*((11.0/15.0 + 187 (7*b2)/(15.0*Rg02)))*Rg2)/b)))/L; 188 189 const double t3 = (Rg*((C3*pow(((Rgb)),((-3.0)/miu)) + 190 C2*pow(((Rgb)),((-2.0)/miu)) + 191 C1*pow(((Rgb)),((-1.0)/miu))))* 192 pow(sech_WR(((-C4) +Rgb)/C5),2.0))/(2.0*C5); 193 194 const double t4 = (b4*Rg*(((-1.0) + pow((double)M_E,(-(Rg02/b2))) + 195 Rg02/b2))*pow(sech_WR(((-C4) + 196 Rgb)/C5),2))/(C5*q04*Rg22); 197 198 const double t5 = (2.0*b4*(((2.0*q0*Rg2)/b - 199 (2.0*pow((double)M_E,(-(Rg02/b2)))*q0*Rg2)/b))* 200 ((1.0 + 0.5*(((-1.0) - tanh(((-C4) + 201 Rgb)/C5))))))/(q04*Rg22); 202 203 const double t6 = (8.0*b4*b*(((-1.0) + pow((double)M_E,(-(Rg02/b2))) + 204 Rg02/b2))*((1.0 + 0.5*(((-1) - tanh(((-C4) + 205 Rgb)/C5))))))/(q05*Rg22); 206 207 const double t7 = (((-((3.0*C3*Rg*pow(((Rgb)),((-1.0) - 208 3.0/miu)))/miu)) - (2.0*C2*Rg*pow(((Rgb)), 209 ((-1.0) - 2.0/miu)))/miu - (C1*Rg*pow(((Rgb)), 210 ((-1.0) - 1.0/miu)))/miu)); 211 212 const double t8 = ((1.0 + tanh(((-C4) + Rgb)/C5))); 213 214 const double t9 = (b*C*((4.0/15.0 - pow((double)M_E,(-(Rg02/b2)))*((11.0/15.0 + 215 (7.0*b2)/(15*Rg02))) + (7.0*b2)/(15.0*Rg02))))/L; 216 217 const double t10 = (2.0*b4*(((-1) + pow((double)M_E,(-(Rg02/b2))) + 218 Rg02/b2))*((1.0 + 0.5*(((-1) - tanh(((-C4) + 219 Rgb)/C5))))))/(q04*Rg22); 220 221 const double yy = ((-1.0*(t1* ((-pow(q0,-p1)*(((b2*M_PI)/(L*q02) + 222 t2 + t3 - t4 + t5 - t6 + 0.5*t7*t8)) - b*p1*pow(q0,((-1.0) - p1))* 223 (((-((b*M_PI)/(L*q0))) + t9 + t10 + 224 0.5*((C3*pow(((Rgb)),((-3.0)/miu)) + 225 C2*pow(((Rgb)),((-2.0)/miu)) + 226 C1*pow(((Rgb)),((-1.0)/miu))))* 227 ((1.0 + tanh(((-C4) + Rgb)/C5)))))))))); 228 229 return (yy); 230 } 231 232 // 233 static double 234 a_short(double q, double L, double b, double p1short, 235 double p2short, double factor, double pdiff, double q0) 236 { 237 const double Rg2_sh = Rgsquareshort(q,L,b); 238 const double Rg2_sh2 = Rg2_sh*Rg2_sh; 239 const double b3 = b*b*b; 240 const double t1 = ((q0*q0*Rg2_sh)/(b*b)); 241 const double Et1 = exp(t1); 242 const double Emt1 = 1.0/Et1; 243 const double q02 = q0*q0; 244 const double q0p = pow(q0,(-4.0 + p1short) ); 245 246 double yy = ((factor/(L*(pdiff)*Rg2_sh2)* 247 ((b*Emt1*q0p*((8.0*b3*L - 8.0*b3*Et1*L - 2.0*b3*L*p2short + 248 2.0*b3*Et1*L*p2short + 4.0*b*L*q02*Rg2_sh + 4.0*b*Et1*L*q02*Rg2_sh - 249 2.0*b*Et1*L*p2short*q02*Rg2_sh - Et1*M_PI*q02*q0*Rg2_sh2 + 250 Et1*p2short*M_PI*q02*q0*Rg2_sh2)))))); 251 252 return(yy); 253 } 254 static double 255 a1short(double q, double L, double b, double p1short, double p2short, double q0) 256 { 257 258 double factor = 1.0; 259 return a_short(q, L, b, p1short, p2short, factor, p1short - p2short, q0); 260 } 261 262 static double 263 a2short(double q, double L, double b, double p1short, double p2short, double q0) 264 { 265 double factor = -1.0; 266 return a_short(q, L, b, p2short, p1short, factor, p1short-p2short, q0); 267 } 268 269 //WR named this w (too generic) 270 static double 271 w_WR(double x) 272 { 273 return 0.5*(1 + tanh((x - 1.523)/0.1477)); 274 } 275 276 // 277 static double 278 u1(double q, double L, double b) 279 { 280 return Rgsquareshort(q,L,b)*q*q; 281 } 282 283 static double 284 u_WR(double q, double L, double b) 285 { 286 return Rgsquare(q,L,b)*q*q; 287 } 288 289 static double 290 Sdebye_kernel(double arg) 291 { 292 // ORIGINAL 293 double result = 2.0*(exp(-arg) + arg -1.0)/(arg*arg); 294 295 // CONVERSION 1 from http://herbie.uwplse.org/ 296 // 297 // exhibits discontinuity - needs more investigation 298 //double a1 = 1.0/6.0; 299 //double a2 = 1.0/72.0; 300 //double a3 = 1.0/24.0; 301 //double result = pow((1.0 - a1*arg - (a2+a3)*arg*arg), 2); 302 303 return result; 304 } 305 static double 306 Sdebye(double q, double L, double b) 307 { 308 double arg = u_WR(q,L,b); 309 return Sdebye_kernel(arg); 310 } 311 312 // 313 static double 314 Sdebye1(double q, double L, double b) 315 { 316 double arg = u1(q,L,b); 317 return Sdebye_kernel(arg); 318 319 } 320 321 // 155 } 156 322 157 static double 323 158 Sexv(double q, double L, double b) 324 159 { 325 326 160 const double C1=1.22; 327 161 const double C2=0.4288; 328 162 const double C3=-1.651; 329 163 const double miu = 0.585; 330 const double qRg = q*sqrt(Rgsquare(q,L,b)); 331 const double x = pow(qRg, -1.0/miu); 332 333 double yy = (1.0 - w_WR(qRg))*Sdebye(q,L,b) + 334 w_WR(qRg)*x*(C1 + x*(C2 + x*C3)); 335 return (yy); 336 } 337 338 339 static double 340 Sexvnew(double q, double L, double b) 341 { 342 double yy; 343 344 const double C1 =1.22; 345 const double C2 =0.4288; 346 const double C3 =-1.651; 347 const double miu = 0.585; 164 const double qr = q*sqrt(Rgsquare(L,b)); 165 const double x = pow(qr, -1.0/miu); 166 const double w = w_WR(qr); 167 168 const double base = (1.0 - w)*Sdebye(qr*qr); 169 const double correction = w*x*(C1 + x*(C2 + x*C3)); 170 return base + correction; 171 } 172 173 174 static double 175 Sexv_new(double q, double L, double b) 176 { 177 // Modified by Yun on Oct. 15, 178 179 // Correction factor to apply to the returned Sexv 180 const double qr = q*sqrt(Rgsquare(L,b)); 181 const double qr2 = qr*qr; 182 const double t1 = (4.0/15.0 + 7.0/(15.0*qr2) - (11.0/15.0 + 7.0/(15.0*qr2))*exp(-qr2))*(b/L); 183 const double C = (L/b > 10.0) ? 3.06*pow(L/b, -0.44)*t1 : t1; 184 185 const double Sexv_orig = Sexv(q, L, b); 186 187 // calculating the derivative to decide on the correction (cutoff) term? 188 // Note: this is modified from WRs original code 348 189 const double del=1.05; 349 const double qRg = q*sqrt(Rgsquare(q,L,b)); 350 const double x = pow(qRg, -1.0/miu); 351 352 353 //calculating the derivative to decide on the corection (cutoff) term? 354 // I have modified this from WRs original code 355 const double qdel = (Sexv(q*del,L,b)-Sexv(q,L,b))/(q*del - q); 356 const double C_star2 =(qdel >= 0.0) ? 0.0 : 1.0; 357 358 yy = (1.0 - w_WR(qRg))*Sdebye(q,L,b) + 359 C_star2*w_WR(qRg)* 360 x*(C1 + x*(C2 + x*C3)); 361 362 return (yy); 363 } 364 365 double Sk_WR(double q, double L, double b) 366 { 367 // 368 const double p1 = 4.12; 369 const double p2 = 4.42; 370 const double p1short = 5.36; 371 const double p2short = 5.62; 372 const double q0 = 3.1; 373 374 double q0short = fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0); 375 double Sexvmodify, ans; 376 377 const double C =(L/b > 10.0) ? 3.06/pow((L/b),0.44) : 1.0; 378 379 if( L > 4*b ) { // Longer Chains 380 if (q*b <= 3.1) { //Modified by Yun on Oct. 15, 381 Sexvmodify = Sexvnew(q, L, b); 382 ans = Sexvmodify + C * (4.0/15.0 + 7.0/(15.0*u_WR(q,L,b)) - 383 (11.0/15.0 + 7.0/(15.0*u_WR(q,L,b)))*exp(-u_WR(q,L,b)))*(b/L); 384 385 } else { //q(i)*b > 3.1 386 ans = a1long(q, L, b, p1, p2, q0)/(pow((q*b),p1)) + 387 a2long(q, L, b, p1, p2, q0)/(pow((q*b),p2)) + M_PI/(q*L); 388 } 389 } else { //L <= 4*b Shorter Chains 390 if (q*b <= fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0) ) { 391 if (q*b<=0.01) { 392 ans = 1.0 - Rgsquareshort(q,L,b)*(q*q)/3.0; 393 } else { 394 ans = Sdebye1(q,L,b); 395 } 396 } else { //q*b > max(1.9/sqrt(Rgsquareshort(q(i),L,b)),3) 397 ans = a1short(q,L,b,p1short,p2short,q0short)/(pow((q*b),p1short)) + 398 a2short(q,L,b,p1short,p2short,q0short)/(pow((q*b),p2short)) + 399 M_PI/(q*L); 400 } 190 const double qdel = (Sexv(q*del,L,b) - Sexv_orig)/(q*(del - 1.0)); 191 192 if (qdel < 0) { 193 // return Sexv with the additional correction 194 return Sexv_orig + C; 195 } else { 196 // recalculate Sexv base and return it with the additional correction 197 const double w = w_WR(qr); 198 return (1.0 - w)*Sdebye(qr2) + C; 401 199 } 402 403 return(ans); 404 } 200 } 201 202 203 static double 204 Sk_WR(double q, double L, double b) 205 { 206 const double Rg_short = sqrt(Rgsquareshort(L, b)); 207 double q0short = fmax(1.9/Rg_short, 3.0); 208 double ans; 209 210 if( L > 4*b ) { // L > 4*b : Longer Chains 211 if (q*b <= 3.1) { 212 ans = Sexv_new(q, L, b); 213 } else { //q(i)*b > 3.1 214 ans = a_long(q, L, b /*, p1, p2, q0*/); 215 } 216 } else { // L <= 4*b : Shorter Chains 217 if (q*b <= q0short) { // q*b <= fmax(1.9/Rg_short, 3) 218 if (q*b <= 0.01) { 219 ans = 1.0 - square(q*Rg_short)/3.0; 220 } else { 221 ans = Sdebye(square(q*Rg_short)); 222 } 223 } else { // q*b > max(1.9/Rg_short, 3) 224 ans = a_short(q, L, b /*, p1short, p2short*/, q0short); 225 } 226 } 227 228 return ans; 229 }
Note: See TracChangeset
for help on using the changeset viewer.