create_param_maps.py 3.11 KB
Newer Older
1 2 3 4 5 6 7 8 9
import h5py
import numpy as np
import os
import argparse

def create_and_write_datasets(args):
    grid_test_2d = np.zeros((20, 20), dtype=np.int_)
    grid_test_2d[10:, :] = 1

10 11 12 13 14
    grid_test_2d_bc_left = np.full((20), 2, dtype=np.int_)
    grid_test_2d_bc_left[10:] = 3
    grid_test_2d_bc_right = np.full((20), 2, dtype=np.int_)
    grid_test_2d_bc_right[10:] = 3

15 16
    grid_test_3d = np.zeros((10, 10, 10), dtype=np.int_)
    grid_test_3d[5:, :, :] = 1
17 18 19 20 21 22 23 24
    grid_test_3d_bc_left = np.full((10, 10), 2, dtype=np.int_)
    grid_test_3d_bc_left[5:, ...] = 3
    grid_test_3d_bc_right = np.full((10, 10), 2, dtype=np.int_)
    grid_test_3d_bc_right[5:, ...] = 3
    grid_test_3d_bc_front = np.full((10, 10), 2, dtype=np.int_)
    grid_test_3d_bc_front[5:, ...] = 3
    grid_test_3d_bc_back = np.full((10, 10), 2, dtype=np.int_)
    grid_test_3d_bc_back[5:, ...] = 3
25

26 27 28
    ode_layered_320 = np.zeros((320, 1), dtype=np.int_)
    ode_layered_320[160:, ...] = 1

29 30 31 32 33 34 35 36 37
    ode_layered_160 = np.zeros((160, 1), dtype=np.int_)
    ode_layered_160[80:, ...] = 1

    ode_layered_40 = np.zeros((40, 1), dtype=np.int_)
    ode_layered_40[20:, ...] = 1

    ode_layered_20 = np.zeros((20, 1), dtype=np.int_)
    ode_layered_20[10:, ...] = 1

38 39
    param_test_2 = np.random.randint(2, size=(50, 50))
    param_test_5 = np.random.randint(2, size=(50, 50))
Lukas Riedel's avatar
Lukas Riedel committed
40

Lukas Riedel's avatar
Lukas Riedel committed
41 42 43 44 45 46 47
    # have a checkerboard!
    parallel_reference_2d = np.kron([[1, 0] * 2, [0, 1] * 2] * 2, np.ones((10, 10), dtype=np.int_))
    parallel_reference_3d = np.kron([[[1, 0],
                                      [0, 1]],
                                     [[0, 1],
                                      [1, 0]]], np.ones((5, 5, 5), dtype=np.int_))

48
    f = h5py.File(args.path, 'w')
49 50 51 52 53 54 55 56 57
    f.create_dataset("grid_test_2d/volume", data=grid_test_2d)
    f.create_dataset("grid_test_2d/boundary_left", data=grid_test_2d_bc_left)
    f.create_dataset("grid_test_2d/boundary_right", data=grid_test_2d_bc_right)
    f.create_dataset("grid_test_3d/volume", data=grid_test_3d)
    f.create_dataset("grid_test_3d/boundary_left", data=grid_test_3d_bc_left)
    f.create_dataset("grid_test_3d/boundary_right", data=grid_test_3d_bc_right)
    f.create_dataset("grid_test_3d/boundary_front", data=grid_test_3d_bc_front)
    f.create_dataset("grid_test_3d/boundary_back", data=grid_test_3d_bc_back)

58
    f.create_dataset("ode_layered_320", data=ode_layered_320)
59 60 61
    f.create_dataset("ode_layered_160", data=ode_layered_160)
    f.create_dataset("ode_layered_40", data=ode_layered_40)
    f.create_dataset("ode_layered_20", data=ode_layered_20)
62 63
    f.create_dataset("ut/param_test_2", data=param_test_2)
    f.create_dataset("ut/param_test_5", data=param_test_5)
Lukas Riedel's avatar
Lukas Riedel committed
64 65
    f.create_dataset("parallel_reference_2d", data=parallel_reference_2d)
    f.create_dataset("parallel_reference_3d", data=parallel_reference_3d)
66 67 68 69 70 71 72 73 74 75 76
    f.close()

def parse_cli():
    parser = argparse.ArgumentParser(description="Write parameter mapping "
        "datasets for all tests")
    parser.add_argument("path", type=os.path.realpath,
        help="File path to write the data")
    return parser.parse_args()

if __name__ == "__main__":
    args = parse_cli()
77
    create_and_write_datasets(args)