/** This software was developed by the University of Tennessee as part of the Distributed Data Analysis of Neutron Scattering Experiments (DANSE) project funded by the US National Science Foundation. If you use DANSE applications to do scientific research that leads to publication, we ask that you acknowledge the use of the software with the following sentence: "This work benefited from DANSE software developed under NSF award DMR-0520547." copyright 2008, University of Tennessee */ #include #include "parameters.hh" #include #include using namespace std; #include "fuzzysphere.h" extern "C" { #include "libSphere.h" } // scattering from a uniform sphere w/ fuzzy surface // Modified from FuzzySpheres in libigor/libSphere.c without polydispersion: JHC static double fuzzysphere_kernel(double dp[], double q){ double pi,x,xr; double radius,sldSph,sldSolv,scale,bkg,delrho,fuzziness,f2,bes,vol,f; //my local names pi = 4.0*atan(1.0); x= q; scale = dp[0]; radius = dp[1]; fuzziness = dp[2]; sldSph = dp[3]; sldSolv = dp[4]; bkg = dp[5]; delrho=sldSph-sldSolv; xr = x*radius; //handle xr==0 separately if(xr == 0.0){ bes = 1.0; }else{ bes = 3.0*(sin(xr)-xr*cos(xr))/(xr*xr*xr); } vol = 4.0*pi/3.0*radius*radius*radius; f = vol*bes*delrho; // [=] A f *= exp(-0.5*fuzziness*fuzziness*x*x); // normalize to single particle volume, convert to 1/cm f2 = f * f / vol * 1.0e8; // [=] 1/cm f2 *= scale; f2 += bkg; return(f2); //scale, and add in the background } FuzzySphereModel :: FuzzySphereModel() { scale = Parameter(0.01); radius = Parameter(60.0, true); radius.set_min(0.0); fuzziness = Parameter(10.0); fuzziness.set_min(0.0); sldSph = Parameter(1.0e-6); sldSolv = Parameter(3.0e-6); background = Parameter(0.001); } /** * Function to evaluate 1D scattering function * The NIST IGOR library is used for the actual calculation. * @param q: q-value * @return: function value */ double FuzzySphereModel :: operator()(double q) { double dp[6]; // Fill parameter array for IGOR library // Add the background after averaging dp[0] = scale(); dp[1] = radius(); dp[2] = fuzziness(); dp[3] = sldSph(); dp[4] = sldSolv(); dp[5] = 0.0; // Get the dispersion points for the radius vector weights_radius; radius.get_weights(weights_radius); // Get the dispersion points for the fuzziness vector weights_fuzziness; fuzziness.get_weights(weights_fuzziness); // Perform the computation, with all weight points double sum = 0.0; double norm = 0.0; double norm_vol = 0.0; double vol = 0.0; // Loop over radius weight points for(size_t i=0; i weights_radius; radius.get_weights(weights_radius); // Loop over radius weight points to average the radius value for(size_t i=0; i