Beispiel #1
0
def test_selec(write_read, num_floats):
    parameters_ref = {
        "selections": {
            "integers": {
                k + 1: v
                for k, v in enumerate(numpy.random.randint(100, size=16))
            },
            "floats": (numpy.random.rand(num_floats) if num_floats is not None
                       and num_floats <= 8 else numpy.random.rand(
                           numpy.random.randint(100) + 1,
                           numpy.random.randint(8) + 1)),
        },
    }
    parameters_ref["selections"]["integers"][1] = (len(
        parameters_ref["selections"]["floats"]) if numpy.ndim(
            parameters_ref["selections"]["floats"]) == 2 else 1)
    parameters = write_read(parameters_ref)

    helpers.allclose_dict(parameters_ref["selections"]["integers"],
                          parameters["selections"]["integers"])
    if "floats" in parameters["selections"].keys():
        assert numpy.allclose(
            parameters_ref["selections"]["floats"],
            parameters["selections"]["floats"],
            atol=1.0e-4,
        )
    else:
        assert parameters_ref["selections"]["integers"][1] == 0
Beispiel #2
0
def test_flac(write_read):
    parameters_ref = {
        "flac": {
            "creep": bool(numpy.random.randint(2)),
            "porosity_model": numpy.random.randint(10),
            "version": numpy.random.randint(10),
        },
        "rocks": {
            helpers.random_string(5): {
                "permeability_model": {
                    "id": numpy.random.randint(10),
                    "parameters":
                    numpy.random.rand(numpy.random.randint(7) + 1),
                },
                "equivalent_pore_pressure": {
                    "id": numpy.random.randint(10),
                    "parameters":
                    numpy.random.rand(numpy.random.randint(7) + 1),
                },
            }
            for _ in numpy.random.rand(10) + 1
        },
    }
    parameters = write_read(parameters_ref)

    helpers.allclose_dict(parameters_ref["flac"], parameters["flac"])
    for k, v in parameters_ref["rocks"].items():
        for kk, vv in v.items():
            helpers.allclose_dict(vv, parameters["rocks"][k][kk], atol=1.0e-4)
Beispiel #3
0
def test_momop(write_read):
    parameters_ref = {
        "more_options":
        {k + 1: v
         for k, v in enumerate(numpy.random.randint(10, size=40))},
    }
    parameters = write_read(parameters_ref)

    helpers.allclose_dict(parameters_ref["more_options"],
                          parameters["more_options"])
Beispiel #4
0
def test_rpcap(write_read, rpcap):
    parameters_ref = {"default": {}}
    if rpcap in {"rp", "both"}:
        parameters_ref["default"]["relative_permeability"] = {
            "id": numpy.random.randint(10),
            "parameters": numpy.random.rand(numpy.random.randint(7) + 1),
        }
    if rpcap in {"cap", "both"}:
        parameters_ref["default"]["capillarity"] = {
            "id": numpy.random.randint(10),
            "parameters": numpy.random.rand(numpy.random.randint(7) + 1),
        }
    parameters = write_read(parameters_ref)

    for k, v in parameters_ref["default"].items():
        helpers.allclose_dict(v, parameters["default"][k], atol=1.0e-4)
Beispiel #5
0
def test_param(write_read, t_steps, num_pvars):
    parameters_ref = {
        "options": {
            "n_iteration": numpy.random.randint(10),
            "n_cycle": numpy.random.randint(10),
            "n_second": numpy.random.randint(10),
            "n_cycle_print": numpy.random.randint(10),
            "verbosity": numpy.random.randint(10),
            "temperature_dependence_gas": numpy.random.rand(),
            "effective_strength_vapor": numpy.random.rand(),
            "t_ini": numpy.random.rand(),
            "t_max": numpy.random.rand(),
            "t_steps": t_steps,
            "t_step_max": numpy.random.rand(),
            "t_reduce_factor": numpy.random.rand(),
            "gravity": numpy.random.rand(),
            "mesh_scale_factor": numpy.random.rand(),
            "eps1": numpy.random.rand(),
            "eps2": numpy.random.rand(),
            "w_upstream": numpy.random.rand(),
            "w_newton": numpy.random.rand(),
            "derivative_factor": numpy.random.rand(),
        },
        "extra_options":
        {k + 1: v
         for k, v in enumerate(numpy.random.randint(10, size=24))},
        "default": {
            "initial_condition": numpy.random.rand(num_pvars)
        },
    }
    parameters = write_read(parameters_ref)

    helpers.allclose_dict(parameters_ref["options"],
                          parameters["options"],
                          atol=1.0e-5)
    helpers.allclose_dict(parameters_ref["extra_options"],
                          parameters["extra_options"])
    if "initial_condition" in parameters["default"].keys():
        assert numpy.allclose(
            parameters_ref["default"]["initial_condition"],
            parameters["default"]["initial_condition"],
            atol=1.0e-5,
        )
    else:
        assert not len(parameters_ref["default"]["initial_condition"])
