Changeset 54b0650 in sasview for src/sas/sascalc/calculator/c_extensions
- Timestamp:
- Nov 7, 2017 1:05:12 PM (7 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- f926abb
- Parents:
- 0957bb3a
- Location:
- src/sas/sascalc/calculator/c_extensions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/c_extensions/sld2i.c
r0957bb3a r54b0650 25 25 * @param s_theta: angle (from x-axis) of the up spin in degree 26 26 */ 27 void initGenI(GenI* this, int npix, double* x, double* y, double* z, double* sldn,27 void initGenI(GenI* this, int is_avg, int npix, double* x, double* y, double* z, double* sldn, 28 28 double* mx, double* my, double* mz, double* voli, 29 29 double in_spin, double out_spin, 30 30 double s_theta) { 31 this->is_avg = is_avg; 31 32 this->n_pix = npix; 32 33 this->x_val = x; … … 73 74 // Loop over q-values and multiply apply matrix 74 75 76 //printf("npoints: %d, npix: %d\n", npoints, this->n_pix); 75 77 for(int i=0; i<npoints; i++){ 76 78 //I_out[i] = 0.0; … … 150 152 // Assumes that q doesn't have qz component and sld_n is all real 151 153 //double Pi = 4.0*atan(1.0); 152 int is_sym = this->n_pix < 0;153 154 double qr = 0.0; 154 155 double sumj; 155 156 double sld_j = 0.0; 156 157 double count = 0.0; 157 int n_pix = is_sym ? -this->n_pix : this->n_pix;158 158 //Assume that pixel volumes are given in vol_pix in A^3 unit 159 159 // Loop over q-values and multiply apply matrix 160 160 for(int i=0; i<npoints; i++){ 161 161 sumj =0.0; 162 for(int j=0; j< n_pix; j++){162 for(int j=0; j<this->n_pix; j++){ 163 163 //Isotropic: Assumes all slds are real (no magnetic) 164 164 //Also assumes there is no polarization: No dependency on spin 165 if ( is_sym== 1){165 if (this->is_avg == 1){ 166 166 // approximation for a spherical symmetric particle 167 167 qr = sqrt(this->x_val[j]*this->x_val[j]+this->y_val[j]*this->y_val[j]+this->z_val[j]*this->z_val[j])*q[i]; … … 177 177 //full calculation 178 178 //pragma omp parallel for 179 for(int k=0; k< n_pix; k++){179 for(int k=0; k<this->n_pix; k++){ 180 180 sld_j = this->sldn_val[j] * this->sldn_val[k] * this->vol_pix[j] * this->vol_pix[k]; 181 181 qr = (this->x_val[j]-this->x_val[k])*(this->x_val[j]-this->x_val[k])+ … … 196 196 } 197 197 I_out[i] = sumj; 198 if ( is_sym == 1){198 if (this->is_avg == 1) { 199 199 I_out[i] *= sumj; 200 200 } -
src/sas/sascalc/calculator/c_extensions/sld2i.h
r0957bb3a r54b0650 10 10 typedef struct { 11 11 // vectors 12 int is_avg; 12 13 int n_pix; 13 14 double* x_val; … … 26 27 27 28 // Constructor 28 void initGenI(GenI*, int npix, double* x, double* y, double* z, double* sldn,29 double* mx, double* my, double* mz, double* voli,29 void initGenI(GenI*, int is_avg, int npix, double* x, double* y, double* z, 30 double* sldn, double* mx, double* my, double* mz, double* voli, 30 31 double in_spin, double out_spin, 31 32 double s_theta); -
src/sas/sascalc/calculator/c_extensions/sld2i_module.c
r0957bb3a r54b0650 35 35 void 36 36 del_sld2i(PyObject *obj){ 37 #if PY_MAJOR_VERSION < 3 38 GenI* sld2i = (GenI *)obj; 39 #else 37 40 GenI* sld2i = (GenI *)(PyCapsule_GetPointer(obj, "GenI")); 41 #endif 38 42 PyMem_Free((void *)sld2i); 39 43 } … … 51 55 PyObject *mz_val_obj; 52 56 PyObject *vol_pix_obj; 53 Py_ssize_t n_x; 54 //PyObject rlimit_obj; 55 //PyObject npoints_obj; 56 //PyObject nrbins_obj; 57 //PyObject nphibins_obj; 58 int n_pix; 57 Py_ssize_t n_x, n_y, n_z, n_sld, n_mx, n_my, n_mz, n_vol_pix; 58 int is_avg; 59 59 double* x_val; 60 60 double* y_val; … … 69 69 double stheta; 70 70 71 if (!PyArg_ParseTuple(args, "iOOOOOOOOddd", &n_pix, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &vol_pix_obj, &inspin, &outspin, &stheta)) return NULL; 72 OUTVECTOR(x_val_obj, x_val, n_x); 73 OUTVECTOR(y_val_obj, y_val, n_x); 74 OUTVECTOR(z_val_obj, z_val, n_x); 75 OUTVECTOR(sldn_val_obj, sldn_val, n_x); 76 OUTVECTOR(mx_val_obj, mx_val, n_x); 77 OUTVECTOR(my_val_obj, my_val, n_x); 78 OUTVECTOR(mz_val_obj, mz_val, n_x); 79 OUTVECTOR(vol_pix_obj, vol_pix, n_x); 80 GenI* sld2i = PyMem_Malloc(sizeof(GenI)); 71 if (!PyArg_ParseTuple(args, "iOOOOOOOOddd", &is_avg, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &vol_pix_obj, &inspin, &outspin, &stheta)) return NULL; 72 INVECTOR(x_val_obj, x_val, n_x); 73 INVECTOR(y_val_obj, y_val, n_y); 74 INVECTOR(z_val_obj, z_val, n_z); 75 INVECTOR(sldn_val_obj, sldn_val, n_sld); 76 INVECTOR(mx_val_obj, mx_val, n_mx); 77 INVECTOR(my_val_obj, my_val, n_my); 78 INVECTOR(mz_val_obj, mz_val, n_mz); 79 INVECTOR(vol_pix_obj, vol_pix, n_vol_pix); 80 GenI* sld2i = PyMem_Malloc(sizeof(GenI)); 81 //printf("sldi:%p\n", sld2i); 81 82 if (sld2i != NULL) { 82 initGenI(sld2i, n_pix,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,vol_pix,inspin,outspin,stheta);83 initGenI(sld2i,is_avg,n_x,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,vol_pix,inspin,outspin,stheta); 83 84 } 84 return PyCapsule_New(sld2i, "GenI", del_sld2i); 85 PyObject *obj = PyCapsule_New(sld2i, "GenI", del_sld2i); 86 //printf("constructed %p\n", obj); 87 return obj; 85 88 } 86 89 … … 89 92 */ 90 93 PyObject * genicom_inputXY(PyObject *self, PyObject *args) { 91 int npoints;94 PyObject *gen_obj; 92 95 PyObject *qx_obj; 96 PyObject *qy_obj; 97 PyObject *I_out_obj; 98 Py_ssize_t n_qx, n_qy, n_out; 93 99 double *qx; 94 PyObject *qy_obj;95 100 double *qy; 96 PyObject *I_out_obj;97 Py_ssize_t n_out;98 101 double *I_out; 99 PyObject *gen_obj;100 102 101 if (!PyArg_ParseTuple(args, "OiOOO", &gen_obj, &npoints, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 102 OUTVECTOR(qx_obj, qx, n_out); 103 OUTVECTOR(qy_obj, qy, n_out); 103 if (!PyArg_ParseTuple(args, "OOOO", &gen_obj, &qx_obj, &qy_obj, &I_out_obj)) return NULL; 104 GenI* sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 105 INVECTOR(qx_obj, qx, n_qx); 106 INVECTOR(qy_obj, qy, n_qy); 104 107 OUTVECTOR(I_out_obj, I_out, n_out); 105 108 106 109 // Sanity check 107 //if(n_ in!=n_out) return Py_BuildValue("i",-1);110 //if(n_q!=n_out) return Py_BuildValue("i",-1); 108 111 109 // Set the array pointers 110 GenI* sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 111 112 genicomXY(sld2i, npoints, qx, qy, I_out); 112 genicomXY(sld2i, n_qx, qx, qy, I_out); 113 113 //return PyCObject_FromVoidPtr(s, del_genicom); 114 114 return Py_BuildValue("i",1); … … 119 119 */ 120 120 PyObject * genicom_input(PyObject *self, PyObject *args) { 121 int npoints;121 PyObject *gen_obj; 122 122 PyObject *q_obj; 123 PyObject *I_out_obj; 124 Py_ssize_t n_q, n_out; 123 125 double *q; 124 PyObject *I_out_obj;125 Py_ssize_t n_out;126 126 double *I_out; 127 PyObject *gen_obj;128 127 129 if (!PyArg_ParseTuple(args, "OiOO", &gen_obj, &npoints, &q_obj, &I_out_obj)) return NULL; 130 OUTVECTOR(q_obj, q, n_out); 128 if (!PyArg_ParseTuple(args, "OOO", &gen_obj, &q_obj, &I_out_obj)) return NULL; 129 GenI *sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 130 INVECTOR(q_obj, q, n_q); 131 131 OUTVECTOR(I_out_obj, I_out, n_out); 132 132 133 133 // Sanity check 134 //if (n_in!=n_out) return Py_BuildValue("i",-1);134 //if (n_q!=n_out) return Py_BuildValue("i",-1); 135 135 136 // Set the array pointers 137 GenI *sld2i = (GenI *)PyCapsule_GetPointer(gen_obj, "GenI"); 138 139 genicom(sld2i, npoints, q, I_out); 140 //return PyCObject_FromVoidPtr(s, del_genicom); 136 genicom(sld2i, n_q, q, I_out); 141 137 return Py_BuildValue("i",1); 142 138 }
Note: See TracChangeset
for help on using the changeset viewer.