Mondaic

salvus.mesh.layered_meshing.layered_model.layer

salvus.mesh.layered_meshing.layered_model.layer salvus mesh layered_meshing layered_model layer

A single layer.

Classes

Layer

class Layer(salvus.utils.dataclass_utils.MappableDataclass):
    def __init__(
        self,
        bot: interface.Interface,
        mod: material.PhysicalMaterial,
        top: interface.Interface,
        linear_solids: (
            LinearSolids
            | typing.Literal["skip_validation_linear_solids"]
            | None
        ) = None,
        _index: int | None = None,
    ) -> None: ...

A layer consists of a model bounded by two interface.

Parameters
  • bot interface.Interface — The bottom layer (smaller vertical coordinate).
  • mod material.PhysicalMaterial — The bounded model.
  • top interface.Interface — The top layer (larger vertical coordinate).
  • linear_solids LinearSolids | typing.Literal['skip_validation_linear_solids'] | None — Any linear solids associated with the layer.
  • _index int | None — An optional index specifying the position of this layer with respect to its neighbors. Required for some reduction algorithms.
Attributes
bot_realized ConcreteInterface

Return the bottom interface as a curve or a surface.

bounds LayerBounds

Get this layer’s bounding interfaces.

index int | None

Get the optional index of this layer.

interfaces tuple[interface.Interface, interface.Interface]

Get a tuple of the (bottom, top) interface.

model material.PhysicalMaterial

Get the model.

strata list[interface.Interface | material.PhysicalMaterial]

Get this layer’s ordered strata.

top_realized ConcreteInterface

Return the top interface as a curve or a surface.

v_ref tuple[float, float]

Get the reference elevations of the (bottom, top) layers.

Methods
bounds_da()
def bounds_da(self, d: DomainBounds) -> xr.DataArray: ...

Get the bounds of this layer as a DataArray.

Parameters
  • d DomainBounds — The domain bounds.
Returns xr.DataArray — The layer bounds as a DataArray.
map()
def map(
    self, f: typing.Callable[[str, typing.Any], tuple[str, typing.Any]]
) -> typing.Self: ...

Generic map for dataclass instances.

f should be a function taking two parameters: the name of the dataclass member and its value, and it should return a tuple containing the same quantities. If a member is not to be transformed, f should just return a tuple of the input member name and value, unchanged. Both names and values can be transformed, with the semantics following those of dataclasses.replace.

In Salvus we primarily treat dataclasses as containers offering semantics similar to typed dictionaries. Deriving from this protocol allows any relevant dataclass to additionally be treated functorially. This allows for the generic un- and re-wrapping of value held in dataclasses, and essentially replaces the following imperative code:

@dataclass
class A:
    member: int

# Before
my_a = A(member=1)
my_a_new = dataclasses.replace(my_a, member=2 * my_a.member)

# After
my_a_new = A(val=1).map(lambda key, val: (key, 2 * val))

As with many functional patterns, the perceived benefits for simple demonstrative purposes is minimal. The scalability of this pattern becomes apparent, however, when parsing deeply nested abstractions, as the transformation logic can be factored out into independent functions. This is used extensively, for example, in the realization logic of the layered mesher, where generic materials can have generic parameters, etc.

Parameters
  • f typing.Callable[[str, typing.Any], tuple[str, typing.Any]] — The function to map over the dataclass.
Returns typing.Self — A new, potentially transformed, dataclass.
replace_bounds()
def replace_bounds(
    self,
    new_top: interface.Interface | None = None,
    new_bot: interface.Interface | None = None,
) -> Layer: ...

Optionally replace each boundary of this layer.

Parameters
  • new_top interface.Interface | None — The new top interface, or None to keep the current interface.
  • new_bot interface.Interface | None — The new bottom interface, or None to keep the current interface.
Returns Layer — A new layer with potentially modified bounding interfaces.

LayerBounds

class LayerBounds(builtins.object):
    def __init__(
        self, top: interface.Interface, bot: interface.Interface
    ) -> None: ...

The bounding interfaces of a layer.

Parameters
  • top interface.Interface — The top interface.
  • bot interface.Interface — The bottom interface.
Methods
from_coords()
def from_coords(
    top: float | interface.Height | interface.Depth,
    bot: float | interface.Height | interface.Depth,
) -> LayerBounds: ...

Construct the layer bounds from coordinate values.

Removes the burden of wrapping the input coordinates with Hyperplanes.

Parameters
  • top float | interface.Height | interface.Depth — The top interface.
  • bot float | interface.Height | interface.Depth — The bottom interface.
Returns LayerBounds — A set of layer bounds consisting of two hyperplanes.
interp_like()
def interp_like(self, like: xr.DataArray) -> typing.Self: ...

Interpolate bounding interfaces onto another DataArray’s coordinates.

Will call the interface’s extend method to ensure that it spans the coordinates spanned by other with the desired expansion behavior.

Parameters
  • like xr.DataArray — The DataArray on which to interpolate this interface.
Returns typing.Self — A new interpolated interface.
replace_bounds()
def replace_bounds(
    self,
    top: interface.Interface | None = None,
    bot: interface.Interface | None = None,
) -> typing.Self: ...

Replace one or both bounds.

Parameters
  • top interface.Interface | None — The new top bound, or None if the current bound is to be kept.
  • bot interface.Interface | None — The new bottom bound, or None if the current bound is to be kept.
Returns typing.Self — An instance of LayerBounds with the specified bounds replaced.