Пример #1
0
    def test_run_simulation_adjust_dt_2_steps(self, mocker):
        """ We should have one step in first phase and two steps in second phase"""
        # Faux setup of Time Machine
        phase_limits = [0, 1, 2]
        steps = [1.2, 0.5]
        time_params = TimeStepProtocol.create_protocol(phase_limits, steps)
        setup = Flow(
            BaseParameters(folder_name=Path(__file__).parent /
                           "results/test_time_machine"))
        newton = NewtonParameters()
        time_machine = TimeMachinePhasesConstantDt(setup, newton, time_params)

        # Patch time_iteration(), which is called in run_simulation()
        mocker.patch("GTS.time_machine.TimeMachine.time_iteration")
        # Patch setup.after_simulation(), which is called in run_simulation()
        mocker.patch("GTS.Flow.after_simulation")

        # Run the simulation
        time_machine.run_simulation(prepare_simulation=False)

        # Check that time_iteration was called 3 times
        assert TimeMachine.time_iteration.call_count == 3
        # Check that after_simulation was called exactly once
        Flow.after_simulation.assert_called_once()  # noqa

        # Check parameters of the Time Machine
        assert time_machine.k_time == 3
        # Time step should be adjusted to dt=1 since the suggested dt=1.2 > 1 (= 1 - 0)
        assert np.isclose(time_machine.current_time_step, 0.5)
        assert np.isclose(time_machine.current_time, 2)
Пример #2
0
    def test_run_simulation_one_time_step(self, mocker):
        """ Test procedure with only one time step."""
        # Faux setup of Time Machine
        phase_limits = [0, 1]
        steps = [1.2]
        time_params = TimeStepProtocol.create_protocol(phase_limits, steps)
        setup = Flow(
            BaseParameters(folder_name=Path(__file__).parent /
                           "results/test_time_machine"))
        newton = NewtonParameters()
        time_machine = TimeMachinePhasesConstantDt(setup, newton, time_params)

        # Patch time_iteration(), which is called in run_simulation()
        mocker.patch("GTS.time_machine.TimeMachine.time_iteration")
        # Patch setup.after_simulation(), which is called in run_simulation()
        mocker.patch("GTS.Flow.after_simulation")

        # Run the simulation
        time_machine.run_simulation(prepare_simulation=False)

        # Check that time_iteration was called exactly once
        TimeMachine.time_iteration.assert_called_once()
        # Check that after_simulation was called exactly once
        Flow.after_simulation.assert_called_once()  # noqa

        # Check parameters of the Time Machine
        assert time_machine.k_time == 1
        # Time step should be adjusted to dt=1 since the suggested dt=1.2 > 1 (= 1 - 0)
        assert np.isclose(time_machine.current_time_step, 1)
        assert np.isclose(time_machine.current_time, 1)
Пример #3
0
def box_validation():
    biot_params, newton_params, time_params = prepare_params(
        length_scale=0.01,
        scalar_scale=1e6,
    )
    setup = ISCBoxModel(biot_params, lcin=5 * 1.5, lcout=50 * 1.5)
    time_machine = TimeMachinePhasesConstantDt(setup, newton_params,
                                               time_params)

    time_machine.run_simulation()
    return time_machine
Пример #4
0
def validation():
    biot_params, newton_params, time_params = prepare_params(
        length_scale=0.01,
        scalar_scale=1e6,
    )
    setup = ISCBiotContactMechanics(biot_params)
    time_machine = TimeMachinePhasesConstantDt(setup, newton_params,
                                               time_params)

    time_machine.run_simulation()
    return time_machine
Пример #5
0
def simple_validation():
    """ Validation on Ivar setup"""
    # Grid
    gb, box, mesh_args = create_grid()

    # Injection phases and time configuration
    start_time = -1e2 * pp.YEAR
    end_time = 15 * pp.YEAR
    phase_limits = [start_time, 0, 10 * 3600, end_time]
    rates = [0, 75, 20]
    injection_protocol = InjectionRateProtocol.create_protocol(phase_limits, rates)

    phase_time_steps = [-start_time, 2.0, 2 / 3 * pp.HOUR]
    time_params = TimeStepProtocol.create_protocol(phase_limits, phase_time_steps)

    # Newton
    newton_params = NewtonParameters(convergence_tol=1e-6, max_iterations=15,)

    # Model parameters
    biot_params = BiotParameters(
        # BaseParameters
        length_scale=15,
        scalar_scale=1e9,
        base=Path("/home/haakonervik/mastersproject-data"),
        head="validation_example",
        time=time_params.start_time,
        time_step=time_params.initial_time_step,
        end_time=time_params.end_time,
        gravity=True,
        rock=IvarGranite(),
        # GeometryParameters
        shearzone_names=["f1", "f2", "f3"],
        box=box,
        mesh_args=mesh_args,
        # MechanicsParameters
        dilation_angle=np.radians(5.0),
        newton_options=newton_params.dict(),
        # FlowParameters
        well_cells=_tag_ivar_well_cells,
        injection_protocol=injection_protocol,
        frac_transmissivity=5.17e-3,  # Gives a0=2e-3, which are Ivar's values.
        # BiotParameters
        alpha=0.8,
    )
    setup = ISCBiotContactMechanics(biot_params)
    setup.gb = gb

    time_machine = TimeMachinePhasesConstantDt(setup, newton_params, time_params)

    time_machine.run_simulation()
    return time_machine
