Esempio n. 1
0
    def test_active_time_step(self):
        phase1 = TimeStepPhase(start_time=0, end_time=1, data=0.1)
        phase2 = TimeStepPhase(start_time=1, end_time=2, data=0.2)
        tsp = TimeStepProtocol([phase1, phase2])

        # Check middle-of-phase
        assert np.isclose(tsp.active_time_step(0.5), 0.1)

        # Check boundary
        assert np.isclose(tsp.active_time_step(1.0), 0.2)

        # Check start time and end time
        assert np.isclose(tsp.active_time_step(0), 0.1)
        assert np.isclose(tsp.active_time_step(2), 0.2)
    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)
    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)
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
Esempio n. 5
0
def isc_dt_and_injection_protocol():
    """ 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.
                - Venting was foreseen at 20 minutes

            For this setup, we only consider Injection Cycle 3.
    """
    _1min = pp.MINUTE
    _10min = 10 * _1min
    initialization_time = 30e3 * pp.YEAR
    phase_limits = [
        -initialization_time,
        0,
        _10min,
        # 2 * _10min,
        # 3 * _10min,
        # 4 * _10min,
        # 7 * _10min,
    ]
    rates = [
        0,
        10,
        # 15,
        # 20,
        # 25,
        # 0,
    ]
    rates = [r / 60 for r in rates]  # Convert to litres / second
    injection_protocol = InjectionRateProtocol.create_protocol(
        phase_limits, rates)

    time_steps = [
        initialization_time / 3,
        _1min,
        # _1min,
        # _1min,
        # _1min,
        # 3 * _1min,
    ]
    time_step_protocol = TimeStepProtocol.create_protocol(
        phase_limits, time_steps)

    return injection_protocol, time_step_protocol
def create_protocols():
    """ Create a test injection protocol"""
    _1min = pp.MINUTE
    phase_limits = [
        0,
        50 * pp.MINUTE,
        100 * pp.MINUTE,
    ]
    rates = [
        0,
        10 / 60,
    ]
    inj_protocol = InjectionRateProtocol.create_protocol(phase_limits, rates)
    time_steps = [
        10 * pp.MINUTE,
        20 * pp.MINUTE,
    ]
    dt_protocol = TimeStepProtocol.create_protocol(phase_limits, time_steps)
    return inj_protocol, dt_protocol
Esempio n. 7
0
def _hs1_protocols_optimal_scaling():
    """ Stimulation protocol for the rate-controlled phase of HS1
    """
    _1min = pp.MINUTE
    _5min = 5 * _1min
    phase_limits = [
        0,
        1 * _5min,  # 5 min
    ]
    rates = [
        15,  # C3, step 1
    ]
    rates = [r / 60 for r in rates]  # Convert to litres / second
    injection_protocol = InjectionRateProtocol.create_protocol(
        phase_limits, rates)

    time_steps = [1 * _1min]
    time_step_protocol = TimeStepProtocol.create_protocol(
        phase_limits, time_steps)

    return injection_protocol, time_step_protocol
    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)
Esempio n. 9
0
    def test_monotone_phase_check(self):
        phase1 = TimeStepPhase(start_time=0, end_time=1.1, data=0.1)
        phase2 = TimeStepPhase(start_time=1, end_time=2, data=0.2)

        with pytest.raises(AssertionError):
            tsp = TimeStepProtocol([phase1, phase2])
Esempio n. 10
0
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.
                - Venting was foreseen at 20 minutes

            For this setup, we only consider Injection Cycle 3.

    Parameters
    ----------
        tunnel_time : float
            AU, VE tunnels were constructed 30 years ago.
    """
    assert tunnel_time > 0
    _1min = pp.MINUTE
    _5min = 5 * _1min
    _10min = 10 * _1min
    initialization_time = 30e3 * pp.YEAR
    phase_limits = [
        -initialization_time,
        -tunnel_time,
        0,
        # S1,       5 min
        1 * _5min,
        # S2,       5 min
        2 * _5min,
        # S3,       5 min
        3 * _5min,
        # S4,       5 min
        4 * _5min,
        # S5,       15 min
        7 * _5min,
        # shut-in,  46 min
        81 * _1min,
        # Venting,  29 min
        11 * _10min,
    ]
    rates = [
        0,  # initialization
        0,  # tunnel calibration
        15,  # C3, step 1
        20,  # C3, step 2
        25,  # C3, step 3
        30,  # C3, step 4
        35,  # C3, step 5
        0,  # shut-in
        0,  # venting (currently modelled as: shut-in)
    ]
    rates = [r / 60 for r in rates]  # Convert to litres / second
    injection_protocol = InjectionRateProtocol.create_protocol(
        phase_limits, rates)

    time_steps = [
        initialization_time / 2,
        tunnel_time / 2,
        1 * _1min,  # S1, 5min
        5 * _1min,  # S2, 5min
        5 * _1min,  # S3, 5min
        5 * _1min,  # S4, 5min
        15 * _1min,  # S5, 15min
        16 * _1min,  # shut-in, 46min
        15 * _1min,  # venting
    ]
    time_step_protocol = TimeStepProtocol.create_protocol(
        phase_limits, time_steps)

    return injection_protocol, time_step_protocol
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