Changeset a4280bd in sasmodels for sasmodels/kernel_iq.cl
- Timestamp:
- Jul 25, 2016 11:54:30 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:
- 2f5c6d4
- Parents:
- 2c74c11
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernel_iq.cl
r7b7da6b ra4280bd 34 34 35 35 36 #if def MAGNETIC36 #if defined(MAGNETIC) && NUM_MAGNETIC>0 37 37 38 38 // Return value restricted between low and high … … 48 48 // ud * (m_sigma_y + 1j*m_sigma_z); 49 49 // du * (m_sigma_y - 1j*m_sigma_z); 50 static void spins(double in_spin, double out_spin, 51 double *uu, double *dd, double *ud, double *du) 50 static void set_spins(double in_spin, double out_spin, double spins[4]) 52 51 { 53 52 in_spin = clip(in_spin, 0.0, 1.0); 54 53 out_spin = clip(out_spin, 0.0, 1.0); 55 *uu = sqrt(sqrt(in_spin * out_spin)); 56 *dd = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin))); 57 *ud = sqrt(sqrt(in_spin * (1.0-out_spin))); 58 *du = sqrt(sqrt((1.0-in_spin) * out_spin)); 54 spins[0] = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin))); // dd 55 spins[1] = sqrt(sqrt((1.0-in_spin) * out_spin)); // du 56 spins[2] = sqrt(sqrt(in_spin * (1.0-out_spin))); // ud 57 spins[3] = sqrt(sqrt(in_spin * out_spin)); // uu 58 } 59 60 static double mag_sld(double qx, double qy, double p, 61 double mx, double my, double sld) 62 { 63 const double perp = qy*mx - qx*my; 64 return sld + perp*p; 59 65 } 60 66 … … 84 90 85 91 // Fill in the initial variables 86 for (int i=0; i < N PARS; i++) {92 for (int i=0; i < NUM_PARS; i++) { 87 93 pvec[i] = values[2+i]; 88 94 //if (q_index==0) printf("p%d = %g\n",i, pvec[i]); 89 95 } 90 96 91 #if def MAGNETIC97 #if defined(MAGNETIC) && NUM_MAGNETIC>0 92 98 // Location of the sld parameters in the parameter pvec. 93 99 // These parameters are updated with the effective sld due to magnetism. 100 #if NUM_MAGNETIC > 3 94 101 const int32_t slds[] = { MAGNETIC_PARS }; 95 96 const double up_frac_i = values[NPARS+2]; 97 const double up_frac_f = values[NPARS+3]; 98 const double up_angle = values[NPARS+4]; 99 #define MX(_k) (values[NPARS+5+3*_k]) 100 #define MY(_k) (values[NPARS+6+3*_k]) 101 #define MZ(_k) (values[NPARS+7+3*_k]) 102 #endif 102 103 103 104 // TODO: could precompute these outside of the kernel. 104 105 // Interpret polarization cross section. 105 double uu, dd, ud, du; 106 // up_frac_i = values[NUM_PARS+2]; 107 // up_frac_f = values[NUM_PARS+3]; 108 // up_angle = values[NUM_PARS+4]; 109 double spins[4]; 106 110 double cos_mspin, sin_mspin; 107 s pins(up_frac_i, up_frac_f, &uu, &dd, &ud, &du);108 SINCOS(- up_angle*M_PI_180, sin_mspin, cos_mspin);111 set_spins(values[NUM_PARS+2], values[NUM_PARS+3], spins); 112 SINCOS(-values[NUM_PARS+4]*M_PI_180, sin_mspin, cos_mspin); 109 113 #endif // MAGNETIC 110 114 … … 222 226 #endif 223 227 224 //if (q_index == 0) {printf("step:%d of %d, pars:",step,pd_stop); for (int i=0; i < N PARS; i++) printf("p%d=%g ",i, pvec[i]); printf("\n"); }228 //if (q_index == 0) {printf("step:%d of %d, pars:",step,pd_stop); for (int i=0; i < NUM_PARS; i++) printf("p%d=%g ",i, pvec[i]); printf("\n"); } 225 229 //if (q_index == 0) printf("sphcor: %g\n", spherical_correction); 226 230 … … 237 241 pd_norm += weight * CALL_VOLUME(local_values); 238 242 239 #ifdef MAGNETIC 240 const double qx = q[2*q_index]; 241 const double qy = q[2*q_index+1]; 242 const double qsq = qx*qx + qy*qy; 243 244 // Constant across orientation, polydispersity for given qx, qy 245 double px, py, pz; 246 if (qsq > 1.e-16) { 247 px = (qy*cos_mspin + qx*sin_mspin)/qsq; 248 py = (qy*sin_mspin - qx*cos_mspin)/qsq; 249 pz = 1.0; 250 } else { 251 px = py = pz = 0.0; 243 #if defined(MAGNETIC) && NUM_MAGNETIC > 0 244 const double qx = q[2*q_index]; 245 const double qy = q[2*q_index+1]; 246 const double qsq = qx*qx + qy*qy; 247 248 // Constant across orientation, polydispersity for given qx, qy 249 double scattering = 0.0; 250 // TODO: what is the magnetic scattering at q=0 251 if (qsq > 1.e-16) { 252 double p[4]; // spin_i, spin_f 253 p[0] = (qy*cos_mspin + qx*sin_mspin)/qsq; 254 p[3] = -p[0]; 255 p[1] = p[2] = (qy*sin_mspin - qx*cos_mspin)/qsq; 256 257 for (int index=0; index<4; index++) { 258 const double xs = spins[index]; 259 if (xs > 1.e-8) { 260 const int spin_flip = (index==1) || (index==2); 261 const double pk = p[index]; 262 for (int axis=0; axis<=spin_flip; axis++) { 263 #define M1 NUM_PARS+5 264 #define M2 NUM_PARS+8 265 #define M3 NUM_PARS+13 266 #define SLD(_M_offset, _sld_offset) \ 267 pvec[_sld_offset] = xs * (axis \ 268 ? (index==1 ? -values[_M_offset+2] : values[_M_offset+2]) \ 269 : mag_sld(qx, qy, pk, values[_M_offset], values[_M_offset+1], \ 270 (spin_flip ? 0.0 : values[_sld_offset+2]))) 271 #if NUM_MAGNETIC==1 272 SLD(M1, MAGNETIC_PAR1); 273 #elif NUM_MAGNETIC==2 274 SLD(M1, MAGNETIC_PAR1); 275 SLD(M2, MAGNETIC_PAR2); 276 #elif NUM_MAGNETIC==3 277 SLD(M1, MAGNETIC_PAR1); 278 SLD(M2, MAGNETIC_PAR2); 279 SLD(M3, MAGNETIC_PAR3); 280 #else 281 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 282 SLD(M1+3*sk, slds[sk]); 283 } 284 #endif 285 scattering += CALL_IQ(q, q_index, local_values); 286 } 287 } 252 288 } 253 254 double scattering = 0.0; 255 if (uu > 1.e-8) { 256 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 257 const double perp = (qy*MX(sk) - qx*MY(sk)); 258 pvec[slds[sk]] = (values[slds[sk]+2] - perp*px)*uu; 259 } 260 scattering += CALL_IQ(q, q_index, local_values); 261 } 262 263 if (dd > 1.e-8){ 264 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 265 const double perp = (qy*MX(sk) - qx*MY(sk)); 266 pvec[slds[sk]] = (values[slds[sk]+2] + perp*px)*dd; 267 } 268 scattering += CALL_IQ(q, q_index, local_values); 269 } 270 if (ud > 1.e-8){ 271 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 272 const double perp = (qy*MX(sk) - qx*MY(sk)); 273 pvec[slds[sk]] = perp*py*ud; 274 } 275 scattering += CALL_IQ(q, q_index, local_values); 276 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 277 pvec[slds[sk]] = MZ(sk)*pz*ud; 278 } 279 scattering += CALL_IQ(q, q_index, local_values); 280 } 281 if (du > 1.e-8) { 282 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 283 const double perp = (qy*MX(sk) - qx*MY(sk)); 284 pvec[slds[sk]] = perp*py*du; 285 } 286 scattering += CALL_IQ(q, q_index, local_values); 287 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 288 pvec[slds[sk]] = -MZ(sk)*pz*du; 289 } 290 scattering += CALL_IQ(q, q_index, local_values); 291 } 289 } 292 290 #else // !MAGNETIC 293 291 const double scattering = CALL_IQ(q, q_index, local_values);
Note: See TracChangeset
for help on using the changeset viewer.