Пример #6
0
    def test_determine_time_step_from_phase(self):
        # Create protocol with two phases.
        phase1 = TimeStepPhase(start_time=0, end_time=1, data=0.5)
        phase2 = TimeStepPhase(start_time=1, end_time=2, data=0.2)
        time_params = TimeStepProtocol([phase1, phase2])
        tm = TimeMachinePhasesConstantDt(None, None, time_params)  # noqa

        # Check initial time
        assert tm.current_time == phase1.start_time

        # Check that new (right) phase is chosen at boundary
        tm.current_time = 1.0
        current_dt = tm.determine_time_step()
        assert current_dt == 0.2

        # Check that time step is adjusted if boundary is hit
        tm.current_time = 0.8
        current_dt = tm.determine_time_step()
        assert np.isclose(current_dt, 0.2)

        # Check that final time step is hit
        tm.current_time = 1.9
        current_dt = tm.determine_time_step()
        assert np.isclose(current_dt, 0.1)
Пример #7
0
        case,
        length_scale=1.0,
        scalar_scale=1e11,
    )
    # *2 gives ~25kc on 4fracs.
    # l=0.3, lcin 5*5*l, lcout 50*10*l
    # lcin = 5*10 lcout = 50*20

    # For 4frac setups:
    # lcin=5*1.4, lcout=50*1.4 --> 44k*3d + 5k*2d + 50*1d
    # lcin=5*10.3, lcout=50*10.4 --> 3k*3d + 200*2d + 9*1d
    # lcin=5*5.4, lcout=50*5.4 --> 6k*3d + 500*2d + 15*1d
    # lcin=5*3, lcout=50*3 --> 12k*3d + 1.2k*2d + 27*1d
    # lcin=5*2, lcout=50*2 --> 22k*3d, 2.5k*2d + 39*1d
    setup = ISCBoxModel(biot_params, lcin=5 * 2, lcout=50 * 2)
    time_machine = TimeMachinePhasesConstantDt(setup, newton_params,
                                               time_params)

    if run:
        time_machine.run_simulation()
    return time_machine


def isc_dt_and_injection_protocol(tunnel_time: float):
    """ Stimulation protocol for the rate-controlled phase of the ISC experiment

    Here, we consider Doetsch et al (2018) [see e.g. p. 78/79 or App. J]
            Hydro Shearing Protocol:
            * Injection Cycle 3:
                - Four injection steps of 10, 15, 20 and 25 l/min
                - Each step lasts 10 minutes.
                - Then, the interval is shut-in and monitored for 40 minutes.
def simple_validation():
    """ Validation on easy setup"""
    path = Path(__file__).parent / "results"
    # Grid
    mesh_size = 20
    gb, box, mesh_args = two_intersecting_blocking_fractures(
        str(path), mesh_size)

    # Injection phases and time configuration
    start_time = -1e2 * pp.YEAR
    phase_limits = [start_time, 0, 12 * pp.HOUR]
    rates = [0, 0]
    injection_protocol = InjectionRateProtocol.create_protocol(
        phase_limits, rates)

    phase_time_steps = [-start_time, 2.0 * pp.MINUTE]
    time_params = TimeStepProtocol.create_protocol(phase_limits,
                                                   phase_time_steps)

    # Newton
    newton_params = NewtonParameters(
        convergence_tol=1e-6,
        max_iterations=50,
    )

    rock = GrimselGranodiorite()
    rock.FRICTION_COEFFICIENT = 0.2
    stress = np.diag(-np.array([6, 13.1, 6]) * pp.MEGA * pp.PASCAL)
    # Model parameters
    biot_params = BiotParameters(
        # BaseParameters
        length_scale=15,
        scalar_scale=1e9,
        folder_name=path,
        time=time_params.start_time,
        time_step=time_params.initial_time_step,
        end_time=time_params.end_time,
        gravity=False,
        rock=rock,
        # GeometryParameters
        shearzone_names=["f1", "f2"],
        box=box,
        mesh_args=mesh_args,
        # MechanicsParameters
        stress=stress,
        dilation_angle=np.radians(5.0),
        newton_options=newton_params.dict(),
        # FlowParameters
        well_cells=nd_injection_cell_center,
        injection_protocol=injection_protocol,
        frac_transmissivity=5.17e-3,  # Gives a0=2e-3, which are Ivar's values.
        # BiotParameters
        alpha=0.8,
    )
    setup = ISCBiotContactMechanics(biot_params)
    setup.gb = gb

    time_machine = TimeMachinePhasesConstantDt(setup, newton_params,
                                               time_params)

    time_machine.run_simulation()
    return time_machine