source: sasview/sansmodels/src/sans/models/c_extensions/stacked_disks.c @ d6da3b1

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 d6da3b1 was 3c102d4, checked in by Jae Cho <jhjcho@…>, 15 years ago

fixed problems in 2d

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[5068697]1/**
2 * Scattering model for a stacked disk
3 * TODO: Add 2D analysis
4 */
5
6#include "stacked_disks.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 staked disks
16 * @param q: q-value
17 * @return: function value
18 */
19double stacked_disks_analytical_1D(StackedDisksParameters *pars, double q) {
20        double dp[10];
[3c102d4]21
[5068697]22        // Fill paramater array
23        dp[0] = pars->scale;
24        dp[1] = pars->radius;
[3c102d4]25        dp[2] = pars->core_thick;
26        dp[3] = pars->layer_thick;
[5068697]27        dp[4] = pars->core_sld;
28        dp[5] = pars->layer_sld;
29        dp[6] = pars->solvent_sld;
[3c102d4]30        dp[7] = pars->n_stacking;
31        dp[8] = pars->sigma_d;
[5068697]32        dp[9] = pars->background;
33
34        // Call library function to evaluate model
[3c102d4]35        return StackedDiscs(dp, q);
[5068697]36}
37/**
38 * Function to evaluate 2D scattering function
39 * @param pars: parameters of the staked disks
40 * @param q: q-value
41 * @return: function value
42 */
43double stacked_disks_analytical_2DXY(StackedDisksParameters *pars, double qx, double qy) {
44        double q;
45        q = sqrt(qx*qx+qy*qy);
46    return stacked_disks_analytical_2D_scaled(pars, q, qx/q, qy/q);
[3c102d4]47}
[5068697]48
49
50/**
51 * Function to evaluate 2D scattering function
52 * @param pars: parameters of the staked disks
53 * @param q: q-value
54 * @param phi: angle phi
55 * @return: function value
56 */
57double stacked_disks_analytical_2D(StackedDisksParameters *pars, double q, double phi) {
58    return stacked_disks_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
[3c102d4]59}
60
[5068697]61/**
62 * Function to evaluate 2D scattering function
63 * @param pars: parameters of the staked disks
64 * @param q: q-value
65 * @param q_x: q_x / q
66 * @param q_y: q_y / q
67 * @return: function value
68 */
69double stacked_disks_analytical_2D_scaled(StackedDisksParameters *pars, double q, double q_x, double q_y) {
70        double cyl_x, cyl_y, cyl_z;
71        double q_z;
72        double alpha, vol, cos_val;
[3c102d4]73        double d, dum, halfheight;
[5068697]74        double answer;
[3c102d4]75
76
[5068697]77
78    // parallelepiped orientation
79    cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi);
80    cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi);
81    cyl_z = cos(pars->axis_theta);
[3c102d4]82
[5068697]83    // q vector
84    q_z = 0;
[3c102d4]85
[5068697]86    // Compute the angle btw vector q and the
87    // axis of the parallelepiped
88    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
[3c102d4]89
[5068697]90    // The following test should always pass
91    if (fabs(cos_val)>1.0) {
92        printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n");
93        return 0;
94    }
[3c102d4]95
[5068697]96    // Note: cos(alpha) = 0 and 1 will get an
97    // undefined value from Stackdisc_kern
98        alpha = acos( cos_val );
99
100        // Call the IGOR library function to get the kernel
[3c102d4]101        d = 2 * pars->layer_thick + pars->core_thick;
102        halfheight = pars->core_thick/2.0;
103        dum =alpha ;
[5068697]104        answer = Stackdisc_kern(q, pars->radius, pars->core_sld,pars->layer_sld,
[3c102d4]105                pars->solvent_sld, halfheight, pars->layer_thick, dum, pars->sigma_d, d, pars->n_stacking)/sin(alpha);
106
[5068697]107        // Multiply by contrast^2
108        //answer *= pars->contrast*pars->contrast;
[3c102d4]109
[5068697]110        //normalize by staked disks volume
[3c102d4]111    vol = acos(-1.0) * pars->radius * pars->radius * d * pars->n_stacking;
112        answer /= vol;
113
[5068697]114        //convert to [cm-1]
115        answer *= 1.0e8;
[3c102d4]116
[5068697]117        //Scale
118        answer *= pars->scale;
[3c102d4]119
[5068697]120        // add in the background
121        answer += pars->background;
[3c102d4]122
[5068697]123        return answer;
124}
[3c102d4]125
[5068697]126
Note: See TracBrowser for help on using the repository browser.