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
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 prepare_params( length_scale, scalar_scale, ) -> Tuple[BiotParameters, NewtonParameters, TimeStepProtocol]: """ Validation on the ISC grid""" injection_protocol, time_params = isc_dt_and_injection_protocol() newton_params = NewtonParameters( convergence_tol=1e-6, max_iterations=200, ) sz = 10 # path = Path(__file__).parent / "isc_simulation/200830/box-test/t1-gravity" root = Path.home() path = root / "mastersproject-data/results/200830/5f-50kc/t1" biot_params = BiotParameters( # BaseParameters length_scale=length_scale, scalar_scale=scalar_scale, # base=Path("/home/haakonervik/mastersproject-data"), # head="validation_example", folder_name=path, time_step=time_params.initial_time_step, end_time=time_params.end_time, gravity=True, # GeometryParameters shearzone_names=["S1_1", "S1_2", "S1_3", "S3_1", "S3_2"], mesh_args={ "mesh_size_frac": sz, "mesh_size_min": 0.1 * sz, "mesh_size_bound": 3 * sz, }, bounding_box=None, # MechanicsParameters dilation_angle=np.radians(3), newton_options=newton_params.dict(), # FlowParameters well_cells=shearzone_injection_cell, injection_protocol=injection_protocol, frac_transmissivity=[5e-8, 1e-9, 5e-10, 3.7e-7, 1e-9], # Initial transmissivites for # ["S1_1", "S1_2", "S1_3", "S3_1", "S3_2"]: # [5e-8, 1e-9, 5e-10, 3.7e-7, 1e-9] ) return biot_params, newton_params, time_params
def params(tmpdir_factory): inj, dt = create_protocols() newton_params = NewtonParameters(convergence_tol=1e-6, max_iterations=10,) path = tmpdir_factory.mktemp("results") biot_params = BiotParameters( # BaseParameters length_scale=0.04, scalar_scale=1e8, folder_name=path, time_step=dt.initial_time_step, end_time=dt.end_time, # GeometryParameters shearzone_names=["S1_1", "S1_2", "S1_3", "S3_1"], # MechanicsParameters newton_options=newton_params, # FlowParameters frac_transmissivity=1e-8, ) return biot_params, newton_params, dt
length_scale, scalar_scale, k, box, case=None, ) -> Tuple[BiotParameters, NewtonParameters, TimeStepProtocol]: """ Hydro shearing experiment HS1 HS1 targeted S1.3 through INJ2 at 39.75 - 40.75 m. """ tunnel_equilibration_time = 30 * pp.YEAR injection_protocol, time_params = isc_dt_and_injection_protocol( tunnel_equilibration_time) newton_params = NewtonParameters( convergence_tol=5e-5, max_iterations=300, ) base = Path.home() / "mastersproject-data/hs1" head = f"final/case_{case or '0'}" biot_params = BiotParameters( # BaseParameters length_scale=length_scale, scalar_scale=scalar_scale, base=base, head=head, time_step=time_params.initial_time_step, end_time=time_params.end_time, rock=GrimselGranodiorite( PERMEABILITY=k, ), # low k: 5e-21 -- high k: 2 * 5e-21 gravity=False, # GeometryParameters
def prepare_params( length_scale, scalar_scale, ) -> Tuple[BiotParameters, NewtonParameters, TimeStepProtocol]: """ Hydro shearing experiment HS1 HS1 targeted S1.3 through INJ2 at 39.75 - 40.75 m. """ tunnel_equilibration_time = 30 * pp.YEAR injection_protocol, time_params = _hs1_protocols_optimal_scaling() newton_params = NewtonParameters( convergence_tol=1e-6, max_iterations=300, ) biot_params = BiotParameters( # BaseParameters length_scale=length_scale, scalar_scale=scalar_scale, use_temp_path=True, # Use a temporary directory for storing mesh time_step=time_params.initial_time_step, end_time=time_params.end_time, rock=GrimselGranodiorite( PERMEABILITY=5e-21, # low k: 5e-21 -- high k: 2 * 5e-21 ), gravity=False, # GeometryParameters shearzone_names=[ "S1_1", "S1_2", "S1_3", "S3_1", # TODO: This is the wrong S3 shear zone. ], # "S3_2"], # ["S1_2", "S3_1"], fraczone_bounding_box={ "xmin": -1, "ymin": 80, "zmin": -5, # -5, # Extended frac zone boundary box test "xmax": 86, # +10, "ymax": 151, # +5, "zmax": 41, # +5, }, # MechanicsParameters dilation_angle=np.radians(3), # FlowParameters source_scalar_borehole_shearzone={ "shearzone": "S1_3", "borehole": "INJ2", }, well_cells=shearzone_injection_cell, tunnel_equilibrium_time= tunnel_equilibration_time, # TODO: Think about initial conditions for scaling injection_protocol=injection_protocol, frac_transmissivity=[ 5e-8, 1e-9, 8.3e-11, # Pre-stimulation T during HS1, observed in S1.3-INJ2. 3.7e-7, # 1e-9, ], # Initial transmissivites for # ["S1_1", "S1_2", "S1_3", "S3_1", "S3_2"]: # [5e-8, 1e-9, 5e-10, 3.7e-7, 1e-9] # Note background hydraulic conductivity: 1e-14 m/s # near_injection_transmissivity=8.3e-11, # near_injection_t_radius=3, ) return biot_params, newton_params, time_params
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