Changes in sasmodels/kernel_iq.c [c57ee9e:70530778] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernel_iq.c

    rc57ee9e r70530778  
    2727//      parameters in the parameter table. 
    2828//  CALL_VOLUME(table) : call the form volume function 
    29 //  CALL_EFFECTIVE_RADIUS(type, table) : call the R_eff function 
    3029//  CALL_IQ(q, table) : call the Iq function for 1D calcs. 
    3130//  CALL_IQ_A(q, table) : call the Iq function with |q| for 2D data. 
    32 //  CALL_FQ(q, F1, F2, table) : call the Fq function for 1D calcs. 
    33 //  CALL_FQ_A(q, F1, F2, table) : call the Iq function with |q| for 2D data. 
    3431//  CALL_IQ_AC(qa, qc, table) : call the Iqxy function for symmetric shapes 
    3532//  CALL_IQ_ABC(qa, qc, table) : call the Iqxy function for asymmetric shapes 
     
    3936//  PROJECTION : equirectangular=1, sinusoidal=2 
    4037//      see explore/jitter.py for definitions. 
    41  
    4238 
    4339#ifndef _PAR_BLOCK_ // protected block so we can include this code twice. 
     
    192188    QACRotation *rotation, 
    193189    double qx, double qy, 
    194     double *qa_out, double *qc_out) 
     190    double *qab_out, double *qc_out) 
    195191{ 
     192    // Indirect calculation of qab, from qab^2 = |q|^2 - qc^2 
    196193    const double dqc = rotation->R31*qx + rotation->R32*qy; 
    197     // Indirect calculation of qab, from qab^2 = |q|^2 - qc^2 
    198     const double dqa = sqrt(-dqc*dqc + qx*qx + qy*qy); 
    199  
    200     *qa_out = dqa; 
     194    const double dqab_sq = -dqc*dqc + qx*qx + qy*qy; 
     195    //*qab_out = sqrt(fabs(dqab_sq)); 
     196    *qab_out = dqab_sq > 0.0 ? sqrt(dqab_sq) : 0.0; 
    201197    *qc_out = dqc; 
    202198} 
     
    274270#endif // _QABC_SECTION 
    275271 
     272 
    276273// ==================== KERNEL CODE ======================== 
    277 #define COMPUTE_F1_F2 defined(CALL_FQ) 
     274 
    278275kernel 
    279276void KERNEL_NAME( 
     
    285282    global const double *q, // nq q values, with padding to boundary 
    286283    global double *result,  // nq+1 return values, again with padding 
    287     const double cutoff,     // cutoff in the dispersity weight product 
    288     int32_t effective_radius_type // which effective radius to compute 
     284    const double cutoff     // cutoff in the dispersity weight product 
    289285    ) 
    290286{ 
     
    345341  // version must loop over all q. 
    346342  #ifdef USE_OPENCL 
    347     #if COMPUTE_F1_F2 
    348       double weight_norm = (pd_start == 0 ? 0.0 : result[2*nq]); 
    349       double weighted_volume = (pd_start == 0 ? 0.0 : result[2*nq+1]); 
    350       double weighted_radius = (pd_start == 0 ? 0.0 : result[2*nq+2]); 
    351       double this_F2 = (pd_start == 0 ? 0.0 : result[2*q_index+0]); 
    352       double this_F1 = (pd_start == 0 ? 0.0 : result[2*q_index+1]); 
    353     #else 
    354       double weight_norm = (pd_start == 0 ? 0.0 : result[nq]); 
    355       double weighted_volume = (pd_start == 0 ? 0.0 : result[nq+1]); 
    356       double weighted_radius = (pd_start == 0 ? 0.0 : result[nq+2]); 
    357       double this_result = (pd_start == 0 ? 0.0 : result[q_index]); 
    358     #endif 
     343    double pd_norm = (pd_start == 0 ? 0.0 : result[nq]); 
     344    double this_result = (pd_start == 0 ? 0.0 : result[q_index]); 
    359345  #else // !USE_OPENCL 
    360     #if COMPUTE_F1_F2 
    361       double weight_norm = (pd_start == 0 ? 0.0 : result[2*nq]); 
    362       double weighted_volume = (pd_start == 0 ? 0.0 : result[2*nq+1]); 
    363       double weighted_radius = (pd_start == 0 ? 0.0 : result[2*nq+2]); 
    364     #else 
    365       double weight_norm = (pd_start == 0 ? 0.0 : result[nq]); 
    366       double weighted_volume = (pd_start == 0 ? 0.0 : result[nq+1]); 
    367       double weighted_radius = (pd_start == 0 ? 0.0 : result[nq+2]); 
    368     #endif 
     346    double pd_norm = (pd_start == 0 ? 0.0 : result[nq]); 
    369347    if (pd_start == 0) { 
    370348      #ifdef USE_OPENMP 
    371349      #pragma omp parallel for 
    372350      #endif 
    373       #if COMPUTE_F1_F2 
    374           // 2*nq for F^2,F pairs 
    375           for (int q_index=0; q_index < 2*nq; q_index++) result[q_index] = 0.0; 
    376       #else 
    377           for (int q_index=0; q_index < nq; q_index++) result[q_index] = 0.0; 
    378       #endif 
     351      for (int q_index=0; q_index < nq; q_index++) result[q_index] = 0.0; 
    379352    } 
    380     //if (q_index==0) printf("start %d %g %g\n", pd_start, weighted_volume, result[0]); 
     353    //if (q_index==0) printf("start %d %g %g\n", pd_start, pd_norm, result[0]); 
    381354#endif // !USE_OPENCL 
    382355 
     
    469442// inner loop and defines the macros that use them. 
    470443 
    471  
    472 #if defined(CALL_FQ) // COMPUTE_F1_F2 is true 
    473   // unoriented 1D returning <F> and <F^2> 
    474   double qk; 
    475   double F1, F2; 
    476   #define FETCH_Q() do { qk = q[q_index]; } while (0) 
    477   #define BUILD_ROTATION() do {} while(0) 
    478   #define APPLY_ROTATION() do {} while(0) 
    479   #define CALL_KERNEL() CALL_FQ(qk,F1,F2,local_values.table) 
    480  
    481 #elif defined(CALL_FQ_A) 
    482   // unoriented 2D return <F> and <F^2> 
    483   double qx, qy; 
    484   double F1, F2; 
    485   #define FETCH_Q() do { qx = q[2*q_index]; qy = q[2*q_index+1]; } while (0) 
    486   #define BUILD_ROTATION() do {} while(0) 
    487   #define APPLY_ROTATION() do {} while(0) 
    488   #define CALL_KERNEL() CALL_FQ_A(sqrt(qx*qx+qy*qy),F1,F2,local_values.table) 
    489  
    490 #elif defined(CALL_IQ) 
    491   // unoriented 1D return <F^2> 
     444#if defined(CALL_IQ) 
     445  // unoriented 1D 
    492446  double qk; 
    493447  #define FETCH_Q() do { qk = q[q_index]; } while (0) 
    494448  #define BUILD_ROTATION() do {} while(0) 
    495449  #define APPLY_ROTATION() do {} while(0) 
    496   #define CALL_KERNEL() CALL_IQ(qk,local_values.table) 
     450  #define CALL_KERNEL() CALL_IQ(qk, local_values.table) 
    497451 
    498452#elif defined(CALL_IQ_A) 
     
    528482  #define APPLY_ROTATION() qabc_apply(&rotation, qx, qy, &qa, &qb, &qc) 
    529483  #define CALL_KERNEL() CALL_IQ_ABC(qa, qb, qc, local_values.table) 
    530  
    531484#elif defined(CALL_IQ_XY) 
    532485  // direct call to qx,qy calculator 
     
    542495// logic in the IQ_AC and IQ_ABC branches.  This will become more important 
    543496// if we implement more projections, or more complicated projections. 
    544 #if defined(CALL_IQ) || defined(CALL_IQ_A) || defined(CALL_FQ) || defined(CALL_FQ_A) 
    545   // no orientation 
     497#if defined(CALL_IQ) || defined(CALL_IQ_A)  // no orientation 
    546498  #define APPLY_PROJECTION() const double weight=weight0 
    547499#elif defined(CALL_IQ_XY) // pass orientation to the model 
     
    693645    // Note: weight==0 must always be excluded 
    694646    if (weight > cutoff) { 
    695       weighted_volume += weight * CALL_VOLUME(local_values.table); 
    696       #if COMPUTE_F1_F2 
    697       weight_norm += weight; 
    698       #endif 
    699       if (effective_radius_type != 0) { 
    700         weighted_radius += weight * CALL_EFFECTIVE_RADIUS(effective_radius_type, local_values.table); 
    701       } 
     647      pd_norm += weight * CALL_VOLUME(local_values.table); 
    702648      BUILD_ROTATION(); 
    703649 
     
    747693          } 
    748694        #else  // !MAGNETIC 
    749           #if COMPUTE_F1_F2 
    750             CALL_KERNEL(); // sets F1 and F2 by reference 
    751           #else 
    752             const double scattering = CALL_KERNEL(); 
    753           #endif 
     695          const double scattering = CALL_KERNEL(); 
    754696        #endif // !MAGNETIC 
    755697//printf("q_index:%d %g %g %g %g\n", q_index, scattering, weight0); 
    756698 
    757699        #ifdef USE_OPENCL 
    758           #if COMPUTE_F1_F2 
    759             this_F2 += weight * F2; 
    760             this_F1 += weight * F1; 
    761           #else 
    762             this_result += weight * scattering; 
    763           #endif 
     700          this_result += weight * scattering; 
    764701        #else // !USE_OPENCL 
    765           #if COMPUTE_F1_F2 
    766             result[2*q_index+0] += weight * F2; 
    767             result[2*q_index+1] += weight * F1; 
    768           #else 
    769             result[q_index] += weight * scattering; 
    770           #endif 
     702          result[q_index] += weight * scattering; 
    771703        #endif // !USE_OPENCL 
    772704      } 
    773705    } 
    774706  } 
     707 
    775708// close nested loops 
    776709++step; 
     
    793726// Remember the current result and the updated norm. 
    794727#ifdef USE_OPENCL 
    795   #if COMPUTE_F1_F2 
    796     result[2*q_index+0] = this_F2; 
    797     result[2*q_index+1] = this_F1; 
    798     if (q_index == 0) { 
    799       result[2*nq+0] = weight_norm; 
    800       result[2*nq+1] = weighted_volume; 
    801       result[2*nq+2] = weighted_radius; 
    802     } 
    803   #else 
    804     result[q_index] = this_result; 
    805     if (q_index == 0) { 
    806       result[nq+0] = weight_norm; 
    807       result[nq+1] = weighted_volume; 
    808       result[nq+2] = weighted_radius; 
    809     } 
    810   #endif 
    811  
    812 //if (q_index == 0) printf("res: %g/%g\n", result[0], weigthed_volume); 
     728  result[q_index] = this_result; 
     729  if (q_index == 0) result[nq] = pd_norm; 
     730//if (q_index == 0) printf("res: %g/%g\n", result[0], pd_norm); 
    813731#else // !USE_OPENCL 
    814   #if COMPUTE_F1_F2 
    815     result[2*nq] = weight_norm; 
    816     result[2*nq+1] = weighted_volume; 
    817     result[2*nq+2] = weighted_radius; 
    818   #else 
    819     result[nq] = weight_norm; 
    820     result[nq+1] = weighted_volume; 
    821     result[nq+2] = weighted_radius; 
    822   #endif 
    823 //printf("res: %g/%g\n", result[0], weighted_volume); 
     732  result[nq] = pd_norm; 
     733//printf("res: %g/%g\n", result[0], pd_norm); 
    824734#endif // !USE_OPENCL 
    825735 
    826736// ** clear the macros in preparation for the next kernel ** 
    827 #undef COMPUTE_F1_F2 
    828737#undef PD_INIT 
    829738#undef PD_OPEN 
Note: See TracChangeset for help on using the changeset viewer.