Author: tlinnet Date: Wed May 21 13:03:04 2014 New Revision: 23301 URL: http://svn.gna.org/viewcvs/relax?rev=23301&view=rev Log: Align math-domain catching for model TAP03 with trunk implementation. task #7793: (https://gna.org/task/?7793) Speed-up of dispersion models. This is to implement catching of math domain errors, before they occur. The catching of errors have to be more careful. Modified: branches/disp_speed/lib/dispersion/tap03.py Modified: branches/disp_speed/lib/dispersion/tap03.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/tap03.py?rev=23301&r1=23300&r2=23301&view=diff ============================================================================== --- branches/disp_speed/lib/dispersion/tap03.py (original) +++ branches/disp_speed/lib/dispersion/tap03.py Wed May 21 13:03:04 2014 @@ -111,28 +111,17 @@ # The gamma factor. sigma = pB*da + pA*db sigma2 = sigma**2 - gamma_denom = (sigma2 + kex2 + spin_lock_fields2)**2 - # Catch math domain error of dividing with 0. - # This is when gamma_denom =0. - if min(abs(gamma_denom)) == 0: - R1rho = array([1e100]*num_points) + gamma = 1.0 + phi_ex*(sigma2 - kex2 + spin_lock_fields2) / (sigma2 + kex2 + spin_lock_fields2)**2 - return R1rho - - gamma = 1.0 + phi_ex*(sigma2 - kex2 + spin_lock_fields2) / gamma_denom + # Bad gamma. + if min(gamma) < 0.0: + return array([1e100]*num_points) # Special omega values. waeff2 = gamma*spin_lock_fields2 + da**2 # Effective field at A. wbeff2 = gamma*spin_lock_fields2 + db**2 # Effective field at B. weff2 = gamma*spin_lock_fields2 + d**2 # Effective field at pop-average. - - # Catch math domain error of dividing with 0. - # This is when weff2 = 0. - if min(abs(weff2)) == 0: - R2eff = array([1e100]*num_points) - - return R2eff # The rotating frame flip angle. theta = arctan2(spin_lock_fields, d) @@ -144,22 +133,18 @@ R1_cos_theta2 = R1 * (1.0 - sin_theta2) R1rho_prime_sin_theta2 = r1rho_prime * sin_theta2 + # Catch zeros (to avoid pointless mathematical operations). + # This will result in no exchange, returning flat lines. + if min(numer) == 0.0: + return R1_cos_theta2 + R1rho_prime_sin_theta2 + # Denominator. denom = waeff2*wbeff2/weff2 + kex2 - 2.0*hat_sin_theta2*phi_ex + (1.0 - gamma)*spin_lock_fields2 # Catch math domain error of dividing with 0. # This is when denom =0. if min(abs(denom)) == 0: - R1rho = array([1e100]*num_points) - - return R1rho - - # Catch math domain error of dividing with 0. - # This is when gamma =0. - if min(abs(gamma)) == 0: - R1rho = array([1e100]*num_points) - - return R1rho + return array([1e100]*num_points) # R1rho calculation. R1rho = R1_cos_theta2 + R1rho_prime_sin_theta2 + hat_sin_theta2 * numer / denom / gamma