[d5b6a9d] | 1 | /* |
---|
| 2 | * Scattering model for a SC_ParaCrystal |
---|
| 3 | */ |
---|
| 4 | #include "fcc.h" |
---|
| 5 | #include "libSphere.h" |
---|
| 6 | #include <math.h> |
---|
[890ac7f1] | 7 | #include <stdio.h> |
---|
[d5b6a9d] | 8 | |
---|
| 9 | /** |
---|
| 10 | * Function to evaluate 1D scattering function |
---|
| 11 | * @param pars: parameters of the FCC_ParaCrystal |
---|
| 12 | * @param q: q-value |
---|
| 13 | * @return: function value |
---|
| 14 | */ |
---|
| 15 | double fcc_analytical_1D(FCParameters *pars, double q) { |
---|
| 16 | double dp[7]; |
---|
| 17 | double result; |
---|
| 18 | |
---|
| 19 | dp[0] = pars->scale; |
---|
| 20 | dp[1] = pars->dnn; |
---|
| 21 | dp[2] = pars->d_factor; |
---|
| 22 | dp[3] = pars->radius; |
---|
| 23 | dp[4] = pars->sldSph; |
---|
| 24 | dp[5] = pars->sldSolv; |
---|
| 25 | dp[6] = pars->background; |
---|
| 26 | |
---|
| 27 | result = FCC_ParaCrystal(dp, q); |
---|
| 28 | // This FIXES a singualrity the kernel in libigor. |
---|
| 29 | if ( result == INFINITY || result == NAN){ |
---|
| 30 | result = pars->background; |
---|
| 31 | } |
---|
| 32 | return result; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * Function to evaluate 2D scattering function |
---|
| 37 | * @param pars: parameters of the FCC_ParaCrystal |
---|
| 38 | * @param q: q-value |
---|
| 39 | * @return: function value |
---|
| 40 | */ |
---|
| 41 | double fc_analytical_2DXY(FCParameters *pars, double qx, double qy){ |
---|
| 42 | double q; |
---|
| 43 | q = sqrt(qx*qx+qy*qy); |
---|
| 44 | return fc_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | double fc_analytical_2D(FCParameters *pars, double q, double phi) { |
---|
| 48 | return fc_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * Function to evaluate 2D scattering function |
---|
| 53 | * @param pars: parameters of the FCCCrystalModel |
---|
| 54 | * @param q: q-value |
---|
| 55 | * @param q_x: q_x / q |
---|
| 56 | * @param q_y: q_y / q |
---|
| 57 | * @return: function value |
---|
| 58 | */ |
---|
| 59 | double fc_analytical_2D_scaled(FCParameters *pars, double q, double q_x, double q_y) { |
---|
[839f7e28] | 60 | double b3_x, b3_y, b3_z, b1_x, b1_y; |
---|
[d5b6a9d] | 61 | double q_z; |
---|
[839f7e28] | 62 | double alpha, cos_val_b3, cos_val_b2, cos_val_b1; |
---|
[d5b6a9d] | 63 | double a1_dot_q, a2_dot_q,a3_dot_q; |
---|
| 64 | double answer; |
---|
| 65 | double Pi = 4.0*atan(1.0); |
---|
[839f7e28] | 66 | double aa, Da, qDa_2, latticeScale, Zq, Fkq, Fkq_2; |
---|
[d5b6a9d] | 67 | |
---|
| 68 | double dp[5]; |
---|
[890ac7f1] | 69 | //convert angle degree to radian |
---|
| 70 | double theta = pars->theta * Pi/180.0; |
---|
| 71 | double phi = pars->phi * Pi/180.0; |
---|
| 72 | double psi = pars->psi * Pi/180.0; |
---|
[d5b6a9d] | 73 | dp[0] = 1.0; |
---|
| 74 | dp[1] = pars->radius; |
---|
| 75 | dp[2] = pars->sldSph; |
---|
| 76 | dp[3] = pars->sldSolv; |
---|
| 77 | dp[4] = 0.0; |
---|
| 78 | |
---|
| 79 | aa = pars->dnn; |
---|
| 80 | Da = pars->d_factor*aa; |
---|
| 81 | qDa_2 = pow(q*Da,2.0); |
---|
[18f2ca1] | 82 | //contrast = pars->sldSph - pars->sldSolv; |
---|
[d5b6a9d] | 83 | |
---|
| 84 | latticeScale = 4.0*(4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa*sqrt(2.0),3.0); |
---|
[85bb870] | 85 | // q vector |
---|
| 86 | q_z = 0.0; // for SANS; assuming qz is negligible |
---|
[d5b6a9d] | 87 | /// Angles here are respect to detector coordinate |
---|
[85bb870] | 88 | /// instead of against q coordinate in PRB 36(46), 3(6), 1754(3854) |
---|
[d5b6a9d] | 89 | // b3 axis orientation |
---|
[4628e31] | 90 | b3_x = sin(theta) * cos(phi);//negative sign here??? |
---|
| 91 | b3_y = sin(theta) * sin(phi); |
---|
| 92 | b3_z = cos(theta); |
---|
[85bb870] | 93 | cos_val_b3 = b3_x*q_x + b3_y*q_y + b3_z*q_z; |
---|
| 94 | alpha = acos(cos_val_b3); |
---|
[d5b6a9d] | 95 | // b1 axis orientation |
---|
[4628e31] | 96 | b1_x = sin(psi); |
---|
| 97 | b1_y = cos(psi); |
---|
[85bb870] | 98 | cos_val_b1 = (b1_x*q_x + b1_y*q_y); |
---|
[d5b6a9d] | 99 | // b2 axis orientation |
---|
[85bb870] | 100 | cos_val_b2 = sin(acos(cos_val_b1)); |
---|
| 101 | // alpha correction |
---|
| 102 | cos_val_b2 *= sin(alpha); |
---|
| 103 | cos_val_b1 *= sin(alpha); |
---|
[d5b6a9d] | 104 | |
---|
| 105 | // Compute the angle btw vector q and the a3 axis |
---|
[85bb870] | 106 | a3_dot_q = 0.5*aa*q*(cos_val_b2+cos_val_b1); |
---|
[d5b6a9d] | 107 | |
---|
| 108 | // a1 axis |
---|
[85bb870] | 109 | a1_dot_q = 0.5*aa*q*(cos_val_b2+cos_val_b3); |
---|
[d5b6a9d] | 110 | |
---|
| 111 | // a2 axis |
---|
[85bb870] | 112 | a2_dot_q = 0.5*aa*q*(cos_val_b3+cos_val_b1); |
---|
[d5b6a9d] | 113 | |
---|
| 114 | // The following test should always pass |
---|
[85bb870] | 115 | if (fabs(cos_val_b3)>1.0) { |
---|
| 116 | printf("fcc_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
[d5b6a9d] | 117 | return 0; |
---|
| 118 | } |
---|
| 119 | // Get Fkq and Fkq_2 |
---|
| 120 | Fkq = exp(-0.5*pow(Da/aa,2.0)*(a1_dot_q*a1_dot_q+a2_dot_q*a2_dot_q+a3_dot_q*a3_dot_q)); |
---|
| 121 | Fkq_2 = Fkq*Fkq; |
---|
| 122 | // Call Zq=Z1*Z2*Z3 |
---|
| 123 | Zq = (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a1_dot_q)+Fkq_2); |
---|
| 124 | Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a2_dot_q)+Fkq_2); |
---|
| 125 | Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a3_dot_q)+Fkq_2); |
---|
| 126 | |
---|
| 127 | // Use SphereForm directly from libigor |
---|
[18f2ca1] | 128 | answer = SphereForm(dp,q)*Zq; |
---|
[d5b6a9d] | 129 | |
---|
| 130 | //consider scales |
---|
| 131 | answer *= latticeScale * pars->scale; |
---|
| 132 | |
---|
| 133 | // This FIXES a singualrity the kernel in libigor. |
---|
| 134 | if ( answer == INFINITY || answer == NAN){ |
---|
| 135 | answer = 0.0; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | // add background |
---|
| 139 | answer += pars->background; |
---|
| 140 | |
---|
| 141 | return answer; |
---|
| 142 | } |
---|