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

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

some corrections and removed polydispersity from inside of function and set dQ =0

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[27a0771]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
[c1c29b6]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,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;//0.0025;               //[=] 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        contr = dp[3];
36        NN = trunc(dp[4]);              //be sure that NN is an integer
37        Cp = dp[5];
38        bkg = dp[6];
39
40        Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del));
41
42        NNint = (int)NN;                //cast to an integer for the loop
43        ii=0;
44        Sq = 0.0;
45        for(ii=1;ii<(NNint-1);ii+=1) {
46
47                fii = (double)ii;               //do I really need to do this?
48
49                temp = 0.0;
50                alpha = Cp/4.0/Pi/Pi*(log(Pi*ii) + Euler);
51                t1 = 2.0*dQ*dQ*dd*dd*alpha;
52                t2 = 2.0*qval*qval*dd*dd*alpha;
53                t3 = dQ*dQ*dd*dd*ii*ii;
54
55                temp = 1.0-ii/NN;
56                temp *= cos(dd*qval*ii/(1.0+t1));
57                temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) );
58                temp /= sqrt(1.0+t1);
59
60                Sq += temp;
61        }
62
63        Sq *= 2.0;
64        Sq += 1.0;
65
66        inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval);
67
68        inten *= 1.0e8;         // 1/A to 1/cm
69
70    return(inten+bkg);
71}
[27a0771]72
73/**
74 * Function to evaluate 1D scattering function
75 * @param pars: parameters of the lamellar
76 * @param q: q-value
77 * @return: function value
78 */
79double lamellarPS_analytical_1D(LamellarPSParameters *pars, double q) {
[c1c29b6]80        double dp[7];
[b4679de]81
[27a0771]82        // Fill paramater array
83        dp[0] = pars->scale;
84        dp[1] = pars->spacing;
85        dp[2] = pars->delta;
[c1c29b6]86        dp[3] = pars->contrast;
87        dp[4] = pars->n_plates;
88        dp[5] = pars->caille;
89        dp[6] = pars->background;
[27a0771]90
91        // Call library function to evaluate model
[c1c29b6]92        return LamellarPS_kernel(dp, q);
[27a0771]93}
94/**
95 * Function to evaluate 2D scattering function
96 * @param pars: parameters of the lamellar
97 * @param q: q-value
98 * @return: function value
99 */
100double lamellarPS_analytical_2DXY(LamellarPSParameters *pars, double qx, double qy) {
101        double q;
102        q = sqrt(qx*qx+qy*qy);
[b4679de]103    return lamellarPS_analytical_1D(pars, q);
104}
[27a0771]105
106
107/**
108 * Function to evaluate 2D scattering function
109 * @param pars: parameters of the lamellar
110 * @param q: q-value
111 * @param phi: angle phi
112 * @return: function value
113 */
114double lamellarPS_analytical_2D(LamellarPSParameters *pars, double q, double phi) {
[b4679de]115    return lamellarPS_analytical_1D(pars,q);
116}
117
[27a0771]118/**
119 * Function to evaluate 2D scattering function
120 * @param pars: parameters of the lamellar
121 * @param q: q-value
122 * @param q_x: q_x / q
123 * @param q_y: q_y / q
124 * @return: function value
125 */
[b4679de]126
[27a0771]127
Note: See TracBrowser for help on using the repository browser.