Changeset f2f67a6 in sasmodels for sasmodels/kernel_iq.c
- Timestamp:
- Apr 15, 2016 7:26:24 PM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- ae2b6b5, 38a9b07, eb97b11
- Parents:
- 0ff62d4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernel_iq.c
r6e7ff6d rf2f67a6 54 54 local ParameterBlock local_values; // current parameter values 55 55 double *pvec = (double *)(&local_values); // Alias named parameters with a vector 56 double norm; 57 58 // number of active loops 59 const int num_active = details->num_active; 56 60 57 61 // Fill in the initial variables … … 63 67 } 64 68 69 // Monodisperse computation 70 if (num_active == 0) { 71 #ifdef INVALID 72 if (INVALID(local_values)) { return; } 73 #endif 74 norm = CALL_VOLUME(local_values); 75 76 const double scale = values[0]; 77 const double background = values[1]; 78 // result[nq] = norm; // Total volume normalization 79 80 #ifdef USE_OPENMP 81 #pragma omp parallel for 82 #endif 83 for (int i=0; i < nq; i++) { 84 double scattering = CALL_IQ(q, i, local_values); 85 result[i] = (norm>0. ? scale*scattering/norm + background : background); 86 } 87 return; 88 } 89 90 #if MAX_PD > 0 65 91 // If it is the first round initialize the result to zero, otherwise 66 92 // assume that the previous result has been passed back. … … 75 101 result[i] = 0.0; 76 102 } 77 } 78 79 // Monodisperse computation 80 if (details->num_active == 0) { 81 #ifdef INVALID 82 if (INVALID(local_values)) { return; } 83 #endif 84 85 const double norm = CALL_VOLUME(local_values); 86 const double scale = values[0]; 87 const double background = values[1]; 88 #ifdef USE_OPENMP 89 #pragma omp parallel for 90 #endif 91 result[nq] = norm; // Total volume normalization 92 for (int i=0; i < nq; i++) { 93 double scattering = CALL_IQ(q, i, local_values); 94 result[i] = (norm>0. ? scale*scattering/norm + background : background); 95 } 96 return; 97 } 98 99 #if MAX_PD > 0 100 //printf("Entering polydispersity from %d to %d\n", pd_start, pd_stop); 101 // Since we are no longer looping over the entire polydispersity hypercube 102 // for each q, we need to track the normalization values between calls. 103 double norm = 0.0; 103 norm = 0.0; 104 } else { 105 norm = result[nq]; 106 } 104 107 105 108 // need product of weights at every Iq calc, so keep product of … … 119 122 pd_index[0] = fast_length; 120 123 124 // Number of coordinated indices 125 const int num_coord = details->num_coord; 126 121 127 // Loop over the weights then loop over q, accumulating values 122 128 for (int loop_index=pd_start; loop_index < pd_stop; loop_index++) { 123 // check if indices need to be updated129 // check if fast loop needs to be reset 124 130 if (pd_index[0] == fast_length) { 125 //printf("should be here with %d active\n", details->num_active);131 //printf("should be here with %d active\n", num_active); 126 132 127 133 // Compute position in polydispersity hypercube 128 for (int k=0; k < details->num_active; k++) {134 for (int k=0; k < num_active; k++) { 129 135 pd_index[k] = (loop_index/details->pd_stride[k])%details->pd_length[k]; 130 136 //printf("pd_index[%d] = %d\n",k,pd_index[k]); … … 134 140 partial_weight = 1.0; 135 141 //printf("partial weight %d: ", loop_index); 136 for (int k=1; k < details->num_active; k++) {142 for (int k=1; k < num_active; k++) { 137 143 double wi = weights[details->pd_offset[k] + pd_index[k]]; 138 144 //printf("pd[%d]=par[%d]=%g ", k, details->pd_par[k], wi); … … 143 149 // Update parameter offsets in weight vector 144 150 //printf("slow %d: ", loop_index); 145 for (int k=0; k < details->num_coord; k++) {151 for (int k=0; k < num_coord; k++) { 146 152 int par = details->par_coord[k]; 147 153 int coord = details->pd_coord[k]; … … 160 166 // if theta is not coordinated with fast index, precompute spherical correction 161 167 if (par == details->theta_par && !(details->par_coord[k]&1)) { 162 spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1 e-6);168 spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1.e-6); 163 169 } 164 170 } … … 170 176 double weight = partial_weight*wi; 171 177 //printf("fast %d: ", loop_index); 172 for (int k=0; k < details->num_coord; k++) {178 for (int k=0; k < num_coord; k++) { 173 179 if (details->pd_coord[k]&1) { 174 180 const int par = details->par_coord[k]; … … 177 183 // if theta is coordinated with fast index, compute spherical correction each time 178 184 if (par == details->theta_par) { 179 spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1 e-6);185 spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1.e-6); 180 186 } 181 187 } … … 205 211 } 206 212 207 // Accumulate norm.208 result[nq] += norm;209 210 213 // End of the PD loop we can normalize 211 214 if (pd_stop >= details->total_pd) { … … 219 222 } 220 223 } 224 225 // Remember the updated norm. 226 result[nq] = norm; 221 227 #endif // MAX_PD > 0 222 228 }
Note: See TracChangeset
for help on using the changeset viewer.