scivianna.interface package
Scivianna Interface Module
The interface module provides data interfaces for reading simulation results from various file formats. Interfaces abstract data access and provide a unified API for visualization.
Files
File |
Description |
|---|---|
|
Package initialization file, registers available interfaces |
|
Base class |
|
Interface for Salome MED file format |
|
Interface for VTK/VTU file formats |
|
Interface for CSV time-series data |
|
Interface for structured mesh data |
|
Utility class for time-indexed data frames |
Interface Hierarchy
GenericInterface (Base Class)
Provides core functionality for all interfaces:
Function |
Description |
|---|---|
|
Reads input files to extract data |
|
Returns list of available fields/results |
|
Returns whether a field is colored by string or float values |
|
Returns list of loaded files with descriptions |
|
Serializes objects for multiprocessing queue transmission |
|
Saves interface state to a pickle file |
|
Loads interface state from a pickle file |
|
Returns a ComputeSlave instance for the interface class |
Data Capability Interfaces
Interfaces inherit from these capability classes based on what they provide:
Interface |
Purpose |
|---|---|
|
Provides 2D cell geometry and field values |
|
Provides 2D geometry as a list of polygons |
|
Provides 2D geometry as a numpy array (rasterized) |
|
Provides values at specific locations/cells/materials |
|
Provides 1D data profiles at locations |
|
Extracts data along user-defined lines |
|
Supports runtime coupling updates (C3PO/Icoco) |
Geometry2D Interface
Extends GenericInterface with 2D geometry capabilities:
Function |
Description |
|---|---|
|
Returns 2D geometry polygons for a given frame |
|
Returns cell name to field value mapping |
Geometry2DPolygon Interface
Subclass of Geometry2D that provides polygon-based geometry. Inherits all Geometry2D methods.
Geometry2DGrid Interface
Subclass of Geometry2D that provides grid-based (rasterized) geometry. Inherits all Geometry2D methods.
ValueAtLocation Interface
Provides point-value access capabilities:
Function |
Description |
|---|---|
|
Returns field value at a specific location/cell/material |
|
Returns field values at multiple locations/cells/materials |
Value1DAtLocation Interface
Provides 1D data profile access:
Function |
Description |
|---|---|
|
Returns 1D data series (pd.Series) at a specific location/cell/material |
OverLine Interface
Provides line-based data extraction:
Function |
Description |
|---|---|
|
Returns field values along a 1D line as a pandas DataFrame |
CouplingInterface
Provides runtime coupling capabilities for C3PO/Icoco integration:
Function |
Description |
|---|---|
|
Sets the current time for coupling updates |
|
Replaces interface data with new value |
|
Appends data associated with current time |
|
Replaces interface mesh and data with new value |
|
Appends mesh and data associated with current time |
|
Returns template for C3PO getOutputxxxFieldTemplate functions |
|
Sets the template for C3PO functions |
Available Interfaces
MED Interface
Reads Salome MED files containing:
Mesh geometry (2D/3D)
Field data on cells/nodes
Time-step information
from scivianna.interface.med_interface import MEDInterface
interface = MEDInterface()
interface.read_file("result.med")
labels = interface.get_labels() # ["temperature", "pressure", ...]
VTK Interface
Reads VTK/VTU files for unstructured grids:
Polygon/polyhedron cells
Point and cell data
Multiple time steps
CSV Interface
Reads structured CSV data:
Time-series results
Column-based variables
Automatic parsing with pandas
Creating Custom Interfaces
Custom interfaces can be easily created, the scivianna.interface.generic_interface file defines what functions need to be provided for a new interface.
from scivianna.interface.generic_interface import GenericInterface, Geometry2D
class MyCustomInterface(GenericInterface, Geometry2D):
def read_file(self, filepath):
# Implement file reading logic
pass
def get_labels(self):
# Return available field names
return ["field1", "field2"]
def get_geometry_2d(self, field_name):
# Return 2D geometry for the field
pass
Interface Registration
Built-in interfaces are automatically discovered and registered via __init__.py. Additional user interfaces can be implemeted by calling:
from scivianna.interface import register_interface
register_interface("MyInterfaceKey", MyInterfaceClass)
Submodules
scivianna.interface.csv_result module
scivianna.interface.generic_interface module
- class scivianna.interface.generic_interface.CouplingInterface
Bases:
GenericInterfaceInterface parent class to implement the C3PO functions required for a code coupling visualization.
- append_data(key: str, data: Any)
Stores the data and associates it to the current time.
- Parameters:
key (str) – Data associated key
data (Any) – New value
- append_mesh(key: str, data: Any)
Stores the data and mesh and associate them to the current time.
- Parameters:
key (str) – Data associated key
data (Any) – New value
- get_template(name: str)
Returns the template for the C3PO getOutputxxxFieldTemplate functions
- Parameters:
name (str) – Field name
- set_template(name: str, template: Any)
Sets the template returned by C3PO getOutputxxxFieldTemplate functions
- Parameters:
name (str) – Field name
template (Any) – Object to set as template
- set_time(time: float)
This non-Icoco function allows setting the current time in an interface to associate to the received value.
- Parameters:
time (float) – Current time
- update_data(key: str, data: Any)
Replaces the interface data by the current value
- Parameters:
key (str) – Data associated key
data (Any) – New value
- update_mesh(key: str, data: Any)
Replaces the interface data and mesh by the current value
- Parameters:
key (str) – Data associated key
data (Any) – New value
- class scivianna.interface.generic_interface.GenericInterface
Bases:
objectGeneric interface class that implement basic functions. This class mutualises functions that are shared between its child classes.
- extensions = []
Extensions associated to this interface.
- get_file_input_list() List[Tuple[str, str]]
Returns a list of file label and its description for the GUI
- Returns:
List of (file label, description)
- Return type:
List[Tuple[str, str]]
- Raises:
NotImplementedError – The function was not implemented in the code interface.
- get_label_coloring_mode(label: str) VisualizationMode
Returns wheter the given field is colored based on a string value or a float.
- Parameters:
label (str) – Field to color name
- Returns:
Coloring mode
- Return type:
- Raises:
NotImplementedError – Function to override in the code interfaces
- get_labels() List[str]
Returns a list of fields names displayable with this interface
- Returns:
List of fields names
- Return type:
List[str]
- classmethod get_slave()
- load(file_path: Path, include_files: bool)
Pickle loads the slave content to a file, allows slave state reload
- Two modes are available:
If include_files is at True, all loaded data are saved, the pickled file can be loaded on its own to recover last session.
If include_files is at False, only the computed data are loaded, enabling faster first computation allowing a smaller pickle file size.
- Parameters:
file_path (Path) – File from which load the slave
include_files (bool) – Included loaded file
- read_file(file_path: str, file_label: str) None
Read a file and store its content in the interface
- Parameters:
file_path (str) – File to read
file_label (str) – Label to define the file type
- Raises:
NotImplementedError – Function to override in the code interfaces
- save(file_path: Path, include_files: bool)
Pickle saves the slave content to a file, allows slave state reload.
- Two modes are available:
If include_files is at True, all loaded data are saved, the pickled file can be loaded on its own to recover last session.
If include_files is at False, only the computed data are loaded, enabling faster first computation allowing a smaller pickle file size.
- Parameters:
file_path (Path) – File in which save the file
include_files (bool) – Included loaded file
- classmethod serialize(obj: Any, key: str) Any
This function receives an object that is about to be transmitted at the given key. - If the object can be passed through a python multiprocessing Queue, it can be returned. - If the object can’t, it is serialized, and the code returns the file path.
The read function will then be able to expect the returned object at the given key.
By default, this class returns the obj, if the cobject can’t be passed, overwrite this function.
- Parameters:
obj (Any) – Object that is sent to the generic interface
key (str) – Key associated to the object
- Returns:
Object transmissible through a multiprocessing Queue associated to the given object.
- Return type:
Any
- class scivianna.interface.generic_interface.Geometry2D
Bases:
GenericInterfaceInterface parent class for classes that can compute geometry 2D slices.
- compute_2D_data(u: Tuple[float, float, float], v: Tuple[float, float, float], u_min: float, u_max: float, v_min: float, v_max: float, w_value: float, q_tasks: Queue, options: Dict[str, Any], caller: str = 'API') Tuple[Data2D, bool]
Returns a list of polygons that defines the geometry in a given frame
- Parameters:
u (Tuple[float, float, float]) – Horizontal coordinate director vector
v (Tuple[float, float, float]) – Vertical coordinate director vector
u_min (float) – Lower bound value along the u axis
u_max (float) – Upper bound value along the u axis
v_min (float) – Lower bound value along the v axis
v_max (float) – Upper bound value along the v axis=
w_value (float) – Value along the u ^ v axis
q_tasks (mp.Queue) – Queue from which get orders from the master.
options (Dict[str, Any]) – Additional options for frame computation.
caller (str) – Identifier of the caller requesting the computation (default: “API”)
- Returns:
Data2D – Geometry to display
bool – Were the polygons updated compared to the past call
- Raises:
NotImplementedError – Function to override in the code interfaces
- geometry_type: GeometryType
Enum telling if the geometry is 2D or 3D (Displays the axis card and the w coordinate in the GUI).
- get_value_dict(value_label: str, cells: List[int | str], options: Dict[str, Any], caller: str = 'API') Dict[int | str, str]
Returns a cell name - field value map for a given field name
- Parameters:
value_label (str) – Field name to get values from
cells (List[Union[int,str]]) – List of cells names
options (Dict[str, Any]) – Additional options for frame computation.
caller (str) – Identifier of the caller requesting the computation (default: “API”)
- Returns:
Field value for each requested cell names
- Return type:
Dict[Union[int,str], str]
- Raises:
NotImplementedError – Function to override in the code interfaces
- rasterized: bool = False
Boolean telling if the geometry is made by rasterizing a 2D grid (displays the line count in the GUI).
- class scivianna.interface.generic_interface.Geometry2DGrid
Bases:
Geometry2DInterface parent class for classes that can compute geometry 2D slices and provide a numpy array.
- rasterized: bool = True
Boolean telling if the geometry is made by rasterizing a 2D grid (displays the line count in the GUI).
- class scivianna.interface.generic_interface.Geometry2DPolygon
Bases:
Geometry2DInterface parent class for classes that can compute geometry 2D slices and provide a list of polygons.
- class scivianna.interface.generic_interface.OverLine
Bases:
GenericInterfaceInterface parent class to implement a function to compute a field value along a 1D line.
- compute_1D_line_data(pos: Tuple[float, float, float], u: Tuple[float, float, float], d: float, q_tasks: Queue, options: Dict[str, Any]) DataFrame
Returns a list of polygons that defines the geometry in a given frame
- Parameters:
pos (Tuple[float, float, float]) – 1D data line start location
u (Tuple[float, float, float]) – Data line direction vector
d (float) – Distance to travel by the 1D line
q_tasks (mp.Queue) – Queue from which get orders from the master.
options (Dict[str, Any]) – Additional options for frame computation.
- Returns:
Pandas dataframe containing the data
- Return type:
pd.DataFrame
- Raises:
NotImplementedError – Function to override in the code interfaces
- class scivianna.interface.generic_interface.Value1DAtLocation
Bases:
GenericInterfaceInterface parent class to implement a function to get 1D data at a specific location.
- get_1D_value(position: Tuple[float, float, float], cell_index: str, material_name: str, field: str, options: Dict[str, Any] = None) Series | List[Series]
Provides the 1D value of a field from either the (x, y, z) position, the cell index, or the material name.
- Parameters:
position (Tuple[float, float, float]) – Position at which the value is requested
cell_index (str) – Index of the requested cell
material_name (str) – Name of the requested material
field (str) – Requested field name
options (Dict[str, Any], optional) – Additional options for 1D value computation.
- Returns:
Field value
- Return type:
Union[pd.Series, List[pd.Series]]
- class scivianna.interface.generic_interface.ValueAtLocation
Bases:
GenericInterfaceInterface parent class to implement a function to get values at a specific location.
- get_value(position: Tuple[float, float, float], cell_index: str, material_name: str, field: str, options: Dict[str, Any] = None) str | float
Provides the result value of a field from either the (x, y, z) position, the cell index, or the material name.
- Parameters:
position (Tuple[float, float, float]) – Position at which the value is requested
cell_index (str) – Index of the requested cell
material_name (str) – Name of the requested material
field (str) – Requested field name
options (Dict[str, Any], optional) – Additional options for value computation.
- Returns:
Field value
- Return type:
Union[str, float]
- get_values(positions: List[Tuple[float, float, float]], cell_indexes: List[str], material_names: List[str], field: str, options: Dict[str, Any] = None) List[str | float]
Provides the result values at different positions from either the (x, y, z) positions, the cell indexes, or the material names.
- Parameters:
positions (List[Tuple[float, float, float]]) – List of position at which the value is requested
cell_indexes (List[str]) – Indexes of the requested cells
material_names (List[str]) – Names of the requested materials
field (str) – Requested field name
options (Dict[str, Any], optional) – Additional options for value computation.
- Returns:
Field values
- Return type:
List[Union[str, float]]