/** 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 */ /** * Scattering model classes * The classes use the IGOR library found in * sansmodels/src/libigor * * TODO: refactor so that we pull in the old sansmodels.c_extensions */ #include #include "models.hh" #include "parameters.hh" #include using namespace std; extern "C" { #include "libCylinder.h" #include "ellipsoid.h" } EllipsoidModel :: EllipsoidModel() { scale = Parameter(1.0); radius_a = Parameter(20.0, true); radius_a.set_min(0.0); radius_b = Parameter(400.0, true); radius_b.set_min(0.0); contrast = Parameter(3.e-6); background = Parameter(0.0); axis_theta = Parameter(1.57, true); axis_phi = Parameter(0.0, true); } /** * Function to evaluate 1D scattering function * The NIST IGOR library is used for the actual calculation. * @param q: q-value * @return: function value */ double EllipsoidModel :: operator()(double q) { double dp[5]; // Fill parameter array for IGOR library // Add the background after averaging dp[0] = scale(); dp[1] = radius_a(); dp[2] = radius_b(); dp[3] = contrast(); dp[4] = 0.0; // Get the dispersion points for the radius_a vector weights_rad_a; radius_a.get_weights(weights_rad_a); // Get the dispersion points for the radius_b vector weights_rad_b; radius_b.get_weights(weights_rad_b); // Perform the computation, with all weight points double sum = 0.0; double norm = 0.0; // Loop over radius_a weight points for(int i=0; i weights_rad_a; radius_a.get_weights(weights_rad_a); // Get the dispersion points for the radius_b vector weights_rad_b; radius_b.get_weights(weights_rad_b); // Get angular averaging for theta vector weights_theta; axis_theta.get_weights(weights_theta); // Get angular averaging for phi vector weights_phi; axis_phi.get_weights(weights_phi); // Perform the computation, with all weight points double sum = 0.0; double norm = 0.0; // Loop over radius weight points for(int i=0; i1) { _ptvalue *= sin(weights_theta[k].value); } sum += _ptvalue; norm += weights_rad_a[i].weight * weights_rad_b[j].weight * weights_theta[k].weight * weights_phi[l].weight; } } } } // Averaging in theta needs an extra normalization // factor to account for the sin(theta) term in the // integration (see documentation). if (weights_theta.size()>1) norm = norm / asin(1.0); return sum/norm + background(); } /** * Function to evaluate 2D scattering function * @param pars: parameters of the cylinder * @param q: q-value * @param phi: angle phi * @return: function value */ double EllipsoidModel :: evaluate_rphi(double q, double phi) { double qx = q*cos(phi); double qy = q*sin(phi); return (*this).operator()(qx, qy); }