|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +import gempy as gp |
| 4 | +import time |
| 5 | + |
| 6 | +PLOT = True |
| 7 | +DENSE_RESOLUTION = [20, 20, 20] |
| 8 | + |
| 9 | + |
| 10 | +def test_compute_time_dense_dense(): |
| 11 | + geo_model: gp.data.GeoModel = _setup_model() |
| 12 | + geo_model.interpolation_options.evaluation_options.mesh_extraction = True |
| 13 | + |
| 14 | + geo_model.grid.active_grids = gp.data.Grid.GridTypes.DENSE |
| 15 | + start_time = time.perf_counter() |
| 16 | + gp.compute_model(geo_model) |
| 17 | + print(f"Computing model on grids: {geo_model.grid.active_grids}") |
| 18 | + end_time = time.perf_counter() |
| 19 | + computation_time_dense_I = end_time - start_time |
| 20 | + |
| 21 | + start_time = time.perf_counter() |
| 22 | + gp.compute_model(geo_model) |
| 23 | + print(f"Computing model on grids: {geo_model.grid.active_grids}") |
| 24 | + end_time = time.perf_counter() |
| 25 | + computation_time_dense_II = end_time - start_time |
| 26 | + |
| 27 | + print(f"Computation only model dense grid 125*50*50: {computation_time_dense_I:.2f} seconds") |
| 28 | + print(f"Computation only model dense grid 125*50*50: {computation_time_dense_II:.2f} seconds") |
| 29 | + |
| 30 | + # Assert that it is not too different |
| 31 | + assert abs(computation_time_dense_I - computation_time_dense_II) < 0.2 |
| 32 | + |
| 33 | + |
| 34 | +def test_compute_time_topo_dense_grid(): |
| 35 | + geo_model: gp.data.GeoModel = _setup_model() |
| 36 | + |
| 37 | + geo_model.grid.active_grids = gp.data.Grid.GridTypes.DENSE |
| 38 | + start_time = time.perf_counter() |
| 39 | + gp.compute_model(geo_model) |
| 40 | + print(f"Computing model on grids: {geo_model.grid.active_grids}") |
| 41 | + end_time = time.perf_counter() |
| 42 | + computation_time_dense = end_time - start_time |
| 43 | + |
| 44 | + # Compute a solution for the model |
| 45 | + geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY |
| 46 | + start_time = time.perf_counter() |
| 47 | + gp.compute_model(geo_model) |
| 48 | + print(f"Computing model on grids: {geo_model.grid.active_grids}") |
| 49 | + end_time = time.perf_counter() |
| 50 | + computation_time_topo = end_time - start_time |
| 51 | + |
| 52 | + # Recompute model as a new grid was added |
| 53 | + geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY | gp.data.Grid.GridTypes.DENSE |
| 54 | + start_time = time.perf_counter() |
| 55 | + gp.compute_model(geo_model) |
| 56 | + print(f"Computing model on grids: {geo_model.grid.active_grids}") |
| 57 | + end_time = time.perf_counter() |
| 58 | + computation_time_topo_dense = end_time - start_time |
| 59 | + |
| 60 | + print(f"Computation only model dense grid 125*50*50: {computation_time_dense:.2f} seconds") |
| 61 | + print(f"Computation time with topography 125*50: {computation_time_topo:.2f} seconds") |
| 62 | + print(f"Computation time with topography and dense grid 125*50*50: {computation_time_topo_dense:.2f} seconds") |
| 63 | + |
| 64 | + # Assert that dense takes longer than topo and that the sum of both is close |
| 65 | + assert computation_time_dense > computation_time_topo |
| 66 | + assert computation_time_topo_dense > computation_time_dense |
| 67 | + |
| 68 | + |
| 69 | +def test_compute_time_custom_dense_grid(): |
| 70 | + geo_model: gp.data.GeoModel = _setup_model() |
| 71 | + |
| 72 | + # numpy array with random coordinates within the extent of the model |
| 73 | + custom_coordinates = np.random.uniform( |
| 74 | + low=geo_model.grid.extent[:3], |
| 75 | + high=geo_model.grid.extent[3:], |
| 76 | + size=(1000, 3) |
| 77 | + ) |
| 78 | + |
| 79 | + start_time = time.perf_counter() |
| 80 | + gp.compute_model_at(geo_model, custom_coordinates) |
| 81 | + end_time = time.perf_counter() |
| 82 | + computation_time_at = end_time - start_time |
| 83 | + |
| 84 | + print(f"Computation compute_at with 1000 custom points: {computation_time_at:.2f} seconds") |
| 85 | + |
| 86 | + |
| 87 | +def _setup_model(): |
| 88 | + # Define the path to data |
| 89 | + data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' |
| 90 | + path_to_data = data_path + "/data/input_data/jan_models/" |
| 91 | + # Create a GeoModel instance |
| 92 | + geo_model = gp.create_geomodel( |
| 93 | + project_name='EGU_example', |
| 94 | + extent=[0, 2500, 0, 1000, 0, 1000], |
| 95 | + resolution=DENSE_RESOLUTION, |
| 96 | + importer_helper=gp.data.ImporterHelper( |
| 97 | + path_to_orientations=path_to_data + "model7_orientations.csv", |
| 98 | + path_to_surface_points=path_to_data + "model7_surface_points.csv" |
| 99 | + ) |
| 100 | + ) |
| 101 | + # Map geological series to surfaces |
| 102 | + gp.map_stack_to_surfaces( |
| 103 | + gempy_model=geo_model, |
| 104 | + mapping_object={ |
| 105 | + "Fault_Series" : ('fault'), |
| 106 | + "Strat_Series1": ('rock3'), |
| 107 | + "Strat_Series2": ('rock2', 'rock1'), |
| 108 | + } |
| 109 | + ) |
| 110 | + # Define youngest structural group as fault |
| 111 | + gp.set_is_fault(geo_model, ["Fault_Series"]) |
| 112 | + # Setting a randomly generated topography |
| 113 | + gp.set_topography_from_random( |
| 114 | + grid=geo_model.grid, |
| 115 | + fractal_dimension=2, |
| 116 | + d_z=np.array([700, 950]), |
| 117 | + topography_resolution=np.array([125, 50]) |
| 118 | + ) |
| 119 | + return geo_model |
0 commit comments