source: sasview/sansmodels/src/c_gen/sld2i.cpp @ 5917637

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 5917637 was 5917637, checked in by Jae Cho <jhjcho@…>, 11 years ago

minor corrections

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/**
2Computes the (magnetic) scattering form sld (n and m) profile
3 */
4#include "sld2i.hh"
5#include <stdio.h>
6#include <math.h>
7using namespace std;
8extern "C" {
9        #include "libmultifunc/libfunc.h"
10        #include "libmultifunc/librefl.h"
11}
12/**
13 * Constructor for GenI
14 *
15 * binning
16 * //@param qx: array of Qx values
17 * //@param qy: array of Qy values
18 * //@param qz: array of Qz values
19 * @param x: array of x values
20 * @param y: array of y values
21 * @param z: array of z values
22 * @param sldn: array of sld n
23 * @param mx: array of sld mx
24 * @param my: array of sld my
25 * @param mz: array of sld mz
26 * @param in_spin: ratio of up spin in Iin
27 * @param out_spin: ratio of up spin in Iout
28 * @param s_theta: angle (from x-axis) of the up spin in degree
29 */
30GenI :: GenI(int npix, double* x, double* y, double* z, double* sldn,
31                        double* mx, double* my, double* mz, double* voli,
32                        double in_spin, double out_spin,
33                        double s_theta) {
34        //this->qx_val = qx;
35        //this->qy_val = qy;
36        //this->qz_val = qz;
37        this->n_pix = npix;
38        this->x_val = x;
39        this->y_val = y;
40        this->z_val = z;
41        this->sldn_val = sldn;
42        this->mx_val = mx;
43        this->my_val = my;
44        this->mz_val = mz;
45        this->vol_pix = voli;
46        this->inspin = in_spin;
47        this->outspin = out_spin;
48        this->stheta = s_theta;
49};
50
51/**
52 * Compute
53 */
54void GenI :: genicom(int npoints, double *qx, double *qy, double *I_out){
55        //npoints is given negative for angular averaging
56        // Assumes that q doesn't have qz component and sld_n is all real
57        double q = 0.0;
58        int is_avg = 0;
59        //double Pi = 4.0*atan(1.0);
60        polar_sld b_sld;
61        double qr = 0.0;
62        complex iqr = cassign(0.0, 0.0);
63        complex ephase = cassign(0.0, 0.0);
64        complex comp_sld = cassign(0.0, 0.0);
65        complex sumj;
66        complex sumj_uu;
67        complex sumj_ud;
68        complex sumj_du;
69        complex sumj_dd;
70        complex temp_fi;
71
72        double count = 0.0;
73        //check if this computation is for averaging
74        if (n_pix < 0 ){
75                is_avg = 1;
76                n_pix = fabs(n_pix);
77        }
78        //Assume that pixel volumes are given in vol_pix in A^3 unit
79        //int x_size = 0; //in Ang
80        //int y_size = 0; //in Ang
81        //int z_size = 0; //in Ang
82        // Loop over q-values and multiply apply matrix
83
84        for(int i=0; i<npoints; i++){
85                //I_out[i] = 0.0;
86                sumj = cassign(0.0, 0.0);
87                sumj_uu = cassign(0.0, 0.0);
88                sumj_ud = cassign(0.0, 0.0);
89                sumj_du = cassign(0.0, 0.0);
90                sumj_dd = cassign(0.0, 0.0);           
91                //printf ("%d ", i);
92                q = sqrt(qx[i]*qx[i] + qy[i]*qy[i]); // + qz[i]*qz[i]);
93
94                for(int j=0; j<n_pix; j++){
95                       
96                        if (sldn_val[j]!=0.0||mx_val[j]!=0.0||my_val[j]!=0.0||mz_val[j]!=0.0)
97                        {       
98                                temp_fi = cassign(0.0, 0.0);
99                                b_sld = cal_msld(0, qx[i], qy[i], sldn_val[j],
100                                                                 mx_val[j], my_val[j], mz_val[j],
101                                                                 inspin, outspin, stheta);
102                                if (is_avg < 1){
103                                        //anisotropic
104                                        qr = (qx[i]*x_val[j] + qy[i]*y_val[j]);
105                                        iqr = cassign(0.0, qr);
106                                        ephase = cplx_exp(iqr);
107                                        }
108                                else{
109                                        //isotropic
110                                        qr = sqrt(x_val[j]*x_val[j]+y_val[j]*y_val[j]+z_val[j]*z_val[j]);
111                                        qr *= q;
112                                        if (qr == 0.0){
113                                                ephase = cassign(0.0, 1.0);
114                                                }
115                                        else{
116                                                qr = sin(qr) / qr;
117                                                ephase = cassign(qr, 0.0);
118                                                }
119                                        }
120                                //Let's multiply pixel(atomic) volume here
121                                ephase = rcmult(vol_pix[j], ephase);
122                                //up_up
123                                if (inspin > 0.0 && outspin > 0.0){
124                                        comp_sld = cassign(b_sld.uu, 0.0);
125                                        temp_fi = cplx_mult(comp_sld, ephase);
126                                        sumj_uu = cplx_add(sumj_uu, temp_fi);
127                                        }
128                                //down_down
129                                if (inspin < 1.0 && outspin < 1.0){
130                                        comp_sld = cassign(b_sld.dd, 0.0);
131                                        temp_fi = cplx_mult(comp_sld, ephase);
132                                        sumj_dd = cplx_add(sumj_dd, temp_fi);
133                                        }
134                                //up_down
135                                if (inspin > 0.0 && outspin < 1.0){
136                                        comp_sld = cassign(b_sld.re_ud, b_sld.im_ud);
137                                        temp_fi = cplx_mult(comp_sld, ephase);
138                                        sumj_ud = cplx_add(sumj_ud, temp_fi);
139                                        }
140                                //down_up
141                                if (inspin < 1.0 && outspin > 0.0){
142                                        comp_sld = cassign(b_sld.re_du, b_sld.im_du);
143                                        temp_fi = cplx_mult(comp_sld, ephase);
144                                        sumj_du = cplx_add(sumj_du, temp_fi);
145                                        }
146                                if (i == 0){
147                                        count += vol_pix[j];
148                                }
149                        }
150                }
151                //printf("aa%d=%g %g %d\n", i, (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im), (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im), count);
152                I_out[i] = (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im);
153                I_out[i] += (sumj_ud.re*sumj_ud.re + sumj_ud.im*sumj_ud.im);
154                I_out[i] += (sumj_du.re*sumj_du.re + sumj_du.im*sumj_du.im);
155                I_out[i] += (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im);
156                I_out[i] *= (1.0E+8 / count); //in cm (unit) / number; //to be multiplied by vol_pix
157        }
158        //printf ("count = %d %g %g %g %g\n", count, sldn_val[0],mx_val[0], my_val[0], mz_val[0]);
159}
Note: See TracBrowser for help on using the repository browser.