Mondaic
This API reference is not for the latest stable Salvus version.

salvus.mesh.tools.transforms

A set of tools to transform meshes and the models they contain.

Functions

interpolate_mesh_to_mesh()

def interpolate_mesh_to_mesh(
    mesh_0: salvus.mesh.unstructured_mesh.UnstructuredMesh,
    mesh_1: salvus.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.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.

Parameters
  • mesh_0 salvus.mesh.unstructured_mesh.UnstructuredMesh — Source mesh (interpolate parameters from here).
  • mesh_1 salvus.mesh.unstructured_mesh.UnstructuredMesh — Destination mesh (interpolate parameters to here).
  • use_layers bool — Search for the elemental parameter layer in 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 is use_layers is not present as an element nodal field in either mesh.
  • use_1d_vertical_coordinate bool — Search for the element nodal parameter z_node_1D in 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 a MantleModel or a CrustalModel. In those cases the models are interpolated using the spherical 1-D radial coordinate before topographic deformations are applied.
  • verbose bool — Print a progress bar outlining the overall progress of the interpolation routine. Defaults to True.
  • exclude_filter Optional[Tuple[str, int]] — Exclude from the interpolation elements which have a a certain elemental flag set as an elemental_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_interpolate Optional[str, List[str]] — Optional list of fields to interpolate. If not given, all valid material parameters defined on mesh_0 will be interpolated.
Returns salvus.mesh.unstructured_mesh.UnstructuredMesh — An unstructured mesh with the parameters from mesh_0 interpolated onto the topology of mesh_1.

uniformly_refine()

def uniformly_refine(
    mesh: salvus.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.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.

Parameters
  • mesh salvus.mesh.unstructured_mesh.UnstructuredMesh — The mesh which should be refined.
  • tensor_order int — The tensor_order of the new refined mesh.
  • refinement_order int — 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 quads
  • change_tensor_order_kwargs Dict — 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_locations bool — create new nodes based on the high order shape of the original mesh. Cannot be used together with change_tensor_order_kwargs.
Returns salvus.mesh.unstructured_mesh.UnstructuredMesh — A new unstructured mesh, uniformly refined with the model re-interpolated and the relevant variables copied over.

uniformly_refine_chunkwise()

def uniformly_refine_chunkwise(
    mesh: salvus.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

Parameters
  • mesh salvus.mesh.unstructured_mesh.UnstructuredMesh — The mesh which should be refined.
  • output_filename str — Filename of the mesh file (h5 format).
  • nchunk int — The number of chunks to use.
  • show_progress bool — show a progress bar while refining & merging.
  • uniformly_refine_kwargs Dict — dictionary of arguments passed to uniformly_refine
Returns None