salvus.mesh.tools.transforms
A set of tools to transform meshes and the models they contain.
Functions
interpolate_mesh_to_mesh()
interpolate_mesh_to_mesh()def interpolate_mesh_to_mesh(
mesh_0: salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh,
mesh_1: salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh,
use_layers: bool,
use_1d_vertical_coordinate: bool,
verbose: bool = True,
exclude_filter: Optional[Tuple[str, int]] = None,
fields_to_interpolate: Optional[str, List[str]] = None,
) -> (
salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh
): ...Interpolate element nodal material parameters from mesh_0 to mesh_1.
It is often desirable to interpolate material parameters from one mesh to another. This may be relevant, for example, when changing frequency bands in an ongoing full-waveform inversion, when performing a convergence analysis, when comparing the efficacy of different models, and when using advanced waveform inversion methodologies (i.e. Smoothiesem). In simplest case of a rectilinear -> rectilinear mesh the interpolation is relatively straightforward: interpolate the model stored on mesh_0 to mesh_1 by evaluating the model on mesh_0’s basis at the points defined by mesh_1.
For the case of deformed meshes, or models with discontinuities that must be preserved, the story gets a little more complicated. For example: what if the resolution of the new mesh’s topography is different than that of the old mesh? In this case, you may get aliasing around the discontinuities or along mesh edges. To remedy issues like this, this function implements several heuristic measures, which can be toggled by selecting the corresponding function arguments (see their descriptions).
As a general rule: any required extrapolations will be performed via a “clamping” approach, where the reference coordinates for a candidate model source element with be clamped to the reference interval [-1, +1]. This helps mitigate any “blow-ups” that could occur by evaluating the model basis too far outside of a given element. In the end, this means that the interpolation performed by this function may not be well defined in some cases. However, we feel that the measures chosen mitigate the most substantial issues, and should be sufficient for most use cases.
If any difficulties are encountered when using this function, please feel free to seek advice in Mondaic’s support forum.
mesh_0salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh — Source mesh (interpolate parameters from here).mesh_1salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh — Destination mesh (interpolate parameters to here).use_layersbool — Search for the elemental parameterlayerin both meshes and, if it exists, restrict the interpolation to matching layers. Useful (in fact, likely essential) when working with models containing discontinuities which should be preserved. Will throw isuse_layersis not present as an element nodal field in either mesh.use_1d_vertical_coordinatebool — Search for the element nodal parameterz_node_1Din both meshes and, if it exists, use it to “flatten” any topography before the interpolation occurs. Setting this to true is consistent with what happens when doing certain model interpolations, for instance when considering the interpolation of aMantleModelor aCrustalModel. In those cases the models are interpolated using the spherical 1-D radial coordinate before topographic deformations are applied.verbosebool — Print a progress bar outlining the overall progress of the interpolation routine. Defaults to True.exclude_filterOptional[Tuple[str, int]] — Exclude from the interpolation elements which have a a certain elemental flag set as anelemental_field. A tuple should be passed containing("elemental_field_name", field value). Elements flagged will be excluded from the interpolation in both meshes.fields_to_interpolateOptional[str, List[str]] — Optional list of fields to interpolate. If not given, all valid material parameters defined on mesh_0 will be interpolated.
mesh_0 interpolated onto the topology of mesh_1.uniformly_refine()
uniformly_refine()def uniformly_refine(
mesh: salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh,
tensor_order: int,
refinement_order: int = 2,
change_tensor_order_kwargs: Dict = {},
use_high_order_node_locations: bool = True,
) -> (
salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh
): ...Refine an unstructured mesh by subdividing all elements uniformly.
This function works by splitting each element evenly into 4 elements in 2-D, and 8 elements in 3-D, resulting in a new mesh with exactly 4 or 8 times as many elements as were present before. Model re-interpolation (of element-nodal fields) from and to arbitrary tensor_orders are supported. Elemental fields and global variables are copied over as well.
A common and practical use case for this function is to increase the frequency band of an ongoing inversion.
meshsalvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh — The mesh which should be refined.tensor_orderint — The tensor_order of the new refined mesh.refinement_orderint — The number of subdivisions per dimension, e.g. 2 will lead to a subdivision of a hex into 8 hexes or a quad into 4 quadschange_tensor_order_kwargsDict — internally, UnstructuredMesh.change_tensor_order() is used to create the new points as well as to set the tensor order of the new mesh. This dictionary can be used to pass additional arguments such as for spherical interpolation. See the docstring of change_tensor_order for details.use_high_order_node_locationsbool — create new nodes based on the high order shape of the original mesh. Cannot be used together with change_tensor_order_kwargs.
uniformly_refine_chunkwise()
uniformly_refine_chunkwise()def uniformly_refine_chunkwise(
mesh: salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh,
output_filename: str,
nchunk: int = 10,
show_progress: bool = True,
uniformly_refine_kwargs: Dict = {},
) -> None: ...Refine an unstructured mesh by subdividing all elements uniformly, working through the mesh in chunks to avoid a memory bottleneck. The mesh is merged and directly written to a file.
See docstring of uniformly_refine for more details
meshsalvus.mesh.data_structures.unstructured_mesh.unstructured_mesh.UnstructuredMesh — The mesh which should be refined.output_filenamestr — Filename of the mesh file (h5 format).nchunkint — The number of chunks to use.show_progressbool — show a progress bar while refining & merging.uniformly_refine_kwargsDict — dictionary of arguments passed to uniformly_refine