Version:

salvus.mesh.layered_meshing.utils.split_layered_model

salvus.mesh.layered_meshing.utils.split_layered_model salvus mesh layered_meshing utils split_layered_model
Functions for splitting layered models.

Functions

split_layered_model()

Split a layered model with a predicate that takes a Layer as input.
The predicate will be applied to the layered model layer-by-layer in top-down order. The first time a predicate returns True for a given layer, the layered model is split at that layer's top interface. To be clear, splitting the following model:
LayeredModel([
        interface.Hyperplane.at(1.0),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.66),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.33),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.0),
    ])
with the predicate:
`lambda lay: lay.bot.max_elevation == 0.33`
will result in the return value of:
```
(
    LayeredModel([
        interface.Hyperplane.at(1.0),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.66),
    ]),
    LayeredModel([
        interface.Hyperplane.at(0.66),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.33),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.0),
    ])
)
```
while the predicate:
`lambda lay: lay.top.max_elevation = 0.33`
would instead result in the return value of:
```
(
    LayeredModel([
        interface.Hyperplane.at(1.0),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.66),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.33),
    ]),
    LayeredModel([
        interface.Hyperplane.at(0.33),
        material.acoustic.Velocity.from_params(rho=1.0, vp=1.0),
        interface.Hyperplane.at(0.0),
    ])
)
```
It may be that the predicate returns True for the top layer, or that it returns False for all layers. In the first case, the return value of this function will be:
`(None, layered_model)`
signifying that all layers are located below the split. Likewise, if the predicate returns False for all layers, the return value of this function will be:
`(layered_model, None)`
signifying that all layers are located above the split.
Finally: the caller is responsible for ensuring that their layered model is complete, i.e. that is has bounding interfaces. If this is not the case, an exception will be thrown.
SIGNATURE
def split_layered_model(
    layered_model: LayeredModel, predicate: typing.Callable[[Layer], bool]
) -> tuple[LayeredModel | None, LayeredModel | None]: ...
ARGUMENTS
Required
layered_model
Type:LayeredModel
Description:
The layered model to split.
Required
predicate
Type:typing.Callable[[Layer], bool]
Description:
A callable taking a layer as input, and returning True to signify that a split should be done at the top of the layer, otherwise returning False.
RETURNS
Return type: tuple[LayeredModel | None, LayeredModel | None]
A tuple of two layered models which have been split from the input layered model as described above. Either of the tuple elements may be None if a split has not occurred.
PAGE CONTENTS