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
Layerclass 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.
botinterface.Interface — The bottom layer (smaller vertical coordinate).modmaterial.PhysicalMaterial — The bounded model.topinterface.Interface — The top layer (larger vertical coordinate).linear_solidsLinearSolids | typing.Literal['skip_validation_linear_solids'] | None — Any linear solids associated with the layer._indexint | None — An optional index specifying the position of this layer with respect to its neighbors. Required for some reduction algorithms.
bot_realized ConcreteInterface
bot_realized ConcreteInterfaceReturn the bottom interface as a curve or a surface.
bounds LayerBounds
bounds LayerBoundsGet this layer’s bounding interfaces.
index int | None
index int | NoneGet the optional index of this layer.
interfaces tuple[interface.Interface, interface.Interface]
interfaces tuple[interface.Interface, interface.Interface]Get a tuple of the (bottom, top) interface.
model material.PhysicalMaterial
model material.PhysicalMaterialGet the model.
strata list[interface.Interface | material.PhysicalMaterial]
strata list[interface.Interface | material.PhysicalMaterial]Get this layer’s ordered strata.
top_realized ConcreteInterface
top_realized ConcreteInterfaceReturn the top interface as a curve or a surface.
v_ref tuple[float, float]
v_ref tuple[float, float]Get the reference elevations of the (bottom, top) layers.
bounds_da()
bounds_da()def bounds_da(self, d: DomainBounds) -> xr.DataArray: ...Get the bounds of this layer as a DataArray.
dDomainBounds — The domain bounds.
map()
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.
ftyping.Callable[[str, typing.Any], tuple[str, typing.Any]] — The function to map over the dataclass.
replace_bounds()
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.
new_topinterface.Interface | None — The new top interface, or None to keep the current interface.new_botinterface.Interface | None — The new bottom interface, or None to keep the current interface.
LayerBounds
LayerBoundsclass LayerBounds(builtins.object):
def __init__(
self, top: interface.Interface, bot: interface.Interface
) -> None: ...The bounding interfaces of a layer.
topinterface.Interface — The top interface.botinterface.Interface — The bottom interface.
from_coords()
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.
topfloat | interface.Height | interface.Depth — The top interface.botfloat | interface.Height | interface.Depth — The bottom interface.
interp_like()
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.
likexr.DataArray — TheDataArrayon which to interpolate this interface.
replace_bounds()
replace_bounds()def replace_bounds(
self,
top: interface.Interface | None = None,
bot: interface.Interface | None = None,
) -> typing.Self: ...Replace one or both bounds.
topinterface.Interface | None — The new top bound, orNoneif the current bound is to be kept.botinterface.Interface | None — The new bottom bound, orNoneif the current bound is to be kept.
LayerBounds with the specified bounds replaced.