def SCFeqns_test(): # away from solution phi_z = np.linspace(.5, 0, 50) chi = 0.1 chi_s = 0.05 sigma = .1 navgsegments = 95.5 pdi = 1.2 p_i = SZdist(pdi, navgsegments) data = np.array( (0.24809791, 0.19944421, 0.16973004, 0.14729207, 0.13005919, 0.11657451, 0.1058576, 0.09727039, 0.09038682, 0.08490298, 0.08058535, 0.07724325, 0.07471421, 0.07285592, 0.07154151, 0.07065667, 0.0700978, 0.06977082, 0.0695903, 0.06947884, 0.0693665, 0.06919036, 0.06889397, 0.06842689, 0.06774423, 0.06680614, 0.06557737, 0.06402683, 0.0621272, 0.05985452, 0.05718783, 0.05410874, 0.05060095, 0.0466496, 0.04224034, 0.037358, 0.03198467, 0.02609722, 0.01966451, 0.01264599, 0.00499654, -0.00331032, -0.01221627, -0.02143066, -0.03017221, -0.0368608, -0.0390676, -0.03438821, -0.02291077, -0.01063797)) result = SCFeqns(phi_z, chi, chi_s, sigma, navgsegments, p_i) check(result, data, rtol=2e-6) # at solution phi_z = easy_phi_z.copy() data = np.array( (-9.29275601e-10, -5.71888092e-11, -6.36132924e-10, -1.55644492e-09, -1.13562165e-09, -9.72811443e-10, -1.63384295e-09, -1.18849514e-09, -2.89755997e-10, -7.75140563e-10, -1.77285464e-10, 9.26357491e-10, 1.16035537e-09, 1.35558342e-10, 3.92842869e-10, -1.16742438e-09, -1.13646220e-09, 1.31389510e-10, -7.78504983e-10, -1.16462257e-10, 1.06623532e-09, 1.31860881e-09, 1.29663683e-09, 1.62908659e-10, 1.10570872e-09, 1.12047058e-09, 2.64739120e-10, -9.46467349e-11, -7.11506659e-10, -1.17296972e-09, -1.00791650e-09, -1.64910530e-10, -1.19973027e-09, -6.62134042e-10, -6.10394263e-10, -6.62704530e-10, -7.97200791e-10, -9.37733571e-10, -1.10498946e-09, -1.24565040e-09, -1.41609789e-09, -1.67821481e-09, -2.02143809e-09, -2.48336908e-09, -2.98173400e-09, -3.44456770e-09, -3.97225693e-09, -4.38723307e-09, -4.62610414e-09, -4.77197874e-09, -4.73971093e-09, -4.48724133e-09, -4.05071319e-09, -3.46513582e-09, -2.77379160e-09, -2.04575741e-09, -1.32608356e-09, -6.40953530e-10, -2.51873555e-11, 5.10576483e-10, 9.60606714e-10, 1.32984397e-09, 1.62342470e-09, 1.85145266e-09, 2.02196043e-09, 2.14281230e-09, 2.21889979e-09, 2.25142468e-09, 2.23470713e-09, -6.43817608e-06, -4.05512658e-06, -2.53549899e-06, -1.57360459e-06, -9.69199656e-07, -5.92195683e-07, -3.58754495e-07, -2.15266255e-07, -1.27713614e-07, -7.46744540e-08, -4.27578070e-08, -2.36527590e-08, -1.22420735e-08, -5.42986558e-09, -1.49766885e-09)) result = SCFeqns(phi_z, chi, chi_s, sigma, navgsegments, p_i) check(result, data)
def SCFeqns_test(): # away from solution phi_z = np.linspace(.5,0,50) chi = 0.1 chi_s = 0.05 sigma = .1 navgsegments = 95.5 pdi = 1.2 p_i = SZdist(pdi,navgsegments) data = np.array(( 0.24810378, 0.19945097, 0.16973725, 0.14729956, 0.13006686, 0.11658225, 0.10586535, 0.0972781 , 0.09039446, 0.08491051, 0.08059274, 0.07725048, 0.07472126, 0.07286278, 0.07154816, 0.0706631 , 0.07010401, 0.06977679, 0.06959604, 0.06948434, 0.06937178, 0.0691954 , 0.06889878, 0.06843147, 0.06774859, 0.06681028, 0.06558131, 0.06403057, 0.06213075, 0.05985788, 0.05719101, 0.05411175, 0.05060381, 0.04665231, 0.04224292, 0.03736045, 0.03198701, 0.02609946, 0.01966667, 0.01264807, 0.00499856, -0.00330835, -0.01221432, -0.02142874, -0.03017032, -0.036859 , -0.03906598, -0.03438694, -0.02291 , -0.01063772)) result = SCFeqns(phi_z,chi,chi_s,sigma,navgsegments,p_i) assert np.allclose(result, data, atol=1e-14) # at solution phi_z = easy_phi_z.copy() data = np.array(( -8.94301463e-08, -8.54926846e-08, -8.48261388e-08, -8.63975905e-08, -8.69395192e-08, -8.93377617e-08, -9.09841657e-08, -9.27694738e-08, -9.40202529e-08, -9.15368746e-08, -9.14763008e-08, -9.09397544e-08, -8.86826744e-08, -8.53626849e-08, -8.09892757e-08, -7.78940357e-08, -7.61289833e-08, -7.04561874e-08, -6.17791860e-08, -5.30517064e-08, -5.05450191e-08, -6.12440418e-08, -9.95948151e-08, -1.80944723e-07, -3.13346818e-07, -4.69662996e-07, -6.22535829e-07, -9.26554049e-07, -1.82794947e-06, -3.85118182e-06, -5.49741579e-06, -3.57205254e-06, -1.60524494e-06, -9.99775760e-07, -9.79287226e-07, -1.22893515e-06, -1.68575805e-06, -2.29902384e-06, -3.00785458e-06, -3.78510399e-06, -4.63784940e-06, -5.56981451e-06, -6.57126744e-06, -7.58582431e-06, -8.52386576e-06, -9.28524056e-06, -9.77055209e-06, -9.89221388e-06, -9.58838679e-06, -8.83634616e-06, -7.66057845e-06, -6.13119467e-06, -4.33559537e-06, -2.37547500e-06, -3.70371253e-07, 1.56485541e-06, 3.34331420e-06, 4.91516031e-06, 6.26511768e-06, 7.40554630e-06, 8.36923052e-06, 9.20310167e-06, 9.96358757e-06, 1.07179875e-05, 1.15255367e-05, 1.23926773e-05, 1.31522431e-05, 1.31565523e-05)) result = SCFeqns(phi_z,chi,chi_s,sigma,navgsegments,p_i) assert np.allclose(result, data, atol=1e-14) # check that penalty penalizes phi_z[0]=.999 result = SCFeqns(phi_z,chi,chi_s,sigma,navgsegments,p_i) below = np.linalg.norm(result,np.inf) phi_z[0] = 1.0 result = SCFeqns(phi_z,chi,chi_s,sigma,navgsegments,p_i) above = np.linalg.norm(result,np.inf) assert above > (below + 1e5*(phi_z[0]-.99999))
def SZdist_test(): # uniform pdi=1 nn=100 data = np.array((( 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.))) assert np.allclose(SZdist(pdi,nn), data, atol=1e-14) # too narrow pdi=1.0000000001 nn=100 assert np.allclose(SZdist(pdi,nn), data, atol=1e-14) # broad pdi=2 nn=30 data = np.array((( 3.22405367e-02, 3.11835662e-02, 3.01612473e-02, 2.91724440e-02, 2.82160575e-02, 2.72910251e-02, 2.63963189e-02, 2.55309446e-02, 2.46939407e-02, 2.38843770e-02, 2.31013540e-02, 2.23440015e-02, 2.16114780e-02, 2.09029695e-02, 2.02176887e-02, 1.95548740e-02, 1.89137890e-02, 1.82937212e-02, 1.76939817e-02, 1.71139040e-02, 1.65528435e-02, 1.60101767e-02, 1.54853007e-02, 1.49776321e-02, 1.44866070e-02, 1.40116795e-02, 1.35523220e-02, 1.31080240e-02, 1.26782919e-02, 1.22626480e-02, 1.18606306e-02, 1.14717929e-02, 1.10957028e-02, 1.07319424e-02, 1.03801075e-02, 1.00398071e-02, 9.71066304e-03, 9.39230964e-03, 9.08439310e-03, 8.78657127e-03, 8.49851320e-03, 8.21989880e-03, 7.95041846e-03, 7.68977274e-03, 7.43767200e-03, 7.19383611e-03, 6.95799411e-03, 6.72988393e-03, 6.50925209e-03, 6.29585343e-03, 6.08945080e-03, 5.88981486e-03, 5.69672376e-03, 5.50996294e-03, 5.32932487e-03, 5.15460882e-03, 4.98562064e-03, 4.82217255e-03, 4.66408293e-03, 4.51117611e-03, 4.36328216e-03, 4.22023676e-03, 4.08188094e-03, 3.94806097e-03, 3.81862813e-03, 3.69343861e-03, 3.57235329e-03, 3.45523762e-03, 3.34196146e-03, 3.23239893e-03, 3.12642829e-03, 3.02393178e-03, 2.92479550e-03, 2.82890930e-03, 2.73616662e-03, 2.64646441e-03, 2.55970299e-03, 2.47578594e-03, 2.39462002e-03, 2.31611504e-03, 2.24018376e-03, 2.16674180e-03, 2.09570755e-03, 2.02700209e-03, 1.96054905e-03, 1.89627461e-03, 1.83410734e-03, 1.77397814e-03, 1.71582022e-03, 1.65956895e-03, 1.60516180e-03, 1.55253834e-03, 1.50164008e-03, 1.45241046e-03, 1.40479478e-03, 1.35874013e-03, 1.31419533e-03, 1.27111088e-03, 1.22943891e-03, 1.18913311e-03, 1.15014869e-03, 1.11244233e-03, 1.07597213e-03, 1.04069757e-03, 1.00657945e-03, 9.73579848e-04, 9.41662104e-04, 9.10790748e-04, 8.80931476e-04, 8.52051107e-04, 8.24117549e-04, 7.97099762e-04, 7.70967724e-04, 7.45692395e-04, 7.21245691e-04, 6.97600444e-04, 6.74730382e-04, 6.52610088e-04, 6.31214985e-04, 6.10521296e-04, 5.90506027e-04, 5.71146937e-04, 5.52422513e-04, 5.34311949e-04, 5.16795120e-04, 4.99852561e-04, 4.83465445e-04, 4.67615562e-04, 4.52285300e-04, 4.37457625e-04, 4.23116058e-04, 4.09244663e-04, 3.95828028e-04, 3.82851241e-04, 3.70299885e-04, 3.58160010e-04, 3.46418129e-04, 3.35061191e-04, 3.24076579e-04, 3.13452085e-04, 3.03175903e-04, 2.93236615e-04, 2.83623175e-04, 2.74324902e-04, 2.65331462e-04, 2.56632862e-04, 2.48219436e-04, 2.40081835e-04, 2.32211016e-04, 2.24598233e-04, 2.17235027e-04, 2.10113216e-04, 2.03224886e-04, 1.96562381e-04, 1.90118300e-04, 1.83885481e-04, 1.77856998e-04, 1.72026152e-04, 1.66386464e-04, 1.60931666e-04, 1.55655699e-04, 1.50552698e-04, 1.45616994e-04, 1.40843101e-04, 1.36225715e-04, 1.31759704e-04, 1.27440108e-04, 1.23262124e-04, 1.19221111e-04, 1.15312578e-04, 1.11532182e-04, 1.07875722e-04, 1.04339135e-04, 1.00918492e-04, 9.76099898e-05, 9.44099537e-05, 9.13148273e-05, 8.83211712e-05, 8.54256588e-05, 8.26250726e-05, 7.99163005e-05, 7.72963325e-05, 7.47622573e-05, 7.23112590e-05, 6.99406139e-05, 6.76476879e-05, 6.54299329e-05, 6.32848845e-05, 6.12101592e-05, 5.92034515e-05, 5.72625315e-05, 5.53852424e-05, 5.35694982e-05, 5.18132812e-05, 5.01146398e-05, 4.84716865e-05, 4.68825956e-05, 4.53456013e-05, 4.38589956e-05, 4.24211267e-05, 4.10303968e-05, 3.96852604e-05, 3.83842228e-05, 3.71258383e-05, 3.59087085e-05, 3.47314810e-05, 3.35928476e-05, 3.24915431e-05, 3.14263436e-05, 3.03960655e-05, 2.93995640e-05, 2.84357316e-05, 2.75034974e-05, 2.66018255e-05, 2.57297140e-05, 2.48861936e-05, 2.40703271e-05, 2.32812080e-05, 2.25179592e-05, 2.17797327e-05, 2.10657081e-05, 2.03750920e-05, 1.97071171e-05, 1.90610409e-05, 1.84361457e-05, 1.78317369e-05, 1.72471431e-05, 1.66817144e-05, 1.61348228e-05, 1.56058604e-05, 1.50942394e-05, 1.45993914e-05, 1.41207664e-05, 1.36578326e-05, 1.32100756e-05, 1.27769978e-05, 1.23581180e-05, 1.19529707e-05, 1.15611057e-05, 1.11820876e-05, 1.08154952e-05, 1.04609211e-05, 1.01179713e-05, 9.78626472e-06, 9.46543280e-06, 9.15511900e-06, 8.85497850e-06, 8.56467777e-06, 8.28389424e-06, 8.01231588e-06, 7.74964092e-06, 7.49557747e-06, 7.24984321e-06, 7.01216508e-06, 6.78227897e-06, 6.55992941e-06, 6.34486935e-06, 6.13685979e-06, 5.93566959e-06, 5.74107520e-06, 5.55286037e-06, 5.37081595e-06, 5.19473966e-06, 5.02443584e-06, 4.85971524e-06, 4.70039482e-06, 4.54629755e-06, 4.39725219e-06, 4.25309311e-06, 4.11366014e-06, 3.97879832e-06, 3.84835779e-06, 3.72219362e-06, 3.60016559e-06, 3.48213813e-06, 3.36798006e-06, 3.25756454e-06, 3.15076887e-06, 3.04747438e-06, 2.94756629e-06, 2.85093357e-06, 2.75746885e-06, 2.66706827e-06, 2.57963137e-06, 2.49506100e-06, 2.41326317e-06, 2.33414699e-06, 2.25762455e-06, 2.18361081e-06, 2.11202354e-06, 2.04278317e-06, 1.97581277e-06, 1.91103792e-06, 1.84838665e-06, 1.78778933e-06, 1.72917862e-06, 1.67248940e-06, 1.61765868e-06, 1.56462552e-06, 1.51333099e-06, 1.46371810e-06, 1.41573171e-06, 1.36931851e-06, 1.32442691e-06, 1.28100703e-06, 1.23901062e-06, 1.19839102e-06, 1.15910309e-06, 1.12110317e-06, 1.08434904e-06, 1.04879985e-06, 1.01441610e-06))) assert np.allclose(SZdist(pdi,nn), data, atol=1e-14)
def SZdist_test(): # uniform pdi = 1 nn = 100 data = np.array( ((0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.))) check(SZdist(pdi, nn), data) # too narrow pdi = 1.0000000001 nn = 100 check(SZdist(pdi, nn), data) # broad pdi = 2 nn = 30 data = np.array( (3.27848972e-02, 3.17100805e-02, 3.06705004e-02, 2.96650018e-02, 2.86924673e-02, 2.77518164e-02, 2.68420036e-02, 2.59620181e-02, 2.51108819e-02, 2.42876492e-02, 2.34914054e-02, 2.27212655e-02, 2.19763738e-02, 2.12559026e-02, 2.05590512e-02, 1.98850454e-02, 1.92331360e-02, 1.86025988e-02, 1.79927331e-02, 1.74028611e-02, 1.68323275e-02, 1.62804982e-02, 1.57467599e-02, 1.52305197e-02, 1.47312039e-02, 1.42482576e-02, 1.37811442e-02, 1.33293445e-02, 1.28923566e-02, 1.24696949e-02, 1.20608897e-02, 1.16654867e-02, 1.12830465e-02, 1.09131443e-02, 1.05553688e-02, 1.02093227e-02, 9.87462129e-03, 9.55089270e-03, 9.23777719e-03, 8.93492683e-03, 8.64200509e-03, 8.35868646e-03, 8.08465612e-03, 7.81960957e-03, 7.56325228e-03, 7.31529937e-03, 7.07547533e-03, 6.84351366e-03, 6.61915660e-03, 6.40215483e-03, 6.19226723e-03, 5.98926056e-03, 5.79290925e-03, 5.60299509e-03, 5.41930706e-03, 5.24164105e-03, 5.06979961e-03, 4.90359181e-03, 4.74283295e-03, 4.58734439e-03, 4.43695335e-03, 4.29149272e-03, 4.15080086e-03, 4.01472142e-03, 3.88310319e-03, 3.75579993e-03, 3.63267016e-03, 3.51357707e-03, 3.39838831e-03, 3.28697589e-03, 3.17921600e-03, 3.07498890e-03, 2.97417878e-03, 2.87667360e-03, 2.78236502e-03, 2.69114825e-03, 2.60292191e-03, 2.51758798e-03, 2.43505163e-03, 2.35522114e-03, 2.27800781e-03, 2.20332583e-03, 2.13109222e-03, 2.06122670e-03, 1.99365165e-03, 1.92829198e-03, 1.86507505e-03, 1.80393062e-03, 1.74479074e-03, 1.68758969e-03, 1.63226392e-03, 1.57875194e-03, 1.52699430e-03, 1.47693347e-03, 1.42851383e-03, 1.38168158e-03, 1.33638467e-03, 1.29257277e-03, 1.25019719e-03, 1.20921085e-03, 1.16956821e-03, 1.13122520e-03, 1.09413923e-03, 1.05826908e-03, 1.02357489e-03, 9.90018113e-04, 9.57561458e-04, 9.26168860e-04, 8.95805433e-04, 8.66437437e-04, 8.38032240e-04, 8.10558275e-04, 7.83985014e-04, 7.58282928e-04, 7.33423457e-04, 7.09378976e-04, 6.86122767e-04, 6.63628987e-04, 6.41872641e-04, 6.20829553e-04, 6.00476339e-04, 5.80790383e-04, 5.61749809e-04, 5.43333460e-04, 5.25520871e-04, 5.08292247e-04, 4.91628445e-04, 4.75510948e-04, 4.59921844e-04, 4.44843813e-04, 4.30260098e-04, 4.16154494e-04, 4.02511327e-04, 3.89315436e-04, 3.76552158e-04, 3.64207310e-04, 3.52267174e-04, 3.40718482e-04, 3.29548402e-04, 3.18744520e-04, 3.08294832e-04, 2.98187725e-04, 2.88411969e-04, 2.78956700e-04, 2.69811411e-04, 2.60965941e-04, 2.52410460e-04, 2.44135461e-04, 2.36131748e-04, 2.28390429e-04, 2.20902900e-04, 2.13660842e-04, 2.06656206e-04, 1.99881210e-04, 1.93328324e-04, 1.86990268e-04, 1.80859998e-04, 1.74930702e-04, 1.69195791e-04, 1.63648893e-04, 1.58283844e-04, 1.53094683e-04, 1.48075642e-04, 1.43221145e-04, 1.38525797e-04, 1.33984382e-04, 1.29591851e-04, 1.25343325e-04, 1.21234082e-04, 1.17259556e-04, 1.13415331e-04, 1.09697134e-04, 1.06100834e-04, 1.02622435e-04, 9.92580712e-05, 9.60040046e-05, 9.28566190e-05, 8.98124169e-05, 8.68680156e-05, 8.40201433e-05, 8.12656354e-05, 7.86014310e-05, 7.60245696e-05, 7.35321877e-05, 7.11215159e-05, 6.87898752e-05, 6.65346749e-05, 6.43534088e-05, 6.22436531e-05, 6.02030634e-05, 5.82293722e-05, 5.63203864e-05, 5.44739845e-05, 5.26881148e-05, 5.09607930e-05, 4.92900995e-05, 4.76741778e-05, 4.61112323e-05, 4.45995263e-05, 4.31373799e-05, 4.17231684e-05, 4.03553202e-05, 3.90323155e-05, 3.77526840e-05, 3.65150038e-05, 3.53178996e-05, 3.41600411e-05, 3.30401417e-05, 3.19569570e-05, 3.09092834e-05, 2.98959565e-05, 2.89158505e-05, 2.79678762e-05, 2.70509801e-05, 2.61641435e-05, 2.53063809e-05, 2.44767390e-05, 2.36742961e-05, 2.28981603e-05, 2.21474693e-05, 2.14213889e-05, 2.07191123e-05, 2.00398590e-05, 1.93828742e-05, 1.87474280e-05, 1.81328142e-05, 1.75383499e-05, 1.69633744e-05, 1.64072488e-05, 1.58693552e-05, 1.53490959e-05, 1.48458927e-05, 1.43591864e-05, 1.38884363e-05, 1.34331192e-05, 1.29927292e-05, 1.25667768e-05, 1.21547889e-05, 1.17563075e-05, 1.13708899e-05, 1.09981078e-05, 1.06375469e-05, 1.02888067e-05, 9.95149945e-06, 9.62525049e-06, 9.30969725e-06, 9.00448907e-06, 8.70928680e-06, 8.42376242e-06, 8.14759864e-06, 7.88048858e-06, 7.62213544e-06, 7.37225212e-06, 7.13056094e-06, 6.89679335e-06, 6.67068957e-06, 6.45199835e-06, 6.24047669e-06, 6.03588953e-06, 5.83800953e-06, 5.64661681e-06, 5.46149870e-06, 5.28244947e-06, 5.10927018e-06, 4.94176838e-06, 4.77975794e-06, 4.62305884e-06, 4.47149694e-06, 4.32490383e-06, 4.18311662e-06, 4.04597775e-06, 3.91333482e-06, 3.78504044e-06, 3.66095206e-06, 3.54093177e-06, 3.42484622e-06, 3.31256641e-06, 3.20396756e-06, 3.09892901e-06, 2.99733403e-06, 2.89906974e-06, 2.80402693e-06, 2.71209999e-06, 2.62318678e-06, 2.53718848e-06, 2.45400955e-06, 2.37355755e-06, 2.29574308e-06, 2.22047967e-06, 2.14768368e-06, 2.07727424e-06, 2.00917309e-06, 1.94330456e-06, 1.87959546e-06, 1.81797499e-06, 1.75837468e-06, 1.70072830e-06, 1.64497180e-06, 1.59104321e-06, 1.53888260e-06, 1.48843203e-06, 1.43963543e-06, 1.39243856e-06, 1.34678900e-06, 1.30263600e-06, 1.25993051e-06, 1.21862508e-06, 1.17867380e-06, 1.14003227e-06, 1.10265757e-06, 1.06650815e-06, 1.03154386e-06)) check(SZdist(pdi, nn), data)