source: sasview/sansmodels/src/sans/models/c_extensions/parallelepiped.c @ 8a6d4af

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 8a6d4af was 8e36cdd, checked in by Jae Cho <jhjcho@…>, 15 years ago

fixed and tested ppmodel 2d and cleaned it up.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/**
2 * Scattering model for a parallelepiped
3 * TODO: Add 2D analysis
4 */
5
6#include "parallelepiped.h"
7#include <math.h>
8#include "libCylinder.h"
9#include <stdio.h>
10#include <stdlib.h>
11
12
13/**
14 * Function to evaluate 1D scattering function
15 * @param pars: parameters of the parallelepiped
16 * @param q: q-value
17 * @return: function value
18 */
19double parallelepiped_analytical_1D(ParallelepipedParameters *pars, double q) {
20        double dp[6];
21
22        // Fill paramater array
23        dp[0] = pars->scale;
24        dp[1] = pars->short_a;
25        dp[2] = pars->short_b;
26        dp[3] = pars->long_c;
27        dp[4] = pars->contrast;
28        dp[5] = pars->background;
29
30        // Call library function to evaluate model
31        return Parallelepiped(dp, q);
32}
33
34
35double pkernel(double a, double b,double c, double ala, double alb, double alc){
36    // mu passed in is really mu*sqrt(1-sig^2)
37    double argA,argB,argC,tmp1,tmp2,tmp3;                       //local variables
38
39    //handle arg=0 separately, as sin(t)/t -> 1 as t->0
40    argA = a*ala/2;
41    argB = b*alb/2;
42    argC = c*alc/2;
43    if(argA==0.0) {
44                tmp1 = 1.0;
45        } else {
46                tmp1 = sin(argA)*sin(argA)/argA/argA;
47    }
48    if (argB==0.0) {
49                tmp2 = 1.0;
50        } else {
51                tmp2 = sin(argB)*sin(argB)/argB/argB;
52    }
53
54    if (argC==0.0) {
55                tmp3 = 1.0;
56        } else {
57                tmp3 = sin(argC)*sin(argC)/argC/argC;
58    }
59
60    return (tmp1*tmp2*tmp3);
61
62}//Function pkernel()
63
64
65
66
67/**
68 * Function to evaluate 2D scattering function
69 * @param pars: parameters of the parallelepiped
70 * @param q: q-value
71 * @return: function value
72 */
73double parallelepiped_analytical_2DXY(ParallelepipedParameters *pars, double qx, double qy) {
74        double q;
75        q = sqrt(qx*qx+qy*qy);
76    return parallelepiped_analytical_2D_scaled(pars, q, qx/q, qy/q);
77}
78
79
80/**
81 * Function to evaluate 2D scattering function
82 * @param pars: parameters of the Parallelepiped
83 * @param q: q-value
84 * @param phi: angle phi
85 * @return: function value
86 */
87double parallelepiped_analytical_2D(ParallelepipedParameters *pars, double q, double phi) {
88    return parallelepiped_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
89}
90
91/**
92 * Function to evaluate 2D scattering function
93 * @param pars: parameters of the parallelepiped
94 * @param q: q-value
95 * @param q_x: q_x / q
96 * @param q_y: q_y / q
97 * @return: function value
98 */
99double parallelepiped_analytical_2D_scaled(ParallelepipedParameters *pars, double q, double q_x, double q_y) {
100        double cparallel_x, cparallel_y, cparallel_z, bparallel_x, bparallel_y, parallel_x, parallel_y, parallel_z;
101        double q_z;
102        double alpha, vol, cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC;
103
104        double answer;
105        double pi = 4.0*atan(1.0);
106
107        edgeA = pars->short_a;
108        edgeB = pars->short_b;
109        edgeC = pars->long_c;
110
111
112    // parallelepiped c axis orientation
113    cparallel_x = sin(pars->parallel_theta) * cos(pars->parallel_phi);
114    cparallel_y = sin(pars->parallel_theta) * sin(pars->parallel_phi);
115    cparallel_z = cos(pars->parallel_theta);
116
117    // q vector
118    q_z = 0;
119
120    // Compute the angle btw vector q and the
121    // axis of the parallelepiped
122    cos_val_c = cparallel_x*q_x + cparallel_y*q_y + cparallel_z*q_z;
123    alpha = acos(cos_val_c);
124
125    // parallelepiped a axis orientation
126    parallel_x = sin(pars->parallel_psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)*sin(pars->parallel_psi);
127    parallel_y = cos(pars->parallel_psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)*cos(pars->parallel_psi);
128
129    cos_val_a = parallel_x*q_x + parallel_y*q_y;
130
131
132
133    // parallelepiped b axis orientation
134    bparallel_x = sqrt(1-sin(pars->parallel_theta)*cos(pars->parallel_phi))*cos(pars->parallel_psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)* cos(pars->parallel_psi);
135    bparallel_y = sqrt(1-sin(pars->parallel_theta)*cos(pars->parallel_phi))*sin(pars->parallel_psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)* sin(pars->parallel_psi);
136    // axis of the parallelepiped
137    cos_val_b = sin(acos(cos_val_a)) ;
138
139
140
141    // The following test should always pass
142    if (fabs(cos_val_c)>1.0) {
143        printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n");
144        return 0;
145    }
146
147        // Call the IGOR library function to get the kernel
148        answer = pkernel( q*edgeA, q*edgeB, q*edgeC, sin(alpha)*cos_val_a,sin(alpha)*cos_val_b,cos_val_c);
149
150        // Multiply by contrast^2
151        answer *= pars->contrast*pars->contrast;
152
153        //normalize by cylinder volume
154        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vparallel
155    vol = edgeA* edgeB * edgeC;
156        answer *= vol;
157
158        //convert to [cm-1]
159        answer *= 1.0e8;
160
161        //Scale
162        answer *= pars->scale;
163
164        // add in the background
165        answer += pars->background;
166
167        return answer;
168}
169
Note: See TracBrowser for help on using the repository browser.