Пример #1
0
@pytest.mark.parametrize("dtype", ["float64"])
def test_make_hermitian(ctx_factory, grid_shape, proc_shape, dtype):
    if proc_shape != (1, 1, 1):
        pytest.skip("test make_hermitian only on one rank")

    kshape = (grid_shape[0], grid_shape[1], grid_shape[2]//2 + 1)
    data = np.random.rand(*kshape) + 1j * np.random.rand(*kshape)

    from pystella.fourier.rayleigh import make_hermitian
    data = make_hermitian(data)
    assert is_hermitian(data), "data is not hermitian"


if __name__ == "__main__":
    from common import parser
    parser.set_defaults(grid_shape=(32,)*3)
    args = parser.parse_args()

    if args.proc_shape == (1, 1, 1):
        test_make_hermitian(
            None, grid_shape=args.grid_shape, proc_shape=args.proc_shape,
            dtype=args.dtype,
        )
    for random in [True, False]:
        test_generate_WKB(
            None, grid_shape=args.grid_shape, proc_shape=args.proc_shape,
            dtype=args.dtype, timing=args.timing, random=random
        )
        test_generate(
            None, grid_shape=args.grid_shape, proc_shape=args.proc_shape,
            dtype=args.dtype, timing=args.timing, random=random
Пример #2
0
                max_amp = np.max(spectrum)
                first_zero = np.argmax(spectrum[1:] < 1e-30 * max_amp)
                first_mode_zeroed[key].append(first_zero)

    for k, errs in errors.items():
        errs = np.array(errs)
        iters = np.arange(1, errs.shape[0] + 1)
        assert (errs[10:, 0] * iters[10:] / errs[0, 0] < 1.).all(), \
            "relaxation not converging at least linearly for " \
            f"{grid_shape=}, {h=}, {proc_shape=}"

    first_mode_zeroed = mpi.bcast(first_mode_zeroed, root=0)
    for k, x in first_mode_zeroed.items():
        x = np.array(list(x))[2:]
        assert (x[1:] <= x[:-1]).all() and np.min(x) < np.max(x) / 5, \
            f"relaxation not smoothing error {grid_shape=}, {h=}, {proc_shape=}"


if __name__ == "__main__":
    from common import parser
    parser.set_defaults(grid_shape=(128, ) * 3)
    args = parser.parse_args()

    test_relax(None,
               grid_shape=args.grid_shape,
               proc_shape=args.proc_shape,
               h=args.h,
               dtype=args.dtype,
               timing=args.timing,
               Solver=NewtonIterator)