Esempio n. 1
0
def test_localization(setup_case, expected_target_gen_kw):
    """
    Note that this is now a snapshot test, so there is no guarantee that the
    snapshots are correct, they are just documenting the current behavior.
    """
    res_config = setup_case("local/snake_oil", "snake_oil.ert")
    ert = EnKFMain(res_config)
    es_update = ESUpdate(ert)
    fsm = ert.getEnkfFsManager()
    sim_fs = fsm.getFileSystem("default_0")
    target_fs = fsm.getFileSystem("target")

    # perform localization
    localized_idxs = (1, 2)
    local_config = ert.getLocalConfig()
    local_config.clear()
    obs = local_config.createObsdata("OBSSET_LOCA")
    obs.addNode("WOPR_OP1_72")
    ministep = local_config.createMinistep("MINISTEP_LOCA")
    ministep.addActiveData("SNAKE_OIL_PARAM")  # replace dataset.addNode()
    active_list = ministep.getActiveList("SNAKE_OIL_PARAM")
    for i in localized_idxs:
        active_list.addActiveIndex(i)
    ministep.attachObsset(obs)
    updatestep = local_config.getUpdatestep()
    updatestep.attachMinistep(ministep)

    # Run ensemble smoother
    mask = [True] * ert.getEnsembleSize()
    model_config = ert.getModelConfig()
    path_fmt = model_config.getRunpathFormat()
    jobname_fmt = model_config.getJobnameFormat()
    subst_list = None
    run_context = ErtRunContext.ensemble_smoother(
        sim_fs, target_fs, mask, path_fmt, jobname_fmt, subst_list, 0
    )
    es_update.smootherUpdate(run_context)

    conf = ert.ensembleConfig()["SNAKE_OIL_PARAM"]
    sim_node = EnkfNode(conf)
    target_node = EnkfNode(conf)

    node_id = NodeId(0, 0)
    sim_node.load(sim_fs, node_id)
    target_node.load(target_fs, node_id)

    sim_gen_kw = list(sim_node.asGenKw())
    target_gen_kw = list(target_node.asGenKw())

    # Test that the localized values has been updated
    assert sim_gen_kw[1:3] != target_gen_kw[1:3]

    # test that all the other values are left unchanged
    assert sim_gen_kw[3:] == target_gen_kw[3:]
    assert sim_gen_kw[0] == target_gen_kw[0]

    assert target_gen_kw == pytest.approx(expected_target_gen_kw)
Esempio n. 2
0
    def test_large_case(self):
        with open("config", "w") as fp:
            fp.write(
                """NUM_REALIZATIONS 10
GRID             CASE.EGRID
FIELD            PORO    PARAMETER    poro.grdecl INIT_FILES:fields/poro%d.grdecl
SUMMARY          WBHP
OBS_CONFIG       observations.txt
TIME_MAP timemap.txt
"""
            )

        for f in ["timemap.txt", "observations.txt"]:
            src_file = self.createTestPath(os.path.join("local/row_scaling", f))
            shutil.copy(src_file, "./")
        # The grid size must be greater than 250000 (the default matrix size in
        # enkf_main_update())
        grid = EclGridGenerator.create_rectangular((70, 70, 70), (1, 1, 1))
        grid.save_EGRID("CASE.EGRID")
        res_config = ResConfig(user_config_file="config")
        main = EnKFMain(res_config)
        init_fs = init_data(main)

        # Configure the local updates
        local_config = main.getLocalConfig()
        local_config.clear()
        local_data = local_config.createDataset("LOCAL")
        local_data.addNode("PORO")
        obs = local_config.createObsdata("OBSSET_LOCAL")
        obs.addNode("WBHP0")
        ministep = local_config.createMinistep("MINISTEP_LOCAL")
        ministep.attachDataset(local_data)
        ministep.attachObsset(obs)
        updatestep = local_config.getUpdatestep()
        updatestep.attachMinistep(ministep)

        # Apply the row scaling
        row_scaling = local_data.row_scaling("PORO")
        ens_config = main.ensembleConfig()
        poro_config = ens_config["PORO"]
        field_config = poro_config.getFieldModelConfig()
        grid = main.eclConfig().getGrid()
        row_scaling.assign(field_config.get_data_size(), ScalingTest(grid))
        es_update = ESUpdate(main)
        update_fs = main.getEnkfFsManager().getFileSystem("target2")
        run_context = ErtRunContext.ensemble_smoother_update(init_fs, update_fs)
        es_update.smootherUpdate(run_context)