source: sasview/sansmodels/src/sans/models/c_extensions/parallelepiped.c @ 793c988

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 793c988 was 5068697, checked in by Gervaise Alina <gervyh@…>, 15 years ago

add 1d models

  • Property mode set to 100644
File size: 3.2 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_edgeA;
25        dp[2] = pars->longer_edgeB;
26        dp[3] = pars->longuest_edgeC;
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 * Function to evaluate 2D scattering function
35 * @param pars: parameters of the parallelepiped
36 * @param q: q-value
37 * @return: function value
38 */
39double parallelepiped_analytical_2DXY(ParallelepipedParameters *pars, double qx, double qy) {
40        double q;
41        q = sqrt(qx*qx+qy*qy);
42    return parallelepiped_analytical_2D_scaled(pars, q, qx/q, qy/q);
43} 
44
45
46/**
47 * Function to evaluate 2D scattering function
48 * @param pars: parameters of the Parallelepiped
49 * @param q: q-value
50 * @param phi: angle phi
51 * @return: function value
52 */
53double parallelepiped_analytical_2D(ParallelepipedParameters *pars, double q, double phi) {
54    return parallelepiped_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
55} 
56       
57/**
58 * Function to evaluate 2D scattering function
59 * @param pars: parameters of the parallelepiped
60 * @param q: q-value
61 * @param q_x: q_x / q
62 * @param q_y: q_y / q
63 * @return: function value
64 */
65double parallelepiped_analytical_2D_scaled(ParallelepipedParameters *pars, double q, double q_x, double q_y) {
66        double parallel_x, parallel_y, parallel_z;
67        double q_z;
68        double alpha, vol, cos_val;
69        double aa, mu, uu;
70        double answer;
71       
72       
73
74    // parallelepiped orientation
75    parallel_x = sin(pars->parallel_theta) * cos(pars->parallel_phi);
76    parallel_y = sin(pars->parallel_theta) * sin(pars->parallel_phi);
77    parallel_z = cos(pars->parallel_theta);
78     
79    // q vector
80    q_z = 0;
81       
82    // Compute the angle btw vector q and the
83    // axis of the parallelepiped
84    cos_val = parallel_x*q_x + parallel_y*q_y + parallel_z*q_z;
85   
86    // The following test should always pass
87    if (fabs(cos_val)>1.0) {
88        printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n");
89        return 0;
90    }
91   
92    // Note: cos(alpha) = 0 and 1 will get an
93    // undefined value from PPKernel
94        alpha = acos( cos_val );
95
96        aa = pars->short_edgeA/pars->longer_edgeB;
97        mu = 1.0;
98        uu = 1.0;
99       
100        // Call the IGOR library function to get the kernel
101        answer = PPKernel( aa, mu, uu);
102       
103        // Multiply by contrast^2
104        answer *= pars->contrast*pars->contrast;
105       
106        //normalize by cylinder volume
107        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vparallel
108    vol = pars->short_edgeA* pars->longer_edgeB * pars->longuest_edgeC;
109        answer *= vol;
110       
111        //convert to [cm-1]
112        answer *= 1.0e8;
113       
114        //Scale
115        answer *= pars->scale;
116       
117        // add in the background
118        answer += pars->background;
119       
120        return answer;
121}
122   
123
Note: See TracBrowser for help on using the repository browser.