Beispiel #6
0
def test_save2incon(reset):
    this_dir = os.path.dirname(os.path.abspath(__file__))
    filename = os.path.join(this_dir, "support_files", "outputs", "SAVE.out")
    save = toughio.read_output(filename)

    output_filename = helpers.tempdir(helpers.random_string(10))
    argv = [
        filename,
        output_filename,
    ]

    if reset:
        argv += ["-r"]

    toughio._cli.save2incon(argv)

    incon = toughio.read_output(output_filename)

    assert save.labels.tolist() == incon.labels.tolist()
    helpers.allclose_dict(save.data, incon.data)
Beispiel #7
0
def test_outpu(write_read, fmt):
    parameters_ref = {
        "output": {
            "format": fmt,
            "variables": {
                helpers.random_string(20):
                None,
                helpers.random_string(20):
                numpy.random.randint(10),
                helpers.random_string(20):
                numpy.random.randint(10, size=1),
                helpers.random_string(20):
                numpy.random.randint(10, size=2),
                helpers.random_string(20):
                numpy.random.randint(10, size=(numpy.random.randint(1,
                                                                    10), 2)),
            },
        },
    }
    parameters = write_read(parameters_ref)

    helpers.allclose_dict(parameters_ref["output"]["variables"],
                          parameters["output"]["variables"])
Beispiel #8
0
def test_rocks(write_read):
    keys = [
        "density",
        "porosity",
        "permeability",
        "conductivity",
        "specific_heat",
        "compressibility",
        "expansivity",
        "conductivity_dry",
        "tortuosity",
        "klinkenberg_parameter",
        "distribution_coefficient_3",
        "distribution_coefficient_4",
    ]
    parameters_ref = {
        "rocks": {
            helpers.random_string(5):
            {key: numpy.random.rand()
             for key in keys[:5]},
            helpers.random_string(5): {
                key: numpy.random.rand()
                if key != "permeability" else numpy.random.rand(3)
                for key in keys[:5]
            },
            helpers.random_string(5):
            {key: numpy.random.rand()
             for key in keys},
            helpers.random_string(5):
            {key: numpy.random.rand()
             for key in keys},
            helpers.random_string(5):
            {key: numpy.random.rand()
             for key in keys},
            helpers.random_string(5):
            {key: numpy.random.rand()
             for key in keys},
        }
    }
    names = list(parameters_ref["rocks"].keys())
    parameters_ref["rocks"][names[-1]].update({
        "relative_permeability": {
            "id": numpy.random.randint(10),
            "parameters": numpy.random.rand(numpy.random.randint(7) + 1),
        },
    })
    parameters_ref["rocks"][names[-2]].update({
        "capillarity": {
            "id": numpy.random.randint(10),
            "parameters": numpy.random.rand(numpy.random.randint(7) + 1),
        },
    })
    parameters_ref["rocks"][names[-3]].update({
        "relative_permeability": {
            "id": numpy.random.randint(10),
            "parameters": numpy.random.rand(numpy.random.randint(7) + 1),
        },
        "capillarity": {
            "id": numpy.random.randint(10),
            "parameters": numpy.random.rand(numpy.random.randint(7) + 1),
        },
    })
    parameters = write_read(parameters_ref)

    assert sorted(parameters_ref["rocks"].keys()) == sorted(
        parameters["rocks"].keys())

    for k, v in parameters_ref["rocks"].items():
        for kk, vv in v.items():
            if not isinstance(vv, dict):
                assert numpy.allclose(vv,
                                      parameters["rocks"][k][kk],
                                      atol=1.0e-5)
            else:
                helpers.allclose_dict(vv,
                                      parameters["rocks"][k][kk],
                                      atol=1.0e-4)