[339ce67] | 1 | /* |
---|
| 2 | * Scattering model for a BarBell |
---|
| 3 | */ |
---|
| 4 | #include "barbell.h" |
---|
| 5 | #include <math.h> |
---|
| 6 | #include "GaussWeights.h" |
---|
| 7 | #include "libCylinder.h" |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * Function to evaluate 1D scattering function |
---|
| 11 | * @param pars: parameters of the BarBell |
---|
| 12 | * @param q: q-value |
---|
| 13 | * @return: function value |
---|
| 14 | */ |
---|
| 15 | double barbell_analytical_1D(BarBellParameters *pars, double q) { |
---|
| 16 | double dp[7]; |
---|
| 17 | double result; |
---|
| 18 | |
---|
| 19 | dp[0] = pars->scale; |
---|
| 20 | dp[1] = pars->rad_bar; |
---|
| 21 | dp[2] = pars->len_bar; |
---|
| 22 | dp[3] = pars->rad_bell; |
---|
| 23 | dp[4] = pars->sld_barbell; |
---|
| 24 | dp[5] = pars->sld_solv; |
---|
| 25 | dp[6] = pars->background; |
---|
| 26 | |
---|
| 27 | result = Barbell(dp, q); |
---|
| 28 | // Make Sure it never goes to inf/nan. |
---|
| 29 | if ( result == INFINITY || result == NAN){ |
---|
| 30 | result = pars->background; |
---|
| 31 | } |
---|
| 32 | return result; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | double bar2d_kernel(double dp[], double q, double alpha) { |
---|
| 37 | int i,j; |
---|
| 38 | double Pi; |
---|
| 39 | double scale,contr,bkg,sldc,slds; |
---|
| 40 | double len,rad,hDist,endRad; |
---|
| 41 | int nordj=76; |
---|
| 42 | double zi=alpha,yyy,answer; //running tally of integration |
---|
| 43 | double summj,vaj,vbj,zij; //for the inner integration |
---|
| 44 | double arg1,arg2,inner,be; |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | scale = dp[0]; |
---|
| 48 | rad = dp[1]; |
---|
| 49 | len = dp[2]; |
---|
| 50 | endRad = dp[3]; |
---|
| 51 | sldc = dp[4]; |
---|
| 52 | slds = dp[5]; |
---|
| 53 | bkg = dp[6]; |
---|
| 54 | |
---|
| 55 | hDist = sqrt(fabs(endRad*endRad-rad*rad)); //by definition for this model |
---|
| 56 | |
---|
| 57 | contr = sldc-slds; |
---|
| 58 | |
---|
| 59 | Pi = 4.0*atan(1.0); |
---|
| 60 | vaj = -1.0*hDist/endRad; |
---|
| 61 | vbj = 1.0; //endpoints of inner integral |
---|
| 62 | |
---|
| 63 | summj=0.0; |
---|
| 64 | |
---|
| 65 | for(j=0;j<nordj;j++) { |
---|
| 66 | //20 gauss points for the inner integral |
---|
| 67 | zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0; //the "t" dummy |
---|
| 68 | yyy = Gauss76Wt[j] * Dumb_kernel(dp,q,zij,zi); //uses the same Kernel as the Dumbbell, here L>0 |
---|
| 69 | summj += yyy; |
---|
| 70 | } |
---|
| 71 | //now calculate the value of the inner integral |
---|
| 72 | inner = (vbj-vaj)/2.0*summj; |
---|
| 73 | inner *= 4.0*Pi*endRad*endRad*endRad; |
---|
| 74 | |
---|
| 75 | //now calculate outer integrand |
---|
| 76 | arg1 = q*len/2.0*cos(zi); |
---|
| 77 | arg2 = q*rad*sin(zi); |
---|
| 78 | yyy = inner; |
---|
| 79 | |
---|
| 80 | if(arg2 == 0) { |
---|
| 81 | be = 0.5; |
---|
| 82 | } else { |
---|
| 83 | be = NR_BessJ1(arg2)/arg2; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if(arg1 == 0.0) { //limiting value of sinc(0) is 1; sinc is not defined in math.h |
---|
| 87 | yyy += Pi*rad*rad*len*2.0*be; |
---|
| 88 | } else { |
---|
| 89 | yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; |
---|
| 90 | } |
---|
| 91 | yyy *= yyy; //sin(zi); |
---|
| 92 | answer = yyy; |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | answer /= Pi*rad*rad*len + 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0); //divide by volume |
---|
| 96 | answer *= 1.0e8; //convert to cm^-1 |
---|
| 97 | answer *= contr*contr; |
---|
| 98 | answer *= scale; |
---|
| 99 | answer += bkg; |
---|
| 100 | |
---|
| 101 | return answer; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * Function to evaluate 2D scattering function |
---|
| 107 | * @param pars: parameters of the BarBell |
---|
| 108 | * @param q: q-value |
---|
| 109 | * @return: function value |
---|
| 110 | */ |
---|
| 111 | double barbell_analytical_2DXY(BarBellParameters *pars, double qx, double qy){ |
---|
| 112 | double q; |
---|
| 113 | q = sqrt(qx*qx+qy*qy); |
---|
| 114 | return barbell_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | double barbell_analytical_2D(BarBellParameters *pars, double q, double phi) { |
---|
| 118 | return barbell_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * Function to evaluate 2D scattering function |
---|
| 123 | * @param pars: parameters of the BarBell |
---|
| 124 | * @param q: q-value |
---|
| 125 | * @param q_x: q_x / q |
---|
| 126 | * @param q_y: q_y / q |
---|
| 127 | * @return: function value |
---|
| 128 | */ |
---|
| 129 | double barbell_analytical_2D_scaled(BarBellParameters *pars, double q, double q_x, double q_y) { |
---|
| 130 | double cyl_x, cyl_y, cyl_z; |
---|
| 131 | double q_z; |
---|
| 132 | double alpha, vol, cos_val; |
---|
| 133 | double answer; |
---|
| 134 | double dp[7]; |
---|
| 135 | |
---|
| 136 | dp[0] = pars->scale; |
---|
| 137 | dp[1] = pars->rad_bar; |
---|
| 138 | dp[2] = pars->len_bar; |
---|
| 139 | dp[3] = pars->rad_bell; |
---|
| 140 | dp[4] = pars->sld_barbell; |
---|
| 141 | dp[5] = pars->sld_solv; |
---|
| 142 | dp[6] = pars->background; |
---|
| 143 | |
---|
[4628e31] | 144 | //convert angle degree to radian |
---|
| 145 | double pi = 4.0*atan(1.0); |
---|
| 146 | double theta = pars->theta * pi/180.0; |
---|
| 147 | double phi = pars->phi * pi/180.0; |
---|
[339ce67] | 148 | |
---|
| 149 | //double Pi = 4.0*atan(1.0); |
---|
| 150 | // Cylinder orientation |
---|
[4628e31] | 151 | cyl_x = sin(theta) * cos(phi); |
---|
| 152 | cyl_y = sin(theta) * sin(phi); |
---|
| 153 | cyl_z = cos(theta); |
---|
[339ce67] | 154 | |
---|
| 155 | // q vector |
---|
| 156 | q_z = 0; |
---|
| 157 | |
---|
| 158 | // Compute the angle btw vector q and the |
---|
| 159 | // axis of the cylinder |
---|
| 160 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
| 161 | |
---|
| 162 | // The following test should always pass |
---|
| 163 | if (fabs(cos_val)>1.0) { |
---|
| 164 | printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
| 165 | return 0; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // Note: cos(alpha) = 0 and 1 will get an |
---|
| 169 | // undefined value from CylKernel |
---|
| 170 | alpha = acos( cos_val ); |
---|
| 171 | |
---|
| 172 | // Call the IGOR library function to get the kernel |
---|
| 173 | answer = bar2d_kernel(dp, q, alpha)/sin(alpha); |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | return answer; |
---|
| 177 | |
---|
| 178 | } |
---|