Mondaic

salvus.opt.models.unstructured_model

salvus.opt.models.unstructured_model salvus opt models unstructured_model

An unstructured mesh model.

Functions

retrieve_valence_and_mass_matrix()

def retrieve_valence_and_mass_matrix(
    model_a: UnstructuredModel, model_b: UnstructuredModel
) -> tuple[npt.NDArray, npt.NDArray]: ...

Get the valence and mass matrix from the model that has them.

This method will check both models for presence of the valence and mass matrix as fields, and fall back to computing them if neither model has them.

If the model should deal with a region_of_interest, it should be accounted for in the model fields and on-mesh fields already, and the on-the-fly computation will not return appropriate values.

Parameters
  • model_a UnstructuredModel — First model.
  • model_b UnstructuredModel — Second model.
Returns tuple[npt.NDArray, npt.NDArray] — A tuple containing the valence and mass matrix (FemMassMatrix as defined by SalvusCompute) from the model that has them, otherwise computed on the fly.

Classes

UnstructuredModel

class UnstructuredModel(salvus.opt.models.base_model.BaseModel):
    def __init__(
        self,
        name: str,
        model: str | pathlib.Path | UnstructuredMesh,
        fields: list[str],
    ): ...

Unstructured mesh inversion model.

Parameters
  • name str — Name of the model.
  • model str | pathlib.Path | UnstructuredMesh — The unstructured mesh.
  • fields list[str] — Names of the elemental fields to use.
Attributes
FemMassMatrix npt.NDArray[np.float64]

The mass matrix as SalvusCompute would write it.

mass_matrix npt.NDArray[np.float64]

The mass matrix as defined on the mesh, without valence scaling.

model UnstructuredMesh

The actual dataset representing the model.

name str

Model name.

status ModelStatus

Model status to keep track of whether the model has been modified.

valence npt.NDArray[np.float64]

The valence as defined on the mesh.

vector npt.NDArray[np.float64]

The unstructured mesh model as a vector.

Methods
from_disk()
def from_disk(parent_folder: pathlib.Path, d: dict) -> Self: ...

Load a model from disk. This will use the dictionary and path provided.

Parameters
  • parent_folder pathlib.Path — Path to store the model.
  • d dict — Dictionary containing meta information of the model.
Returns Self
from_json()
def from_json(d: dict) -> Self: ...

Create a model from a dictionary.

Parameters
  • d dict — Dictionary containing meta information of the model.
Returns Self
compute_inf_norm()
def compute_inf_norm(self) -> float: ...

Infinity norm of the model.

Returns float
compute_norm()
def compute_norm(self) -> float: ...

Return the model norm.

Returns float
copy()
def copy(self, name: str) -> Self: ...

Copy the model.

Will load the model from disk if necessary, and leave it in memory.

Parameters
  • name str — Name of the new model.
Returns Self — A copy of the model with the new name. Always fully in memory.
dot()
def dot(self, other: Self) -> float: ...

Dot product of the model with another model.

Parameters
  • other Self — The other model.
Returns float — The dot product as a float.
max()
def max(self, other: Self) -> Self: ...

In-place point-wise maximum.

Parameters
  • other Self — Model to compare with.
Returns Self — A reference to the modified input model, i.e., self.
min()
def min(self, other: Self) -> Self: ...

In-place point-wise minimum.

Parameters
  • other Self — Model to compare with.
Returns Self — A reference to the modified input model, i.e., self.
set_vector()
def set_vector(self, vector: npt.NDArray[np.float64]) -> None: ...

Set the model from a vector.

Parameters
  • vector npt.NDArray[np.float64] — The vector to set the model from.
Returns None
to_disk()
def to_disk(self, parent_folder: pathlib.Path | str) -> dict: ...

Serialize the model to JSON (and an associated npy file).

Parameters
  • parent_folder pathlib.Path | str — Parent folder where the JSON + h5 files should be stored.
Returns dict — A dictionary containing meta information of the serialized model.
to_json()
def to_json(
    self,
    external_file_hash: types = None,
    timer: types = None,
    log_to_logger: bool = False,
    comm: types = None,
) -> builtins.dict: ...

Serialize the object to a dictionary that can be written to JSON.

Parameters
  • external_file_hash types — Hash of any external files associated with this object. Can be passed here in which case it will be stored in a centralized location in the JSON file.
  • timer types — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm types — MPI communicator, if any.
Returns builtins.dict

Used in tutorials