def test_mphsolver_on_ones_block(): """Run solver on a block of ones.""" l = 20 img = np.ones([l, l, l]).reshape(1, l, l, l) S = tau.MultiPhaseSolver(img) S.solve(iter_limit=1000) assert np.around(S.tau, 4) == 1.0
def test_mphsolver_on_empty_block(): """Run solver on a block of zeros.""" l = 20 img = np.zeros([l, l, l]).reshape(1, l, l, l) S = tau.MultiPhaseSolver(img) S.solve(iter_limit=1000) assert S.tau == cp.inf
def test_mphsolver_on_strip_of_ones(): """Run solver on a strip of ones, 1/4 volume of total""" l = 20 img = np.zeros([l, l, l]).reshape(1, l, l, l) x = 10 img[:, :, 0:x, 0:x] = 1 S = tau.MultiPhaseSolver(img) S.solve() assert np.around(S.tau, 4) == 1.0
def test_mphsolver_on_halves(): """Run solver on a block of halves.""" l = 20 img = np.ones([l, l, l]).reshape(1, l, l, l) cond = 0.5 S = tau.MultiPhaseSolver(img, {1: cond}) S.solve(iter_limit=1000) print(S.D_eff, S.D_mean) assert np.around(S.tau, 4) == 1.0
def test_mphsolver_on_strip_of_ones_and_twos_and_threes(): """Run solver on a strip of ones, 1/4 volume of total""" l = 20 img = np.ones([l, l, l]).reshape(1, l, l, l) x = 10 img[:, :, 0:x, 0:x] = 2 img[:, :, 0:x, x:l] = 3 cond = {1: 1, 2: 0.5, 3: 2} S = tau.MultiPhaseSolver(img, cond) S.solve() assert np.around(S.tau, 4) == 1
def test_multiphase_and_solver_agree(): x = 100 img = np.ones([x, x, x]) img[50:] = 2 img[:, :20] = 0 img[:, 50:] = 1 s = tau.MultiPhaseSolver(img, {1: 1, 2: 1 * 10**-4}) mph = s.solve(verbose='per_iter', conv_crit=0.02) img[img == 2] = 0 s = tau.Solver(img) s.solve(verbose='per_iter') err = (mph - s.tau) assert err < 0.02