[ae3ce4e] | 1 | /** |
---|
| 2 | * Scattering model for a core-shell cylinder |
---|
| 3 | * @author: Mathieu Doucet / UTK |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #include "core_shell_cylinder.h" |
---|
| 7 | #include "libCylinder.h" |
---|
| 8 | #include <math.h> |
---|
| 9 | #include <stdio.h> |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | /** |
---|
| 13 | * Function to evaluate 1D scattering function |
---|
| 14 | * @param pars: parameters of the core-shell cylinder |
---|
| 15 | * @param q: q-value |
---|
| 16 | * @return: function value |
---|
| 17 | */ |
---|
| 18 | double core_shell_cylinder_analytical_1D(CoreShellCylinderParameters *pars, double q) { |
---|
| 19 | double dp[8]; |
---|
| 20 | |
---|
| 21 | dp[0] = pars->scale; |
---|
| 22 | dp[1] = pars->radius; |
---|
| 23 | dp[2] = pars->thickness; |
---|
| 24 | dp[3] = pars->length; |
---|
| 25 | dp[4] = pars->core_sld; |
---|
| 26 | dp[5] = pars->shell_sld; |
---|
| 27 | dp[6] = pars->solvent_sld; |
---|
| 28 | dp[7] = pars->background; |
---|
| 29 | |
---|
| 30 | return CoreShellCylinder(dp, q); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * Function to evaluate 2D scattering function |
---|
| 35 | * @param pars: parameters of the core-shell cylinder |
---|
| 36 | * @param q: q-value |
---|
| 37 | * @return: function value |
---|
| 38 | */ |
---|
| 39 | double core_shell_cylinder_analytical_2DXY(CoreShellCylinderParameters *pars, double qx, double qy) { |
---|
| 40 | double q; |
---|
| 41 | q = sqrt(qx*qx+qy*qy); |
---|
| 42 | return core_shell_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * Function to evaluate 2D scattering function |
---|
| 47 | * @param pars: parameters of the core-shell cylinder |
---|
| 48 | * @param q: q-value |
---|
| 49 | * @param phi: angle phi |
---|
| 50 | * @return: function value |
---|
| 51 | */ |
---|
| 52 | double core_shell_cylinder_analytical_2D(CoreShellCylinderParameters *pars, double q, double phi) { |
---|
| 53 | return core_shell_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | /** |
---|
| 57 | * Function to evaluate 2D scattering function |
---|
| 58 | * @param pars: parameters of the core-shell cylinder |
---|
| 59 | * @param q: q-value |
---|
| 60 | * @param q_x: q_x / q |
---|
| 61 | * @param q_y: q_y / q |
---|
| 62 | * @return: function value |
---|
| 63 | */ |
---|
| 64 | double core_shell_cylinder_analytical_2D_scaled(CoreShellCylinderParameters *pars, double q, double q_x, double q_y) { |
---|
| 65 | double cyl_x, cyl_y, cyl_z; |
---|
| 66 | double q_z, lenq; |
---|
| 67 | double theta, alpha, f, vol, sin_val, cos_val; |
---|
| 68 | double answer; |
---|
| 69 | |
---|
| 70 | // Cylinder orientation |
---|
| 71 | cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi); |
---|
| 72 | cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi); |
---|
| 73 | cyl_z = cos(pars->axis_theta); |
---|
| 74 | |
---|
| 75 | // q vector |
---|
| 76 | q_z = 0; |
---|
| 77 | |
---|
| 78 | // Compute the angle btw vector q and the |
---|
| 79 | // axis of the cylinder |
---|
| 80 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
| 81 | |
---|
| 82 | // The following test should always pass |
---|
| 83 | if (fabs(cos_val)>1.0) { |
---|
| 84 | printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val); |
---|
| 85 | return 0; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | alpha = acos( cos_val ); |
---|
| 89 | |
---|
| 90 | // Call the IGOR library function to get the kernel |
---|
| 91 | answer = CoreShellCylKernel(q, pars->radius, pars->thickness, |
---|
| 92 | pars->core_sld,pars->shell_sld, |
---|
| 93 | pars->solvent_sld, pars->length/2.0, alpha) / sin(alpha); |
---|
| 94 | |
---|
| 95 | //normalize by cylinder volume |
---|
| 96 | vol=acos(-1.0)*(pars->radius+pars->thickness) |
---|
| 97 | *(pars->radius+pars->thickness) |
---|
| 98 | *(pars->length+2.0*pars->thickness); |
---|
| 99 | answer /= vol; |
---|
| 100 | |
---|
| 101 | //convert to [cm-1] |
---|
| 102 | answer *= 1.0e8; |
---|
| 103 | |
---|
| 104 | //Scale |
---|
| 105 | answer *= pars->scale; |
---|
| 106 | |
---|
| 107 | // add in the background |
---|
| 108 | answer += pars->background; |
---|
| 109 | |
---|
| 110 | return answer; |
---|
| 111 | } |
---|