|
| 1 | +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
| 2 | +# Copyright (c) 2025 Mira Geoscience Ltd. ' |
| 3 | +# ' |
| 4 | +# This file is part of simpeg-drivers package. ' |
| 5 | +# ' |
| 6 | +# simpeg-drivers is distributed under the terms and conditions of the MIT License ' |
| 7 | +# (see LICENSE file at the root of this source code package). ' |
| 8 | +# ' |
| 9 | +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
| 10 | + |
| 11 | +import numpy as np |
| 12 | +from discretize import TreeMesh |
| 13 | +from discretize.utils import mesh_builder_xyz |
| 14 | +from geoh5py.objects import Octree, Points, Surface |
| 15 | +from octree_creation_app.driver import OctreeDriver |
| 16 | +from octree_creation_app.utils import treemesh_2_octree |
| 17 | + |
| 18 | + |
| 19 | +def get_base_octree( |
| 20 | + survey: Points, |
| 21 | + topography: Surface, |
| 22 | + cell_size: tuple[float, float, float], |
| 23 | + refinement: tuple, |
| 24 | + padding: float, |
| 25 | +) -> TreeMesh: |
| 26 | + """ |
| 27 | + Generate a survey centered TreeMesh object with topography refinement. |
| 28 | +
|
| 29 | + :param survey: Survey object with vertices that define the core of the |
| 30 | + tensor mesh. |
| 31 | + :param topography: Surface used to refine the topography. |
| 32 | + :param cell_size: Tuple defining the cell size in all directions. |
| 33 | + :param refinement: Tuple containing the number of cells to refine at each |
| 34 | + level around the topography. |
| 35 | + :param padding: Distance to pad the mesh in all directions. |
| 36 | +
|
| 37 | + :return mesh: The discretize TreeMesh object for computations. |
| 38 | + """ |
| 39 | + padding_distance = np.ones((3, 2)) * padding |
| 40 | + mesh = mesh_builder_xyz( |
| 41 | + survey.vertices - np.r_[cell_size] / 2.0, |
| 42 | + cell_size, |
| 43 | + depth_core=100.0, |
| 44 | + padding_distance=padding_distance, |
| 45 | + mesh_type="TREE", |
| 46 | + tree_diagonal_balance=False, |
| 47 | + ) |
| 48 | + mesh = OctreeDriver.refine_tree_from_surface( |
| 49 | + mesh, topography, levels=refinement, finalize=False |
| 50 | + ) |
| 51 | + |
| 52 | + return mesh |
| 53 | + |
| 54 | + |
| 55 | +def get_octree_mesh( |
| 56 | + survey: Points, |
| 57 | + topography: Surface, |
| 58 | + cell_size: tuple[float, float, float], |
| 59 | + refinement: tuple, |
| 60 | + padding_distance: float, |
| 61 | + refine_on_receivers: bool, |
| 62 | + name: str = "mesh", |
| 63 | +) -> Octree: |
| 64 | + """Generate a survey centered mesh with topography and survey refinement. |
| 65 | +
|
| 66 | + :param survey: Survey object with vertices that define the core of the |
| 67 | + tensor mesh and the source refinement for EM methods. |
| 68 | + :param topography: Surface used to refine the topography. |
| 69 | + :param cell_size: Tuple defining the cell size in all directions. |
| 70 | + :param refinement: Tuple containing the number of cells to refine at each |
| 71 | + level around the topography. |
| 72 | + :param padding: Distance to pad the mesh in all directions. |
| 73 | + :param refine_on_receivers: Refine on the survey locations or not. |
| 74 | +
|
| 75 | + :return entity: The geoh5py Octree object to store the results of |
| 76 | + computation in the shared cells of the computational mesh. |
| 77 | + :return mesh: The discretize TreeMesh object for computations. |
| 78 | + """ |
| 79 | + |
| 80 | + mesh = get_base_octree(survey, topography, cell_size, refinement, padding_distance) |
| 81 | + |
| 82 | + if refine_on_receivers: |
| 83 | + mesh = OctreeDriver.refine_tree_from_points( |
| 84 | + mesh, survey.vertices, levels=[2], finalize=False |
| 85 | + ) |
| 86 | + |
| 87 | + mesh.finalize() |
| 88 | + entity = treemesh_2_octree(survey.workspace, mesh, name=name) |
| 89 | + |
| 90 | + return entity |
0 commit comments