Changeset 50e1e40 in sasmodels
- Timestamp:
- Mar 1, 2016 7:49:00 PM (9 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- ad90df9
- Parents:
- a4a7308
- Location:
- sasmodels/models
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/models/barbell.c
r3c97ff0 r50e1e40 7 7 8 8 //barbell kernel - same as dumbell 9 double _bell_kernel(double q, double h, double bell_radius, 10 double length, double sin_alpha, double cos_alpha); 11 double _bell_kernel(double q, double h, double bell_radius, 12 double length, double sin_alpha, double cos_alpha) 9 static double 10 _bell_kernel(double q, double h, double bell_radius, 11 double half_length, double sin_alpha, double cos_alpha) 13 12 { 13 // translate a point in [-1,1] to a point in [lower,upper] 14 14 const double upper = 1.0; 15 const double lower = -1.0*h/bell_radius; 15 const double lower = h/bell_radius; 16 const double zm = 0.5*(upper-lower); 17 const double zb = 0.5*(upper+lower); 16 18 19 // cos term in integral is: 20 // cos (q (R t - h + L/2) cos(alpha)) 21 // so turn it into: 22 // cos (m t + b) 23 // where: 24 // m = q R cos(alpha) 25 // b = q(L/2-h) cos(alpha) 26 const double m = q*bell_radius*cos_alpha; // cos argument slope 27 const double b = q*(half_length-h)*cos_alpha; // cos argument intercept 28 const double qrst = q*bell_radius*sin_alpha; // Q*R*sin(theta) 17 29 double total = 0.0; 18 30 for (int i = 0; i < 76; i++){ 19 const double t = 0.5*(Gauss76Z[i]*(upper-lower)+upper+lower); 20 const double arg1 = q*cos_alpha*(bell_radius*t+h+length*0.5); 21 const double arg2 = q*bell_radius*sin_alpha*sqrt(1.0-t*t); 22 const double be = (arg2 == 0.0 ? 0.5 :J1(arg2)/arg2); 23 const double Fq = cos(arg1)*(1.0-t*t)*be; 31 const double t = Gauss76Z[i]*zm + zb; 32 const double radical = 1.0 - t*t; 33 const double bj = J1c(qrst*sqrt(radical)); 34 const double Fq = cos(m*t + b) * radical * bj; 24 35 total += Gauss76Wt[i] * Fq; 25 36 } 26 const double integral = 0.5*(upper-lower)*total; 27 return 4.0*M_PI*bell_radius*bell_radius*bell_radius*integral; 37 // translate dx in [-1,1] to dx in [lower,upper] 38 const double integral = total*zm; 39 const double bell_Fq = 2*M_PI*cube(bell_radius)*integral; 40 return bell_Fq; 28 41 } 29 42 … … 34 47 35 48 // bell radius should never be less than radius when this is called 36 const double hdist = sqrt( bell_radius*bell_radius - radius*radius);37 const double p1 = 2.0 *bell_radius*bell_radius*bell_radius/3.0;38 const double p2 = bell_radius*bell_radius*hdist;39 const double p3 = hdist*hdist*hdist/3.0;49 const double hdist = sqrt(square(bell_radius) - square(radius)); 50 const double p1 = 2.0/3.0*cube(bell_radius); 51 const double p2 = square(bell_radius)*hdist; 52 const double p3 = cube(hdist)/3.0; 40 53 41 return M_PI* radius*radius*length + 2.0*M_PI*(p1+p2-p3);54 return M_PI*square(radius)*length + 2.0*M_PI*(p1+p2-p3); 42 55 } 43 56 44 double Iq(double q, double sld, 45 double solvent_sld, 46 double bell_radius, 47 double radius, 48 double length) 57 double Iq(double q, double sld, double solvent_sld, 58 double bell_radius, double radius, double length) 49 59 { 50 double sn, cn; // slots to hold sincos function output 60 // Exclude invalid inputs. 61 if (bell_radius < radius) return NAN; 62 const double h = -sqrt(bell_radius*bell_radius - radius*radius); 63 const double half_length = 0.5*length; 51 64 52 if (bell_radius < radius) return NAN; 53 54 const double lower = 0.0; 55 const double upper = M_PI_2; 56 const double h = sqrt(bell_radius*bell_radius-radius*radius); 65 // translate a point in [-1,1] to a point in [0, pi/2] 66 const double zm = M_PI_4; 67 const double zb = M_PI_4; 57 68 double total = 0.0; 58 69 for (int i = 0; i < 76; i++){ 59 const double alpha= 0.5*(Gauss76Z[i]*(upper-lower) + upper + lower); 60 SINCOS(alpha, sn, cn); 70 const double alpha= Gauss76Z[i]*zm + zb; 71 double sin_alpha, cos_alpha; // slots to hold sincos function output 72 SINCOS(alpha, sin_alpha, cos_alpha); 61 73 62 const double bell_Fq = _bell_kernel(q, h, bell_radius, length, sn, cn); 74 const double bell_Fq = _bell_kernel(q, h, bell_radius, half_length, sin_alpha, cos_alpha); 75 const double bj = J1c(q*radius*sin_alpha); 76 const double si = sinc(q*half_length*cos_alpha); 77 const double cyl_Fq = M_PI*radius*radius*length*bj*si; 78 const double Aq = bell_Fq + cyl_Fq; 79 total += Gauss76Wt[i] * Aq * Aq * sin_alpha; 80 } 81 // translate dx in [-1,1] to dx in [lower,upper] 82 const double form = total*zm; 63 83 64 const double arg1 = q*length*0.5*cn; 65 const double arg2 = q*radius*sn; 66 // lim_{x->0} J1(x)/x = 1/2, lim_{x->0} sin(x)/x = 1 67 const double be = (arg2 == 0.0 ? 0.5 :J1(arg2)/arg2); 68 const double si = (arg1 == 0.0 ? 1.0 :sin(arg1)/arg1); 69 const double cyl_Fq = M_PI*radius*radius*length*si*2.0*be; 70 71 const double Aq = cyl_Fq + bell_Fq; 72 total += Gauss76Wt[i] * Aq * Aq * sn; 73 } 74 75 const double form = total*(upper-lower)*0.5; 76 77 //Contrast and volume normalization 84 //Contrast 78 85 const double s = (sld - solvent_sld); 79 return form*1.0e-4*s*s; //form_volume(bell_radius,radius,length);86 return 1.0e-4 * s * s * form; 80 87 } 81 88 82 89 83 84 90 double Iqxy(double qx, double qy, 85 double sld, 86 double solvent_sld, 87 double bell_radius, 88 double radius, 89 double length, 90 double theta, 91 double phi) 91 double sld, double solvent_sld, 92 double bell_radius, double radius, double length, 93 double theta, double phi) 92 94 { 93 double sn, cn; // slots to hold sincos function output 95 // Compute angle alpha between q and the cylinder axis 96 double sn, cn; // slots to hold sincos function output 97 SINCOS(theta*M_PI_180, sn, cn); 98 const double q = sqrt(qx*qx+qy*qy); 99 const double cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q); 100 const double alpha = acos(cos_val); // rod angle relative to q 94 101 95 102 // Exclude invalid inputs. 96 103 if (bell_radius < radius) return NAN; 104 const double h = -sqrt(square(bell_radius) - square(radius)); 105 const double half_length = 0.5*length; 97 106 98 // Compute angle alpha between q and the cylinder axis 99 SINCOS(theta*M_PI_180, sn, cn); 100 // # The following correction factor exists in sasview, but it can't be 101 // # right, so we are leaving it out for now. 102 const double q = sqrt(qx*qx+qy*qy); 103 const double cos_val = cn*cos(phi*M_PI_180)*qx + sn*qy; 104 const double alpha = acos(cos_val); // rod angle relative to q 105 SINCOS(alpha, sn, cn); 106 107 const double h = sqrt(bell_radius*bell_radius - radius*radius); // negative h 108 const double bell_Fq = _bell_kernel(q, h, bell_radius, length, sn, cn)/sn; 109 110 const double besarg = q*radius*sn; 111 const double siarg = q*0.5*length*cn; 112 // lim_{x->0} J1(x)/x = 1/2, lim_{x->0} sin(x)/x = 1 113 const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg); 114 const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg); 115 const double cyl_Fq = M_PI*radius*radius*length*2.0*bj*si; 116 117 // Volume weighted average F(q) 107 double sin_alpha, cos_alpha; // slots to hold sincos function output 108 SINCOS(alpha, sin_alpha, cos_alpha); 109 const double bell_Fq = _bell_kernel(q, h, bell_radius, half_length, sin_alpha, cos_alpha); 110 const double bj = J1c(q*radius*sin_alpha); 111 const double si = sinc(q*half_length*cos_alpha); 112 const double cyl_Fq = M_PI*radius*radius*length*bj*si; 118 113 const double Aq = cyl_Fq + bell_Fq; 119 114 120 // Multiply by contrast^2 , normalize by cylinder volumeand convert to cm-1115 // Multiply by contrast^2 and convert to cm-1 121 116 const double s = (sld - solvent_sld); 122 return 1.0e-4 * Aq * Aq * s * s; // form_volume(radius, cap_radius, length);117 return 1.0e-4 * square(s * Aq); 123 118 } -
sasmodels/models/barbell.py
rdcdf29d r50e1e40 121 121 # pylint: enable=bad-whitespace, line-too-long 122 122 123 source = ["lib/J1 .c", "lib/gauss76.c", "barbell.c"]123 source = ["lib/J1c.c", "lib/gauss76.c", "barbell.c"] 124 124 125 125 # parameters for demo -
sasmodels/models/capped_cylinder.c
r139c528 r50e1e40 13 13 // length is the cylinder length, or the separation between the lens halves 14 14 // alpha is the angle of the cylinder wrt q. 15 double _cap_kernel(double q, double h, double cap_radius, double length, 16 double sin_alpha, double cos_alpha); 17 double _cap_kernel(double q, double h, double cap_radius, double length, 18 double sin_alpha, double cos_alpha) 15 static double 16 _cap_kernel(double q, double h, double cap_radius, 17 double half_length, double sin_alpha, double cos_alpha) 19 18 { 20 // For speed, we are pre-calculating terms which are constant over the 21 // kernel. 19 // translate a point in [-1,1] to a point in [lower,upper] 22 20 const double upper = 1.0; 23 21 const double lower = h/cap_radius; // integral lower bound 24 22 const double zm = 0.5*(upper-lower); 25 23 const double zb = 0.5*(upper+lower); 24 26 25 // cos term in integral is: 27 26 // cos (q (R t - h + L/2) cos(alpha)) … … 32 31 // b = q(L/2-h) cos(alpha) 33 32 const double m = q*cap_radius*cos_alpha; // cos argument slope 34 const double b = q*( 0.5*length-h)*cos_alpha; // cos argument intercept33 const double b = q*(half_length-h)*cos_alpha; // cos argument intercept 35 34 const double qrst = q*cap_radius*sin_alpha; // Q*R*sin(theta) 36 35 double total = 0.0; 37 36 for (int i=0; i<76 ;i++) { 38 // translate a point in [-1,1] to a point in [lower,upper]39 //const double t = ( Gauss76Z[i]*(upper-lower) + upper + lower )/2.0;40 37 const double t = Gauss76Z[i]*zm + zb; 41 38 const double radical = 1.0 - t*t; 42 const double arg = qrst*sqrt(radical); // cap bessel function arg 43 const double be = (arg == 0.0 ? 0.5 : J1(arg)/arg); 44 const double Fq = cos(m*t + b) * radical * be; 39 const double bj = J1c(qrst*sqrt(radical)); 40 const double Fq = cos(m*t + b) * radical * bj; 45 41 total += Gauss76Wt[i] * Fq; 46 42 } 47 43 // translate dx in [-1,1] to dx in [lower,upper] 48 //const double form = (upper-lower)/2.0*total;49 const double integral = 0.5*(upper-lower)*total;50 return 4.0*M_PI*cap_radius*cap_radius*cap_radius*integral;44 const double integral = total*zm; 45 const double cap_Fq = 2*M_PI*cube(cap_radius)*integral; 46 return cap_Fq; 51 47 } 52 48 … … 66 62 // The first part is clearly V_cyl. The second part requires some work: 67 63 // (R-h)^2 => h_c^2 68 // (2R+h) => 2R+ h_c-h_c + h => 2R + (R-h)-h c + h => 3R-h_c64 // (2R+h) => 2R+ h_c-h_c + h => 2R + (R-h)-h_c + h => 3R-h_c 69 65 // And so: 70 66 // 2/3 pi (R-h)^2 (2R + h) => 2/3 pi h_c^2 (3 r_cap - h_c) … … 77 73 // = pi (r^2 (L+hc) + hc^3/3) 78 74 const double hc = cap_radius - sqrt(cap_radius*cap_radius - radius*radius); 79 return M_PI*(radius*radius*(length+hc) + 0.333333333333333*hc*hc*hc);75 return M_PI*(radius*radius*(length+hc) + hc*hc*hc/3.0); 80 76 } 81 77 82 double Iq(double q, 83 double sld, 84 double solvent_sld, 85 double radius, 86 double cap_radius, 87 double length) 78 double Iq(double q, double sld, double solvent_sld, 79 double radius, double cap_radius, double length) 88 80 { 89 double sn, cn; // slots to hold sincos function output90 91 81 // Exclude invalid inputs. 92 82 if (cap_radius < radius) return NAN; 83 const double h = sqrt(cap_radius*cap_radius - radius*radius); 84 const double half_length = 0.5*length; 93 85 94 const double lower = 0.0;95 const double upper = M_PI_2;96 const double h = sqrt(cap_radius*cap_radius - radius*radius); // negative h86 // translate a point in [-1,1] to a point in [0, pi/2] 87 const double zm = M_PI_4; 88 const double zb = M_PI_4; 97 89 double total = 0.0; 98 90 for (int i=0; i<76 ;i++) { 99 // translate a point in [-1,1] to a point in [lower,upper]100 const double alpha= 0.5*(Gauss76Z[i]*(upper-lower) + upper + lower);101 SINCOS(alpha, s n, cn);91 const double alpha= Gauss76Z[i]*zm + zb; 92 double sin_alpha, cos_alpha; // slots to hold sincos function output 93 SINCOS(alpha, sin_alpha, cos_alpha); 102 94 103 const double cap_Fq = _cap_kernel(q, h, cap_radius, length, sn, cn); 104 105 // The following is CylKernel() / sin(alpha), but we are doing it in place 106 // to avoid sin(alpha)/sin(alpha) for alpha = 0. It is also a teensy bit 107 // faster since we don't multiply and divide sin(alpha). 108 const double besarg = q*radius*sn; 109 const double siarg = q*0.5*length*cn; 110 // lim_{x->0} J1(x)/x = 1/2, lim_{x->0} sin(x)/x = 1 111 const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg); 112 const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg); 113 const double cyl_Fq = M_PI*radius*radius*length*2.0*bj*si; 114 115 // Volume weighted average F(q) 116 const double Aq = cyl_Fq + cap_Fq; 117 total += Gauss76Wt[i] * Aq * Aq * sn; // sn for spherical coord integration 95 const double cap_Fq = _cap_kernel(q, h, cap_radius, half_length, sin_alpha, cos_alpha); 96 const double bj = J1c(q*radius*sin_alpha); 97 const double si = sinc(q*half_length*cos_alpha); 98 const double cyl_Fq = M_PI*radius*radius*length*bj*si; 99 const double Aq = cap_Fq + cyl_Fq; 100 total += Gauss76Wt[i] * Aq * Aq * sin_alpha; // sin_alpha for spherical coord integration 118 101 } 119 102 // translate dx in [-1,1] to dx in [lower,upper] 120 const double form = total * 0.5*(upper-lower);103 const double form = total * zm; 121 104 122 // Multiply by contrast^2, normalize by cylinder volume and convert to cm-1 123 // NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl 124 // The additional volume factor is for polydisperse volume normalization. 105 // Contrast 125 106 const double s = (sld - solvent_sld); 126 return 1.0e-4 * form * s * s; // form_volume(radius, cap_radius, length);107 return 1.0e-4 * s * s * form; 127 108 } 128 109 129 110 130 111 double Iqxy(double qx, double qy, 131 double sld, 132 double solvent_sld, 133 double radius, 134 double cap_radius, 135 double length, 136 double theta, 137 double phi) 112 double sld, double solvent_sld, double radius, 113 double cap_radius, double length, 114 double theta, double phi) 138 115 { 139 double sn, cn; // slots to hold sincos function output 116 // Compute angle alpha between q and the cylinder axis 117 double sn, cn; 118 SINCOS(theta*M_PI_180, sn, cn); 119 const double q = sqrt(qx*qx+qy*qy); 120 const double cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q); 121 const double alpha = acos(cos_val); // rod angle relative to q 140 122 141 123 // Exclude invalid inputs. 142 124 if (cap_radius < radius) return NAN; 125 const double h = sqrt(cap_radius*cap_radius - radius*radius); 126 const double half_length = 0.5*length; 143 127 144 // Compute angle alpha between q and the cylinder axis 145 SINCOS(theta*M_PI_180, sn, cn); 146 // # The following correction factor exists in sasview, but it can't be 147 // # right, so we are leaving it out for now. 148 const double q = sqrt(qx*qx+qy*qy); 149 const double cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q); 150 const double alpha = acos(cos_val); // rod angle relative to q 151 SINCOS(alpha, sn, cn); 128 double sin_alpha, cos_alpha; // slots to hold sincos function output 129 SINCOS(alpha, sin_alpha, cos_alpha); 130 const double cap_Fq = _cap_kernel(q, h, cap_radius, half_length, sin_alpha, cos_alpha); 131 const double bj = J1c(q*radius*sin_alpha); 132 const double si = sinc(q*half_length*cos_alpha); 133 const double cyl_Fq = M_PI*radius*radius*length*bj*si; 134 const double Aq = cap_Fq + cyl_Fq; 152 135 153 const double h = sqrt(cap_radius*cap_radius - radius*radius); // negative h 154 const double cap_Fq = _cap_kernel(q, h, cap_radius, length, sn, cn); 155 156 const double besarg = q*radius*sn; 157 const double siarg = q*0.5*length*cn; 158 // lim_{x->0} J1(x)/x = 1/2, lim_{x->0} sin(x)/x = 1 159 const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg); 160 const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg); 161 const double cyl_Fq = M_PI*radius*radius*length*2.0*bj*si; 162 163 // Volume weighted average F(q) 164 const double Aq = cyl_Fq + cap_Fq; 165 166 // Multiply by contrast^2, normalize by cylinder volume and convert to cm-1 136 // Multiply by contrast^2 and convert to cm-1 167 137 const double s = (sld - solvent_sld); 168 return 1.0e-4 * Aq * Aq * s * s; // form_volume(radius, cap_radius, length);138 return 1.0e-4 * square(s * Aq); 169 139 } -
sasmodels/models/capped_cylinder.py
rdcdf29d r50e1e40 147 147 # pylint: enable=bad-whitespace, line-too-long 148 148 149 source = ["lib/J1 .c", "lib/gauss76.c", "capped_cylinder.c"]149 source = ["lib/J1c.c", "lib/gauss76.c", "capped_cylinder.c"] 150 150 151 151 demo = dict(scale=1, background=0, -
sasmodels/models/cylinder.c
r3c97ff0 r50e1e40 3 3 double Iqxy(double qx, double qy, double sld, double solvent_sld, 4 4 double radius, double length, double theta, double phi); 5 6 // twovd = 2 * volume * delta_rho7 // besarg = q * R * sin(alpha)8 // siarg = q * L/2 * cos(alpha)9 double _cyl(double besarg, double siarg);10 double _cyl(double besarg, double siarg)11 {12 const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg);13 const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg);14 return si*bj;15 }16 5 17 6 double form_volume(double radius, double length) … … 26 15 double length) 27 16 { 17 // TODO: return NaN if radius<0 or length<0? 18 // precompute qr and qh to save time in the loop 28 19 const double qr = q*radius; 29 20 const double qh = q*0.5*length; 21 22 // translate a point in [-1,1] to a point in [0, pi/2] 23 const double zm = M_PI_4; 24 const double zb = M_PI_4; 25 30 26 double total = 0.0; 31 // double lower=0, upper=M_PI_2;32 27 for (int i=0; i<76 ;i++) { 33 // translate a point in [-1,1] to a point in [lower,upper] 34 //const double alpha = ( Gauss76Z[i]*(upper-lower) + upper + lower )/2.0; 35 const double alpha = M_PI_4*(Gauss76Z[i] + 1.0); 28 const double alpha = Gauss76Z[i]*zm + zb; 36 29 double sn, cn; 37 30 SINCOS(alpha, sn, cn); 38 // For a bit of efficiency, we are moving the 2 V delta rho constant 39 // factor, 2Vdrho, out of the loop, so this is fq/2Vdrho rather than fq. 40 const double fq = _cyl(qr*sn, qh*cn); 41 total += Gauss76Wt[i] * fq * fq * sn; 31 const double fq = sinc(qh*cn) * J1c(qr*sn); 32 total += Gauss76Wt[i] * fq*fq * sn; 42 33 } 43 34 // translate dx in [-1,1] to dx in [lower,upper] 44 //const double form = (upper-lower)/2.0*total;45 const double twoVdrho = 2.0*(sld-solvent_sld)*form_volume(radius, length);46 return 1.0e-4 * twoVdrho * twoVdrho * total * M_PI_4;35 const double form = total*zm; 36 const double s = (sld - solvent_sld) * form_volume(radius, length); 37 return 1.0e-4 * s * s * form; 47 38 } 48 39 … … 56 47 double phi) 57 48 { 58 // TODO: check that radius<0 and length<0 give zero scattering. 59 // This should be the case since the polydispersity weight vector should 60 // be zero length, and this function never called. 49 // TODO: return NaN if radius<0 or length<0? 61 50 double sn, cn; // slots to hold sincos function output 62 51 63 52 // Compute angle alpha between q and the cylinder axis 64 53 SINCOS(theta*M_PI_180, sn, cn); 65 const double q = sqrt(qx*qx +qy*qy);54 const double q = sqrt(qx*qx + qy*qy); 66 55 const double cos_val = (q==0. ? 1.0 : (cn*cos(phi*M_PI_180)*qx + sn*qy)/q); 67 56 const double alpha = acos(cos_val); 57 68 58 SINCOS(alpha, sn, cn); 69 //sn = sqrt(1.0 - cos_val*cos_val); 70 //sn = 1.0 - 0.5*cos_val*cos_val; // if cos_val is very small 71 //cn = cos_val; 72 73 const double twovd = 2.0*(sld-solvent_sld)*form_volume(radius, length); 74 const double fq = twovd * _cyl(q*radius*sn, q*0.5*length*cn); 75 return 1.0e-4 * fq * fq; 59 const double fq = sinc(q*0.5*length*cn) * J1c(q*radius*sn); 60 const double s = (sld-solvent_sld) * form_volume(radius, length); 61 return 1.0e-4 * square(s * fq); 76 62 } -
sasmodels/models/cylinder.py
r0c3a226 r50e1e40 141 141 ] 142 142 143 source = ["lib/J1 .c", "lib/gauss76.c", "cylinder.c"]143 source = ["lib/J1c.c", "lib/gauss76.c", "cylinder.c"] 144 144 145 145 def ER(radius, length): -
sasmodels/models/ellipsoid.c
r9c461c7 r50e1e40 17 17 double form_volume(double rpolar, double requatorial) 18 18 { 19 return 1.333333333333333*M_PI*rpolar*requatorial*requatorial;19 return M_4PI_3*rpolar*requatorial*requatorial; 20 20 } 21 21 … … 26 26 double requatorial) 27 27 { 28 //const double lower = 0.0; 29 //const double upper = 1.0; 28 // translate a point in [-1,1] to a point in [0, 1] 29 const double zm = 0.5; 30 const double zb = 0.5; 30 31 double total = 0.0; 31 32 for (int i=0;i<76;i++) { 32 33 //const double sin_alpha = (Gauss76Z[i]*(upper-lower) + upper + lower)/2; 33 const double sin_alpha = 0.5*(Gauss76Z[i] + 1.0);34 const double sin_alpha = Gauss76Z[i]*zm + zb; 34 35 total += Gauss76Wt[i] * _ellipsoid_kernel(q, rpolar, requatorial, sin_alpha); 35 36 } 36 // const double form = (upper-lower)/2*total;37 const double form = 0.5*total;37 // translate dx in [-1,1] to dx in [lower,upper] 38 const double form = total*zm; 38 39 const double s = (sld - solvent_sld) * form_volume(rpolar, requatorial); 39 return 1.0e-4 * form * s * s;40 return 1.0e-4 * s * s * form; 40 41 } 41 42 -
sasmodels/models/sphere.py
rc691551 r50e1e40 83 83 # This should perhaps be volume normalized? 84 84 form_volume = """ 85 return 1.333333333333333*M_PI*radius*radius*radius;85 return M_4PI_3*cube(radius); 86 86 """ 87 87 -
sasmodels/models/triaxial_ellipsoid.c
r9c461c7 r50e1e40 20 20 21 21 double sn, cn; 22 // double st, ct;23 //const double lower = 0.0;24 //const double upper = 1.0;22 // translate a point in [-1,1] to a point in [0, 1] 23 const double zm = 0.5; 24 const double zb = 0.5; 25 25 double outer = 0.0; 26 26 for (int i=0;i<76;i++) { … … 34 34 double inner = 0.0; 35 35 for (int j=0;j<76;j++) { 36 const double y = 0.5*(Gauss76Z[j] + 1.0);37 const double t = q*sqrt(acosx2 + bsinx2*(1.0-y *y) + c2*y*y);36 const double ysq = square(Gauss76Z[j]*zm + zb); 37 const double t = q*sqrt(acosx2 + bsinx2*(1.0-ysq) + c2*ysq); 38 38 const double fq = sph_j1c(t); 39 39 inner += Gauss76Wt[j] * fq * fq ; … … 41 41 outer += Gauss76Wt[i] * 0.5 * inner; 42 42 } 43 // const double fq2 = (upper-lower)/2*outer;44 const double fq 2 = 0.5*outer;43 // translate dx in [-1,1] to dx in [lower,upper] 44 const double fqsq = outer*zm; 45 45 const double s = (sld - solvent_sld) * form_volume(req_minor, req_major, rpolar); 46 return 1.0e-4 * fq2 * s * s;46 return 1.0e-4 * s * s * fqsq; 47 47 } 48 48 … … 62 62 double sphi, cphi; 63 63 double spsi, cpsi; 64 double st, ct;65 64 66 65 const double q = sqrt(qx*qx + qy*qy); … … 76 75 + req_major*req_major*cmu*cmu 77 76 + rpolar*rpolar*calpha*calpha); 78 SINCOS(t, st, ct); 79 const double fq = ( t==0.0 ? 1.0 : 3.0*(st-t*ct)/(t*t*t) ); 77 const double fq = sph_j1c(t); 80 78 const double s = (sld - solvent_sld) * form_volume(req_minor, req_major, rpolar); 81 79 82 return 1.0e-4 * fq * fq * s * s;80 return 1.0e-4 * square(s * fq); 83 81 } 84 82
Note: See TracChangeset
for help on using the changeset viewer.