source: sasview/sansmodels/src/sans/models/c_extensions/fuzzysphere.c @ 0b12abb5

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

More models added and correction of Wrappergenerator on model parameter value precision

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * Scattering model for a fuzzy sphere
3 */
4
5#include <math.h>
6#include "libSphere.h"
7#include "fuzzysphere.h"
8#include <stdio.h>
9#include <stdlib.h>
10
11// scattering from a uniform sphere w/ fuzzy surface
12// Modified from FuzzySpheres in libigor/libSphere.c without polydispersion: JHC
13double fuzzysphere_kernel(double dp[], double q){
14        double pi,x,xr;
15        double radius,sldSph,sldSolv,scale,bkg,delrho,fuzziness,f2,bes,vol,f;           //my local names
16
17        pi = 4.0*atan(1.0);
18        x= q;
19        scale = dp[0];
20        radius = dp[1];
21        fuzziness = dp[2];
22        sldSph = dp[3];
23        sldSolv = dp[4];
24        bkg = dp[5];
25        delrho=sldSph-sldSolv;
26
27        xr = x*radius;
28        //handle xr==0 separately
29        if(xr == 0.0){
30                bes = 1.0;
31        }else{
32                bes = 3.0*(sin(xr)-xr*cos(xr))/(xr*xr*xr);
33        }
34        vol = 4.0*pi/3.0*radius*radius*radius;
35        f = vol*bes*delrho;             // [=] A
36        f *= exp(-0.5*fuzziness*fuzziness*x*x);
37        // normalize to single particle volume, convert to 1/cm
38        f2 = f * f / vol * 1.0e8;               // [=] 1/cm
39
40        f2 *= scale;
41        f2 += bkg;
42
43    return(f2); //scale, and add in the background
44}
45
46
47/**
48 * Function to evaluate 1D scattering function
49 * @param pars: parameters of the fuzzysphere
50 * @param q: q-value
51 * @return: function value
52 */
53double fuzzysphere_analytical_1D(FuzzySphereParameters *pars, double q) {
54        double dp[6];
55
56        dp[0] = pars->scale;
57        dp[1] = pars->radius;
58        dp[2] = pars->fuzziness;
59        dp[3] = pars->sldSph;
60        dp[4] = pars->sldSolv;
61        dp[5] = pars->background;
62
63        return fuzzysphere_kernel(dp, q);
64}
65
66/**
67 * Function to evaluate 2D scattering function
68 * @param pars: parameters of the fuzzysphere
69 * @param q: q-value
70 * @return: function value
71 */
72double fuzzysphere_analytical_2D(FuzzySphereParameters *pars, double q, double phi) {
73        return fuzzysphere_analytical_1D(pars,q);
74}
75
76double sphere_analytical_2DXY(FuzzySphereParameters *pars, double qx, double qy){
77        return fuzzysphere_analytical_1D(pars,sqrt(qx*qx+qy*qy));
78}
Note: See TracBrowser for help on using the repository browser.