Changeset 5bddd89 in sasmodels
- Timestamp:
- Oct 14, 2016 4:05:39 PM (8 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:
- 9068f4c
- Parents:
- 0b717c5
- Location:
- sasmodels/models
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/models/capped_cylinder.c
r0d6e865 r5bddd89 49 49 } 50 50 51 static double 52 _fq(double q, double h, double radius_cap, double radius, double half_length, 53 double sin_alpha, double cos_alpha) 54 { 55 const double cap_Fq = _cap_kernel(q, h, radius_cap, half_length, sin_alpha, cos_alpha); 56 const double bj = sas_J1c(q*radius*sin_alpha); 57 const double si = sinc(q*half_length*cos_alpha); 58 const double cyl_Fq = 2.*M_PI*radius*radius*half_length*bj*si; 59 const double Aq = cap_Fq + cyl_Fq; 60 return Aq; 61 } 62 51 63 double form_volume(double radius, double radius_cap, double length) 52 64 { … … 93 105 SINCOS(alpha, sin_alpha, cos_alpha); 94 106 95 const double cap_Fq = _cap_kernel(q, h, radius_cap, half_length, sin_alpha, cos_alpha); 96 const double bj = sas_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 107 const double Aq = _fq(q, h, radius_cap, radius, half_length, sin_alpha, cos_alpha); 108 // sin_alpha for spherical coord integration 109 total += Gauss76Wt[i] * Aq * Aq * sin_alpha; 101 110 } 102 111 // translate dx in [-1,1] to dx in [lower,upper] … … 114 123 double theta, double phi) 115 124 { 116 // Compute angle alpha between q and the cylinder axis 117 double sn, cn; 118 SINCOS(phi*M_PI_180, sn, cn); 119 const double q = sqrt(qx*qx+qy*qy); 120 const double cos_val = (q==0. ? 1.0 : (cn*qx + sn*qy)*sin(theta*M_PI_180)/q); 121 const double alpha = acos(cos_val); // rod angle relative to q 125 double q, sin_alpha, cos_alpha; 126 ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 122 127 123 128 const double h = sqrt(radius_cap*radius_cap - radius*radius); 124 const double half_length = 0.5*length; 125 126 double sin_alpha, cos_alpha; // slots to hold sincos function output 127 SINCOS(alpha, sin_alpha, cos_alpha); 128 const double cap_Fq = _cap_kernel(q, h, radius_cap, half_length, sin_alpha, cos_alpha); 129 const double bj = sas_J1c(q*radius*sin_alpha); 130 const double si = sinc(q*half_length*cos_alpha); 131 const double cyl_Fq = M_PI*radius*radius*length*bj*si; 132 const double Aq = cap_Fq + cyl_Fq; 129 const double Aq = _fq(q, h, radius_cap, radius, 0.5*length, sin_alpha, cos_alpha); 133 130 134 131 // Multiply by contrast^2 and convert to cm-1 -
sasmodels/models/core_shell_bicelle.c
r0d6e865 r5bddd89 26 26 double form_volume(double radius, double thick_rim, double thick_face, double length) 27 27 { 28 return M_PI*(radius+thick_rim)*(radius+thick_rim)*(length+2 *thick_face);28 return M_PI*(radius+thick_rim)*(radius+thick_rim)*(length+2.0*thick_face); 29 29 } 30 30 … … 39 39 double rhor, 40 40 double rhosolv, 41 double dum) 41 double sin_alpha, 42 double cos_alpha) 42 43 { 43 44 double si1,si2,be1,be2; … … 49 50 const double vol2 = M_PI*(rad+radthick)*(rad+radthick)*2.0*(length+facthick); 50 51 const double vol3 = M_PI*rad*rad*2.0*(length+facthick); 51 double sn,cn; 52 SINCOS(dum, sn, cn); 53 double besarg1 = qq*rad*sn; 54 double besarg2 = qq*(rad+radthick)*sn; 55 double sinarg1 = qq*length*cn; 56 double sinarg2 = qq*(length+facthick)*cn; 52 double besarg1 = qq*rad*sin_alpha; 53 double besarg2 = qq*(rad+radthick)*sin_alpha; 54 double sinarg1 = qq*length*cos_alpha; 55 double sinarg2 = qq*(length+facthick)*cos_alpha; 57 56 58 57 be1 = sas_J1c(besarg1); … … 65 64 vol3*dr3*si2*be1; 66 65 67 const double retval = t*t*s n;66 const double retval = t*t*sin_alpha; 68 67 69 return (retval);68 return retval; 70 69 71 70 } … … 83 82 { 84 83 // set up the integration end points 85 const double uplim = M_PI /4;86 const double halfheight = length/2.0;84 const double uplim = M_PI_4; 85 const double halfheight = 0.5*length; 87 86 88 87 double summ = 0.0; 89 88 for(int i=0;i<N_POINTS_76;i++) { 90 double zi = (Gauss76Z[i] + 1.0)*uplim; 89 double alpha = (Gauss76Z[i] + 1.0)*uplim; 90 double sin_alpha, cos_alpha; // slots to hold sincos function output 91 SINCOS(alpha, sin_alpha, cos_alpha); 91 92 double yyy = Gauss76Wt[i] * bicelle_kernel(qq, rad, radthick, facthick, 92 halfheight, rhoc, rhoh, rhor,rhosolv, zi); 93 halfheight, rhoc, rhoh, rhor, rhosolv, 94 sin_alpha, cos_alpha); 93 95 summ += yyy; 94 96 } … … 96 98 // calculate value of integral to return 97 99 double answer = uplim*summ; 98 return (answer);100 return answer; 99 101 } 100 102 101 103 static double 102 bicelle_kernel_2d(double q , double q_x, double q_y,104 bicelle_kernel_2d(double qx, double qy, 103 105 double radius, 104 106 double thick_rim, … … 112 114 double phi) 113 115 { 114 //convert angle degree to radian 115 theta *= M_PI_180; 116 phi *= M_PI_180; 116 double q, sin_alpha, cos_alpha; 117 ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 117 118 118 // Cylinder orientation119 const double cyl_x = sin(theta) * cos(phi);120 const double cyl_y = sin(theta) * sin(phi);121 122 // Compute the angle btw vector q and the axis of the cylinder123 const double cos_val = cyl_x*q_x + cyl_y*q_y;124 const double alpha = acos( cos_val );125 126 // Get the kernel127 119 double answer = bicelle_kernel(q, radius, thick_rim, thick_face, 128 length/2.0, core_sld, face_sld, rim_sld,129 solvent_sld, alpha) / fabs(sin(alpha));120 0.5*length, core_sld, face_sld, rim_sld, 121 solvent_sld, sin_alpha, cos_alpha) / fabs(sin_alpha); 130 122 131 123 answer *= 1.0e-4; … … 162 154 double phi) 163 155 { 164 double q; 165 q = sqrt(qx*qx+qy*qy); 166 double intensity = bicelle_kernel_2d(q, qx/q, qy/q, 156 double intensity = bicelle_kernel_2d(qx, qy, 167 157 radius, 168 158 thick_rim, -
sasmodels/models/core_shell_cylinder.c
r0d6e865 r5bddd89 11 11 double _cyl(double twovd, double besarg, double siarg) 12 12 { 13 const double bj = (besarg == 0.0 ? 0.5 : 0.5*sas_J1c(besarg)); 14 const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg); 15 return twovd*si*bj; 13 return twovd * sinc(siarg) * sas_J1c(besarg); 16 14 } 17 15 18 16 double form_volume(double radius, double thickness, double length) 19 17 { 20 return M_PI*(radius+thickness)*(radius+thickness)*(length+2 *thickness);18 return M_PI*(radius+thickness)*(radius+thickness)*(length+2.0*thickness); 21 19 } 22 20 … … 66 64 double phi) 67 65 { 68 double sn, cn; // slots to hold sincos function output 69 70 // Compute angle alpha between q and the cylinder axis 71 SINCOS(phi*M_PI_180, sn, cn); 72 // # The following correction factor exists in sasview, but it can't be 73 // # right, so we are leaving it out for now. 74 // const double correction = fabs(cn)*M_PI_2; 75 const double q = sqrt(qx*qx+qy*qy); 76 const double cos_val = (q==0. ? 1.0 : (cn*qx + sn*qy)*sin(theta*M_PI_180)/q); 77 const double alpha = acos(cos_val); 66 double q, sin_alpha, cos_alpha; 67 ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 78 68 79 69 const double core_qr = q*radius; … … 86 76 * (shell_sld-solvent_sld); 87 77 88 SINCOS(alpha, sn, cn); 89 const double fq = _cyl(core_twovd, core_qr*sn, core_qh*cn) 90 + _cyl(shell_twovd, shell_qr*sn, shell_qh*cn); 78 const double fq = _cyl(core_twovd, core_qr*sin_alpha, core_qh*cos_alpha) 79 + _cyl(shell_twovd, shell_qr*sin_alpha, shell_qh*cos_alpha); 91 80 return 1.0e-4 * fq * fq; 92 81 } -
sasmodels/models/core_shell_ellipsoid.c
r0d6e865 r5bddd89 32 32 const double equat_shell = radius_equat_core + thick_shell; 33 33 const double polar_shell = radius_equat_core*x_core + thick_shell*x_polar_shell; 34 double vol = 4.0*M_PI/3.0*equat_shell*equat_shell*polar_shell;34 double vol = M_4PI_3*equat_shell*equat_shell*polar_shell; 35 35 return vol; 36 36 } … … 60 60 61 61 for(int i=0;i<N_POINTS_76;i++) { 62 double zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;62 double zi = 0.5*( Gauss76Z[i]*(uplim-lolim) + uplim + lolim ); 63 63 double yyy = Gauss76Wt[i] * gfn4(zi, 64 64 radius_equat_core, … … 72 72 } 73 73 74 double answer = (uplim-lolim)/2.0*summ;74 double answer = 0.5*(uplim-lolim)*summ; 75 75 //convert to [cm-1] 76 76 answer *= 1.0e-4; … … 80 80 81 81 static double 82 core_shell_ellipsoid_xt_kernel_2d(double q , double q_x, double q_y,82 core_shell_ellipsoid_xt_kernel_2d(double qx, double qy, 83 83 double radius_equat_core, 84 84 double x_core, … … 91 91 double phi) 92 92 { 93 //convert angle degree to radian 94 theta = theta * M_PI_180; 95 phi = phi * M_PI_180; 96 97 // ellipsoid orientation, the axis of the rotation is consistent with the ploar axis. 98 const double cyl_x = sin(theta) * cos(phi); 99 const double cyl_y = sin(theta) * sin(phi); 93 double q, sin_alpha, cos_alpha; 94 ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 100 95 101 96 const double sldcs = core_sld - shell_sld; 102 97 const double sldss = shell_sld- solvent_sld; 103 104 // Compute the angle btw vector q and the105 // axis of the cylinder106 const double cos_val = cyl_x*q_x + cyl_y*q_y;107 98 108 99 const double polar_core = radius_equat_core*x_core; … … 112 103 // Call the IGOR library function to get the kernel: 113 104 // MUST use gfn4 not gf2 because of the def of params. 114 double answer = gfn4(cos_ val,105 double answer = gfn4(cos_alpha, 115 106 radius_equat_core, 116 107 polar_core, … … 160 151 double phi) 161 152 { 162 double q; 163 q = sqrt(qx*qx+qy*qy); 164 double intensity = core_shell_ellipsoid_xt_kernel_2d(q, qx/q, qy/q, 153 double intensity = core_shell_ellipsoid_xt_kernel_2d(qx, qy, 165 154 radius_equat_core, 166 155 x_core, -
sasmodels/models/ellipsoid.c
r0d6e865 r5bddd89 49 49 double phi) 50 50 { 51 double sn, cn; 52 53 const double q = sqrt(qx*qx + qy*qy); 54 SINCOS(phi*M_PI_180, sn, cn); 55 const double cos_alpha = (q==0. ? 1.0 : (cn*qx + sn*qy)*sin(theta*M_PI_180)/q); 56 const double alpha = acos(cos_alpha); 57 SINCOS(alpha, sn, cn); 58 const double form = _ellipsoid_kernel(q, radius_polar, radius_equatorial, sn); 51 double q, sin_alpha, cos_alpha; 52 ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 53 const double form = _ellipsoid_kernel(q, radius_polar, radius_equatorial, sin_alpha); 59 54 const double s = (sld - sld_solvent) * form_volume(radius_polar, radius_equatorial); 60 55 -
sasmodels/models/hollow_cylinder.c
r0d6e865 r5bddd89 1 1 double form_volume(double radius, double thickness, double length); 2 3 2 double Iq(double q, double radius, double thickness, double length, double sld, 4 3 double solvent_sld); … … 9 8 10 9 // From Igor library 11 static double hollow_cylinder_scaling(12 10 static double 11 _hollow_cylinder_scaling(double integrand, double delrho, double volume) 13 12 { 14 double answer; 15 // Multiply by contrast^2 16 answer = integrand*delrho*delrho; 17 18 //normalize by cylinder volume 19 answer *= volume*volume; 20 21 //convert to [cm-1] 22 answer *= 1.0e-4; 23 24 return answer; 13 return 1.0e-4 * square(volume * delrho * integrand); 25 14 } 26 15 27 16 28 static double _hollow_cylinder_kernel( 29 double q, double radius, double thickness, double length, double dum) 17 static double 18 _hollow_cylinder_kernel(double q, 19 double radius, double thickness, double length, double sin_val, double cos_val) 30 20 { 31 const double qs = q*s qrt(1.0-dum*dum);21 const double qs = q*sin_val; 32 22 const double lam1 = sas_J1c((radius+thickness)*qs); 33 23 const double lam2 = sas_J1c(radius*qs); … … 35 25 //Note: lim_{r -> r_c} psi = J0(radius_core*qs) 36 26 const double psi = (lam1 - gamma_sq*lam2)/(1.0 - gamma_sq); //SRK 10/19/00 37 const double t2 = sinc( q*length*dum/2.0);38 return square(psi*t2);27 const double t2 = sinc(0.5*q*length*cos_val); 28 return psi*t2; 39 29 } 40 30 41 42 static double hollow_cylinder_analytical_2D_scaled( 43 double q, double q_x, double q_y, double radius, double thickness, 44 double length, double sld, double solvent_sld, double theta, double phi) 45 { 46 double cyl_x, cyl_y; //, cyl_z 47 //double q_z; 48 double vol, cos_val, delrho; 49 double answer; 50 //convert angle degree to radian 51 theta = theta * M_PI_180; 52 phi = phi * M_PI_180; 53 delrho = solvent_sld - sld; 54 55 // Cylinder orientation 56 cyl_x = sin(theta) * cos(phi); 57 cyl_y = sin(theta) * sin(phi); 58 //cyl_z = -cos(theta) * sin(phi); 59 60 // q vector 61 //q_z = 0; 62 63 // Compute the angle btw vector q and the 64 // axis of the cylinder 65 cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 66 67 answer = _hollow_cylinder_kernel(q, radius, thickness, length, cos_val); 68 69 vol = form_volume(radius, thickness, length); 70 answer = hollow_cylinder_scaling(answer, delrho, vol); 71 72 return answer; 73 } 74 75 76 double form_volume(double radius, double thickness, double length) 31 double 32 form_volume(double radius, double thickness, double length) 77 33 { 78 34 double v_shell = M_PI*length*((radius+thickness)*(radius+thickness)-radius*radius); … … 81 37 82 38 83 double Iq(double q, double radius, double thickness, double length, 39 double 40 Iq(double q, double radius, double thickness, double length, 84 41 double sld, double solvent_sld) 85 42 { 86 int i; 87 double lower,upper,zi, inter; //upper and lower integration limits 88 double summ,answer,delrho; //running tally of integration 89 double norm,volume; //final calculation variables 43 const double lower = 0.0; 44 const double upper = 1.0; //limits of numerical integral 90 45 91 lower = 0.0; 92 upper = 1.0; //limits of numerical integral 93 94 summ = 0.0; //initialize intergral 95 for (i=0;i<76;i++) { 96 zi = ( Gauss76Z[i] * (upper-lower) + lower + upper )/2.0; 97 inter = Gauss76Wt[i] * _hollow_cylinder_kernel(q, radius, thickness, length, zi); 98 summ += inter; 46 double summ = 0.0; //initialize intergral 47 for (int i=0;i<76;i++) { 48 const double cos_val = 0.5*( Gauss76Z[i] * (upper-lower) + lower + upper ); 49 const double sin_val = sqrt(1.0 - cos_val*cos_val); 50 const double inter = _hollow_cylinder_kernel(q, radius, thickness, length, 51 sin_val, cos_val); 52 summ += Gauss76Wt[i] * inter; 99 53 } 100 54 101 norm = summ*(upper-lower)/2.0;102 volume = form_volume(radius, thickness, length);103 delrho = solvent_sld - sld;104 answer = hollow_cylinder_scaling(norm, delrho, volume); 55 const double Aq = 0.5*summ*(upper-lower); 56 const double volume = form_volume(radius, thickness, length); 57 return _hollow_cylinder_scaling(Aq, solvent_sld - sld, volume); 58 } 105 59 106 return(answer); 60 double 61 Iqxy(double qx, double qy, 62 double radius, double thickness, double length, 63 double sld, double solvent_sld, double theta, double phi) 64 { 65 double q, sin_alpha, cos_alpha; 66 ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 67 const double Aq = _hollow_cylinder_kernel(q, radius, thickness, length, 68 sin_alpha, cos_alpha); 69 70 const double vol = form_volume(radius, thickness, length); 71 return _hollow_cylinder_scaling(Aq, solvent_sld-sld, vol); 107 72 } 108 73 109 74 110 double Iqxy(double qx, double qy, double radius, double thickness,111 double length, double sld, double solvent_sld, double theta, double phi)112 {113 const double q = sqrt(qx*qx+qy*qy);114 return hollow_cylinder_analytical_2D_scaled(q, qx/q, qy/q, radius, thickness, length, sld, solvent_sld, theta, phi);115 }
Note: See TracChangeset
for help on using the changeset viewer.