spectre.Visualization.TransformVolumeData

Functions

get_tensor_component_names(tensor_name, ...)

Lists all independent components like 'Vector_x', 'Vector_y', etc.

parse_input_names(ctx, param, all_values)

parse_kernel_arg(arg, map_input_names[, ...])

Determine how data for a kernel function argument will be retrieved

parse_kernel_output(output, output_name, ...)

Transform the return value of a kernel to a dict of tensor datasets

parse_kernels(kernels, exec_files, ...[, ...])

parse_pybind11_signatures(callable)

snake_case_to_camel_case(s)

snake_case to CamelCase

transform_volume_data(volfiles, kernels[, ...])

Transforms data in the 'volfiles' with a sequence of 'kernels'

Classes

ElementArg(element_attr)

Kernel argument retrieved from an element in the computational domain

Kernel(callable, output_name[, ...])

KernelArg()

Subclasses provide data for a kernel function argument

TensorArg(tensor_type, dataset_name[, ...])

Kernel argument loaded from a volume file tensor dataset

class spectre.Visualization.TransformVolumeData.ElementArg(element_attr: str)

Kernel argument retrieved from an element in the computational domain

element_attr: str
get(all_tensor_data: Dict[str, Any], element: Element)

Get the data that will be passed to the kernel function

class spectre.Visualization.TransformVolumeData.Kernel(callable, output_name: str | None, map_input_names: Dict[str, str] = {}, elementwise: bool | None = None, interactive: bool = False)
class spectre.Visualization.TransformVolumeData.KernelArg

Subclasses provide data for a kernel function argument

get(all_tensor_data: Dict[str, Any], element: Element)

Get the data that will be passed to the kernel function

class spectre.Visualization.TransformVolumeData.TensorArg(tensor_type: Type[Any], dataset_name: str, extract_single_component: bool = False)

Kernel argument loaded from a volume file tensor dataset

property component_names
dataset_name: str
extract_single_component: bool = False
get(all_tensor_data: Dict[str, Any], element: Element | None)

Get the data that will be passed to the kernel function

tensor_type: Type[Any]
spectre.Visualization.TransformVolumeData.get_tensor_component_names(tensor_name: str, tensor_type: Type[Any]) List[str]

Lists all independent components like ‘Vector_x’, ‘Vector_y’, etc.

spectre.Visualization.TransformVolumeData.parse_input_names(ctx, param, all_values)
spectre.Visualization.TransformVolumeData.parse_kernel_arg(arg: Parameter, map_input_names: Dict[str, str], interactive: bool = False) KernelArg

Determine how data for a kernel function argument will be retrieved

Examines the name and type annotation of the argument. The following arguments are supported:

  • Mesh: Annotate the argument with a ‘Mesh’ type.

  • ElementId: Annotate the argument with an ‘ElementId’ type.

  • Coordinates: Annotate the argument with a ‘tnsr.I’ type and name it

    “logical_coords” / “logical_coordinates” or “inertial_coords” / “inertial_coordinates” / “x”.

  • Jacobians: Annotate the argument with a ‘Jacobian’ or ‘InverseJacobian’.

  • Any tensor dataset: Annotate the argument with the tensor type, e.g.

    ‘Scalar[DataVector]’ or ‘tnsr.ii[DataVector, 3]’.

For example, the following function is a possible kernel:

def one_index_constraint(

psi: Scalar[DataVector], mesh: Mesh[3], inv_jacobian: InverseJacobian[DataVector, 3],

) -> tnsr.i[DataVector, 3]:

# …

The function can also be a binding of a C++ function, such as this:

tnsr::i<DataVector, 3> one_index_constraint(

const Scalar<DataVector>& psi, const Mesh<3>& mesh, const InverseJacobian<

DataVector, 3, Frame::ElementLogical, Frame::Inertial>& inv_jacobian) {

// …

}

The annotation of the ‘psi’ argument is ‘Scalar[DataVector]’, so a scalar dataset will be read from the volume data. If ‘interactive’ is True, the user will be prompted for the dataset name to read for ‘psi’, otherwise the ‘map_input_names’ must contain a dataset name for ‘psi’. In addition, the mesh and inverse Jacobian will be read from the volume data and passed to the function.

Parameters:
  • arg – The function argument. Must have a type annotation.

  • map_input_names – A map of argument names to dataset names.

  • interactive – Optional (default is False). Prompt the user for missing dataset names.

Returns: A ‘KernelArg’ object that knows how to retrieve the data for the

argument.

spectre.Visualization.TransformVolumeData.parse_kernel_output(output, output_name: str | None, num_points: int) Dict[str, Any]

Transform the return value of a kernel to a dict of tensor datasets

The following return values of kernels are supported:

  • Any Tensor.

  • A DataVector: will be treated as a scalar.

  • A Numpy array: will be treated as a scalar or vector.

  • An int or float: will be expanded over the grid as a constant scalar.

  • A dict of the above: can be used to return multiple datasets, and to assign names to them. The keys of the dictionary are used as dataset names.

  • A list of the above: can be used to visualize output from C++ bindings that return a std::array or std::vector. For example, a C++ binding named truncation_error that returns 3 numbers (one per dimension) per element can be visualized with this. The three numbers get expanded as constants over the volume of the element and returned as three datasets named ‘TruncationError(_1,_2,_3)’.

Parameters:
  • output – The return value of a kernel function.

  • output_name – The dataset name. Unused if ‘output’ is a dict.

  • num_points – Number of grid points.

Returns: A mapping from dataset names to tensors.

spectre.Visualization.TransformVolumeData.parse_kernels(kernels, exec_files, map_input_names, interactive=False)
spectre.Visualization.TransformVolumeData.parse_pybind11_signatures(callable) Iterable[Signature]
spectre.Visualization.TransformVolumeData.snake_case_to_camel_case(s: str) str

snake_case to CamelCase

spectre.Visualization.TransformVolumeData.transform_volume_data(volfiles: H5Vol | Iterable[H5Vol], kernels: Sequence[Kernel], integrate: bool = False, force: bool = False) None | Dict[str, Sequence[float]]

Transforms data in the ‘volfiles’ with a sequence of ‘kernels’

Parameters:
  • volfiles – Iterable of open H5 volume files, or a single H5 volume file. Must be opened in writable mode, e.g. in mode “a”. The transformed data will be written back into these files. All observations in these files will be transformed.

  • kernels – List of transformations to apply to the volume data in the form of ‘Kernel’ objects.

  • integrate – Compute the volume integral over the kernels instead of writing them back into the volume files. The integral is computed in inertial coordinates for every tensor component of all kernels and over all observations in the volume files. For example, if a kernel returns a vector named ‘Shift’ then this function returns integrals named ‘Shift(_x,_y,_z)’. In addition, the corresponding observation values are returned (named ‘Time’), and the inertial volume (named ‘Volume’).

  • force – Overwrite existing datasets in the volume files (default: False).

Returns:

None, or the volume integrals if ‘integrate’ is True.