source: sasmodels/sasmodels/models/hollow_cylinder.c @ 2f5c6d4

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 2f5c6d4 was 2f5c6d4, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

move valid parameter test to macro

  • Property mode set to 100644
File size: 3.6 KB
Line 
1double form_volume(double radius, double core_radius, double length);
2
3double Iq(double q, double radius, double core_radius, double length, double sld,
4        double solvent_sld);
5double Iqxy(double qx, double qy, double radius, double core_radius, double length, double sld,
6        double solvent_sld, double theta, double phi);
7
8#define INVALID(v) (v.core_radius >= v.radius || v.radius >= v.length)
9
10// From Igor library
11static double hollow_cylinder_scaling(double integrand, double delrho, double volume)
12{
13        double answer;
14        // Multiply by contrast^2
15        answer = integrand*delrho*delrho;
16
17        //normalize by cylinder volume
18        answer *= volume*volume;
19
20        //convert to [cm-1]
21        answer *= 1.0e-4;
22
23        return answer;
24}
25
26static double _hollow_cylinder_kernel(double q, double core_radius, double radius,
27        double length, double dum)
28{
29    double gamma,arg1,arg2,lam1,lam2,psi,sinarg,t2,retval;              //local variables
30   
31    gamma = core_radius/radius;
32    arg1 = q*radius*sqrt(1.0-dum*dum);          //1=shell (outer radius)
33    arg2 = q*core_radius*sqrt(1.0-dum*dum);                     //2=core (inner radius)
34    if (arg1 == 0.0){
35        lam1 = 1.0;
36    }else{
37        lam1 = sas_J1c(arg1);
38    }
39    if (arg2 == 0.0){
40        lam2 = 1.0;
41    }else{
42        lam2 = sas_J1c(arg2);
43    }
44    //Todo: Need to check psi behavior as gamma goes to 1.
45    psi = (lam1 -  gamma*gamma*lam2)/(1.0-gamma*gamma);         //SRK 10/19/00
46    sinarg = q*length*dum/2.0;
47    if (sinarg == 0.0){
48        t2 = 1.0;
49    }else{
50        t2 = sin(sinarg)/sinarg;
51    }
52
53    retval = psi*psi*t2*t2;
54   
55    return(retval);
56}
57static double hollow_cylinder_analytical_2D_scaled(double q, double q_x, double q_y, double radius, double core_radius, double length, double sld,
58        double solvent_sld, double theta, double phi) {
59        double cyl_x, cyl_y; //, cyl_z
60        //double q_z;
61        double vol, cos_val, delrho;
62        double answer;
63        //convert angle degree to radian
64        double pi = 4.0*atan(1.0);
65        theta = theta * pi/180.0;
66        phi = phi * pi/180.0;
67        delrho = solvent_sld - sld;
68
69        // Cylinder orientation
70        cyl_x = cos(theta) * cos(phi);
71        cyl_y = sin(theta);
72        //cyl_z = -cos(theta) * sin(phi);
73
74        // q vector
75        //q_z = 0;
76
77        // Compute the angle btw vector q and the
78        // axis of the cylinder
79        cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z;
80
81        answer = _hollow_cylinder_kernel(q, core_radius, radius, length, cos_val);
82
83        vol = form_volume(radius, core_radius, length);
84        answer = hollow_cylinder_scaling(answer, delrho, vol);
85
86        return answer;
87}
88
89
90double form_volume(double radius, double core_radius, double length)
91{
92        double pi = 4.0*atan(1.0);
93        double v_shell = pi*length*(radius*radius-core_radius*core_radius);
94        return(v_shell);
95}
96
97
98double Iq(double q, double radius, double core_radius, double length, double sld,
99        double solvent_sld)
100{
101    int i;
102        int nord=76;                    //order of integration
103        double lower,upper,zi, inter;           //upper and lower integration limits
104        double summ,answer,delrho;                      //running tally of integration
105        double norm,volume;     //final calculation variables
106       
107        delrho = solvent_sld - sld;
108        lower = 0.0;
109        upper = 1.0;            //limits of numerical integral
110
111        summ = 0.0;                     //initialize intergral
112        for(i=0;i<nord;i++) {
113                zi = ( Gauss76Z[i] * (upper-lower) + lower + upper )/2.0;
114                inter = Gauss76Wt[i] * _hollow_cylinder_kernel(q, core_radius, radius, length, zi);
115                summ += inter;
116        }
117       
118        norm = summ*(upper-lower)/2.0;
119        volume = form_volume(radius, core_radius, length);
120        answer = hollow_cylinder_scaling(norm, delrho, volume);
121       
122        return(answer);
123}
124
125double Iqxy(double qx, double qy, double radius, double core_radius, double length, double sld,
126        double solvent_sld, double theta, double phi)
127{
128        double q;
129        q = sqrt(qx*qx+qy*qy);
130        return hollow_cylinder_analytical_2D_scaled(q, qx/q, qy/q, radius, core_radius, length, sld, solvent_sld, theta, phi);
131}
Note: See TracBrowser for help on using the repository browser.