source: sasview/sansmodels/src/c_models/coresecondmoment.cpp @ 08648c0

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 08648c0 was 7289627, checked in by Jae Cho <jhjcho@…>, 13 years ago

change core2ndmoment model name and added the help doc

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * Scattering model classes
3 *
4 */
5
6#include <math.h>
7#include "parameters.hh"
8#include <stdio.h>
9using namespace std;
10#include "coresecondmoment.h"
11
12static double core_secondmoment_kernel(double dp[], double q) {
13  //fit parameters
14  double scale = dp[0];
15  double density_poly = dp[1];
16  double sld_poly = dp[2];
17  double radius_core = dp[3];
18  double volf_cores = dp[4];
19  double ads_amount = dp[5];
20  double second_moment = dp[6];
21  double sld_solv = dp[7];
22  double background = dp[8];
23  // Not valid for very small r
24  if (radius_core < 0.001){
25          return 0.0;
26  }
27  //others
28  double form_factor = 0.0;
29  double x_val = 0.0;
30  //Pi
31  double pi = 4.0 * atan(1.0);
32  //relative sld
33  double contrast = sld_poly - sld_solv;
34  //x for exp
35  x_val = q*second_moment;
36  x_val *= x_val;
37  //computation
38  form_factor = contrast * ads_amount;
39  form_factor /= (q * density_poly);
40  form_factor *= form_factor;
41  form_factor *= (6.0 * pi * volf_cores * 1.0e+10);
42  form_factor /= radius_core;
43  form_factor *= exp(-x_val);
44
45  // scale and background
46  form_factor *= scale;
47  form_factor += background;
48  return (form_factor);
49}
50
51Core2ndMomentModel :: Core2ndMomentModel() {
52        scale = Parameter(1.0);
53        density_poly = Parameter(0.7);
54        sld_poly = Parameter(1.5e-6);
55        radius_core = Parameter(500.0, true);
56        radius_core.set_min(0.0);
57        volf_cores = Parameter(0.14);
58        ads_amount = Parameter(1.9);
59        second_moment = Parameter(23.0);
60        sld_solv   = Parameter(6.3e-6);
61        background = Parameter(0.0);
62}
63
64/**
65 * Function to evaluate 1D scattering function
66 * @param q: q-value
67 * @return: function value
68 */
69double Core2ndMomentModel :: operator()(double q) {
70        double dp[9];
71
72        // Add the background after averaging
73        dp[0] = scale();
74        dp[1] = density_poly();
75        dp[2] = sld_poly();
76        dp[3] = radius_core();
77        dp[4] = volf_cores();
78        dp[5] = ads_amount();
79        dp[6] = second_moment();
80        dp[7] = sld_solv();
81        dp[8] = 0.0;
82
83        // Get the dispersion points for the radius
84        vector<WeightPoint> weights_rad;
85        radius_core.get_weights(weights_rad);
86
87        // Perform the computation, with all weight points
88        double sum = 0.0;
89        double norm = 0.0;
90
91        // Loop over radius weight points
92        for(size_t i=0; i<weights_rad.size(); i++) {
93                dp[3] = weights_rad[i].value;
94                //weighted sum
95                sum += weights_rad[i].weight
96                        * core_secondmoment_kernel(dp, q);
97                norm += weights_rad[i].weight;
98        }
99        return sum/norm + background();
100}
101
102/**
103 * Function to evaluate 2D scattering function
104 * @param q_x: value of Q along x
105 * @param q_y: value of Q along y
106 * @return: function value
107 */
108double Core2ndMomentModel :: operator()(double qx, double qy) {
109        double q = sqrt(qx*qx + qy*qy);
110        return (*this).operator()(q);
111}
112
113/**
114 * Function to evaluate 2D scattering function
115 * @param pars: parameters of the sphere
116 * @param q: q-value
117 * @param phi: angle phi
118 * @return: function value
119 */
120double Core2ndMomentModel :: evaluate_rphi(double q, double phi) {
121        return (*this).operator()(q);
122}
123
124/**
125 * Function to calculate effective radius
126 * @return: effective radius value
127 */
128double Core2ndMomentModel :: calculate_ER() {
129        return 0.0;
130}
Note: See TracBrowser for help on using the repository browser.