source: sasview/sansmodels/src/sans/models/c_extensions/cylinder.c @ 67e258c

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 67e258c was f10063e, checked in by Jae Cho <jhjcho@…>, 14 years ago

Updated the definition of SLD params according to new libigor functions

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[ae3ce4e]1/**
2 * Scattering model for a cylinder
3 * @author: Mathieu Doucet / UTK
4 */
5
6#include "cylinder.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 cylinder
16 * @param q: q-value
17 * @return: function value
18 */
19double cylinder_analytical_1D(CylinderParameters *pars, double q) {
[f10063e]20        double dp[6];
21
[ae3ce4e]22        // Fill paramater array
23        dp[0] = pars->scale;
24        dp[1] = pars->radius;
25        dp[2] = pars->length;
[f10063e]26        dp[3] = pars->sldCyl;
27        dp[4] = pars->sldSolv;
28        dp[5] = pars->background;
29
[ae3ce4e]30        // Call library function to evaluate model
[f10063e]31        return CylinderForm(dp, q);
[ae3ce4e]32}
33
34/**
35 * Function to evaluate 2D scattering function
36 * @param pars: parameters of the cylinder
37 * @param q: q-value
38 * @return: function value
39 */
40double cylinder_analytical_2DXY(CylinderParameters *pars, double qx, double qy) {
41        double q;
42        q = sqrt(qx*qx+qy*qy);
43    return cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q);
[f10063e]44}
[ae3ce4e]45
46
47/**
48 * Function to evaluate 2D scattering function
49 * @param pars: parameters of the cylinder
50 * @param q: q-value
51 * @param phi: angle phi
52 * @return: function value
53 */
54double cylinder_analytical_2D(CylinderParameters *pars, double q, double phi) {
55    return cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
[f10063e]56}
57
[ae3ce4e]58/**
59 * Function to evaluate 2D scattering function
60 * @param pars: parameters of the cylinder
61 * @param q: q-value
62 * @param q_x: q_x / q
63 * @param q_y: q_y / q
64 * @return: function value
65 */
66double cylinder_analytical_2D_scaled(CylinderParameters *pars, double q, double q_x, double q_y) {
67        double cyl_x, cyl_y, cyl_z;
68        double q_z;
69        double alpha, vol, cos_val;
70        double answer;
[f10063e]71
[ae3ce4e]72    // Cylinder orientation
73    cyl_x = sin(pars->cyl_theta) * cos(pars->cyl_phi);
74    cyl_y = sin(pars->cyl_theta) * sin(pars->cyl_phi);
75    cyl_z = cos(pars->cyl_theta);
[f10063e]76
[ae3ce4e]77    // q vector
78    q_z = 0;
[f10063e]79
[ae3ce4e]80    // Compute the angle btw vector q and the
81    // axis of the cylinder
82    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
[f10063e]83
[ae3ce4e]84    // The following test should always pass
85    if (fabs(cos_val)>1.0) {
86        printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n");
87        return 0;
88    }
[f10063e]89
[ae3ce4e]90    // Note: cos(alpha) = 0 and 1 will get an
91    // undefined value from CylKernel
92        alpha = acos( cos_val );
[f10063e]93
[ae3ce4e]94        // Call the IGOR library function to get the kernel
95        answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha);
[f10063e]96
[ae3ce4e]97        // Multiply by contrast^2
[f10063e]98        answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv);
99
[ae3ce4e]100        //normalize by cylinder volume
101        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
102    vol = acos(-1.0) * pars->radius * pars->radius * pars->length;
103        answer *= vol;
[f10063e]104
[ae3ce4e]105        //convert to [cm-1]
106        answer *= 1.0e8;
[f10063e]107
[ae3ce4e]108        //Scale
109        answer *= pars->scale;
[f10063e]110
[ae3ce4e]111        // add in the background
112        answer += pars->background;
[f10063e]113
[ae3ce4e]114        return answer;
115}
[f10063e]116
Note: See TracBrowser for help on using the repository browser.