Changeset a4280bd in sasmodels for sasmodels/kernel_iq.c
- 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.c
r7b7da6b ra4280bd 34 34 35 35 36 #ifdef MAGNETIC 36 #if defined(MAGNETIC) && NUM_MAGNETIC>0 37 37 38 // Return value restricted between low and high 38 39 static double clip(double value, double low, double high) … … 47 48 // ud * (m_sigma_y + 1j*m_sigma_z); 48 49 // du * (m_sigma_y - 1j*m_sigma_z); 49 static void spins(double in_spin, double out_spin, 50 double *uu, double *dd, double *ud, double *du) 50 static void set_spins(double in_spin, double out_spin, double spins[4]) 51 51 { 52 52 in_spin = clip(in_spin, 0.0, 1.0); 53 53 out_spin = clip(out_spin, 0.0, 1.0); 54 *uu = sqrt(sqrt(in_spin * out_spin)); 55 *dd = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin))); 56 *ud = sqrt(sqrt(in_spin * (1.0-out_spin))); 57 *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; 58 65 } 59 66 … … 78 85 double *pvec = (double *)&local_values; 79 86 80 #if def MAGNETIC87 #if defined(MAGNETIC) && NUM_MAGNETIC>0 81 88 // Location of the sld parameters in the parameter pvec. 82 89 // These parameters are updated with the effective sld due to magnetism. 90 #if NUM_MAGNETIC > 3 83 91 const int32_t slds[] = { MAGNETIC_PARS }; 84 85 const double up_frac_i = values[NPARS+2]; 86 const double up_frac_f = values[NPARS+3]; 87 const double up_angle = values[NPARS+4]; 88 #define MX(_k) (values[NPARS+5+3*_k]) 89 #define MY(_k) (values[NPARS+6+3*_k]) 90 #define MZ(_k) (values[NPARS+7+3*_k]) 92 #endif 91 93 92 94 // TODO: could precompute these outside of the kernel. 93 95 // Interpret polarization cross section. 94 double uu, dd, ud, du; 96 // up_frac_i = values[NUM_PARS+2]; 97 // up_frac_f = values[NUM_PARS+3]; 98 // up_angle = values[NUM_PARS+4]; 99 double spins[4]; 95 100 double cos_mspin, sin_mspin; 96 s pins(up_frac_i, up_frac_f, &uu, &dd, &ud, &du);97 SINCOS(- up_angle*M_PI_180, sin_mspin, cos_mspin);101 set_spins(values[NUM_PARS+2], values[NUM_PARS+3], spins); 102 SINCOS(-values[NUM_PARS+4]*M_PI_180, sin_mspin, cos_mspin); 98 103 #endif // MAGNETIC 99 104 … … 104 109 #pragma omp parallel for 105 110 #endif 106 for (int i=0; i < N PARS; i++) {111 for (int i=0; i < NUM_PARS; i++) { 107 112 pvec[i] = values[2+i]; 108 113 //printf("p%d = %g\n",i, pvec[i]); … … 228 233 #endif 229 234 230 //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");235 //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"); 231 236 //printf("sphcor: %g\n", spherical_correction); 232 237 … … 247 252 #endif 248 253 for (int q_index=0; q_index<nq; q_index++) { 249 #if def MAGNETIC254 #if defined(MAGNETIC) && NUM_MAGNETIC > 0 250 255 const double qx = q[2*q_index]; 251 256 const double qy = q[2*q_index+1]; … … 253 258 254 259 // Constant across orientation, polydispersity for given qx, qy 255 double px, py, pz; 260 double scattering = 0.0; 261 // TODO: what is the magnetic scattering at q=0 256 262 if (qsq > 1.e-16) { 257 px = (qy*cos_mspin + qx*sin_mspin)/qsq; 258 py = (qy*sin_mspin - qx*cos_mspin)/qsq; 259 pz = 1.0; 260 } else { 261 px = py = pz = 0.0; 262 } 263 264 double scattering = 0.0; 265 if (uu > 1.e-8) { 266 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 267 const double perp = (qy*MX(sk) - qx*MY(sk)); 268 pvec[slds[sk]] = (values[slds[sk]+2] - perp*px)*uu; 263 double p[4]; 264 p[0] = (qy*cos_mspin + qx*sin_mspin)/qsq; 265 p[3] = -p[0]; 266 p[1] = p[2] = (qy*sin_mspin - qx*cos_mspin)/qsq; 267 268 for (int index=0; index<4; index++) { 269 const double xs = spins[index]; 270 if (xs > 1.e-8) { 271 const int spin_flip = (index==1) || (index==2); 272 const double pk = p[index]; 273 for (int axis=0; axis<=spin_flip; axis++) { 274 #define M1 NUM_PARS+5 275 #define M2 NUM_PARS+8 276 #define M3 NUM_PARS+13 277 #define SLD(_M_offset, _sld_offset) \ 278 pvec[_sld_offset] = xs * (axis \ 279 ? (index==1 ? -values[_M_offset+2] : values[_M_offset+2]) \ 280 : mag_sld(qx, qy, pk, values[_M_offset], values[_M_offset+1], \ 281 (spin_flip ? 0.0 : values[_sld_offset+2]))) 282 #if NUM_MAGNETIC==1 283 SLD(M1, MAGNETIC_PAR1); 284 #elif NUM_MAGNETIC==2 285 SLD(M1, MAGNETIC_PAR1); 286 SLD(M2, MAGNETIC_PAR2); 287 #elif NUM_MAGNETIC==3 288 SLD(M1, MAGNETIC_PAR1); 289 SLD(M2, MAGNETIC_PAR2); 290 SLD(M3, MAGNETIC_PAR3); 291 #else 292 for (int sk=0; sk<NUM_MAGNETIC; sk++) { 293 SLD(M1+3*sk, slds[sk]); 294 } 295 #endif 296 scattering += CALL_IQ(q, q_index, local_values); 297 } 298 } 269 299 } 270 scattering += CALL_IQ(q, q_index, local_values);271 }272 if (dd > 1.e-8){273 for (int sk=0; sk<NUM_MAGNETIC; sk++) {274 const double perp = (qy*MX(sk) - qx*MY(sk));275 pvec[slds[sk]] = (values[slds[sk]+2] + perp*px)*dd;276 }277 scattering += CALL_IQ(q, q_index, local_values);278 }279 if (ud > 1.e-8){280 for (int sk=0; sk<NUM_MAGNETIC; sk++) {281 const double perp = (qy*MX(sk) - qx*MY(sk));282 pvec[slds[sk]] = perp*py*ud;283 }284 scattering += CALL_IQ(q, q_index, local_values);285 for (int sk=0; sk<NUM_MAGNETIC; sk++) {286 pvec[slds[sk]] = MZ(sk)*pz*ud;287 }288 scattering += CALL_IQ(q, q_index, local_values);289 }290 if (du > 1.e-8) {291 for (int sk=0; sk<NUM_MAGNETIC; sk++) {292 const double perp = (qy*MX(sk) - qx*MY(sk));293 pvec[slds[sk]] = perp*py*du;294 }295 scattering += CALL_IQ(q, q_index, local_values);296 for (int sk=0; sk<NUM_MAGNETIC; sk++) {297 pvec[slds[sk]] = -MZ(sk)*pz*du;298 }299 scattering += CALL_IQ(q, q_index, local_values);300 300 } 301 301 #else // !MAGNETIC
Note: See TracChangeset
for help on using the changeset viewer.