source: sasview/sansmodels/src/sans/models/c_extensions/lamellarPS.c @ c09ace41

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

Updated the definition of SLD params according to new libigor functions

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * Scattering model for a lamellar
3 * TODO: Add 2D analysis
4 */
5
6#include "lamellarPS.h"
7#include <math.h>
8#include "libCylinder.h"
9#include <stdio.h>
10#include <stdlib.h>
11
12/*LamellarPS_kernel() was moved from libigor to get rid of polydipersity in del(thickness) that we provide from control panel.
13/*      LamellarPSX  :  calculates the form factor of a lamellar structure - with S(q) effects included
14-------
15------- resolution effects ARE NOT included, but only a CONSTANT default value, not the real q-dependent resolution!!
16
17        */
18double
19LamellarPS_kernel(double dp[], double q)
20{
21        double scale,dd,del,sld_bi,sld_sol,contr,NN,Cp,bkg;             //local variables of coefficient wave
22        double inten, qval,Pq,Sq,alpha,temp,t1,t2,t3,dQ;
23        double Pi,Euler,dQDefault,fii;
24        int ii,NNint;
25        Euler = 0.5772156649;           // Euler's constant
26        dQDefault = 0.0;                //[=] 1/A, q-resolution, default value
27        dQ = dQDefault;
28
29        Pi = 4.0*atan(1.0);
30        qval = q;
31
32        scale = dp[0];
33        dd = dp[1];
34        del = dp[2];
35        sld_bi = dp[3];
36        sld_sol = dp[4];
37        NN = trunc(dp[5]);              //be sure that NN is an integer
38        Cp = dp[6];
39        bkg = dp[7];
40
41        contr = sld_bi - sld_sol;
42
43        Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del));
44
45        NNint = (int)NN;                //cast to an integer for the loop
46        ii=0;
47        Sq = 0.0;
48        for(ii=1;ii<(NNint-1);ii+=1) {
49
50                fii = (double)ii;               //do I really need to do this?
51
52                temp = 0.0;
53                alpha = Cp/4.0/Pi/Pi*(log(Pi*ii) + Euler);
54                t1 = 2.0*dQ*dQ*dd*dd*alpha;
55                t2 = 2.0*qval*qval*dd*dd*alpha;
56                t3 = dQ*dQ*dd*dd*ii*ii;
57
58                temp = 1.0-ii/NN;
59                temp *= cos(dd*qval*ii/(1.0+t1));
60                temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) );
61                temp /= sqrt(1.0+t1);
62
63                Sq += temp;
64        }
65
66        Sq *= 2.0;
67        Sq += 1.0;
68
69        inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval);
70
71        inten *= 1.0e8;         // 1/A to 1/cm
72
73    return(inten+bkg);
74}
75
76/**
77 * Function to evaluate 1D scattering function
78 * @param pars: parameters of the lamellar
79 * @param q: q-value
80 * @return: function value
81 */
82double lamellarPS_analytical_1D(LamellarPSParameters *pars, double q) {
83        double dp[8];
84
85        // Fill paramater array
86        dp[0] = pars->scale;
87        dp[1] = pars->spacing;
88        dp[2] = pars->delta;
89        dp[3] = pars->sld_bi;
90        dp[4] = pars->sld_sol;
91        dp[5] = pars->n_plates;
92        dp[6] = pars->caille;
93        dp[7] = pars->background;
94
95        // Call library function to evaluate model
96        return LamellarPS_kernel(dp, q);
97}
98/**
99 * Function to evaluate 2D scattering function
100 * @param pars: parameters of the lamellar
101 * @param q: q-value
102 * @return: function value
103 */
104double lamellarPS_analytical_2DXY(LamellarPSParameters *pars, double qx, double qy) {
105        double q;
106        q = sqrt(qx*qx+qy*qy);
107    return lamellarPS_analytical_1D(pars, q);
108}
109
110
111/**
112 * Function to evaluate 2D scattering function
113 * @param pars: parameters of the lamellar
114 * @param q: q-value
115 * @param phi: angle phi
116 * @return: function value
117 */
118double lamellarPS_analytical_2D(LamellarPSParameters *pars, double q, double phi) {
119    return lamellarPS_analytical_1D(pars,q);
120}
121
122/**
123 * Function to evaluate 2D scattering function
124 * @param pars: parameters of the lamellar
125 * @param q: q-value
126 * @param q_x: q_x / q
127 * @param q_y: q_y / q
128 * @return: function value
129 */
130
131
Note: See TracBrowser for help on using the repository browser.