scivianna package

Subpackages

Submodules

scivianna.constants module

scivianna.enums module

class scivianna.enums.DataType(*values)

Bases: Enum

Are the data returned in a grid or polygons

GRID = 0

Data are contained in a numpy array

POLYGONS = 1

Data are contained in a list of polygons

class scivianna.enums.GeometryType(*values)

Bases: Enum

Is the geometry 2D or 3D.

class scivianna.enums.PlotType(*values)

Bases: Enum

Is the plot 1D or 2D.

class scivianna.enums.UpdateEvent(*values)

Bases: int, Enum

What triggers a plot update

CLIC = 1

The plot is updated when the mouse is clics on a 2D plot, the applicable plots are updated requesting the mouse space location.

MOUSE_CELL_CHANGE = 3

The plot is updated when the mouse is moved over a 2D plot and enters a new cell.

MOUSE_POSITION_CHANGE = 2

The plot is updated when the mouse is moved over a 2D plot, the applicable plots are updated requesting the mouse space location.

PERIODIC = 4

The plot is preiodically updated, applicable in real-time code coupling simulations

RANGE_CHANGE = 5

The plot is updated when the (u, v) ranges change

RECOMPUTE = 0

The plot is only updated by pressing the mouse button

class scivianna.enums.UpdatePolicy(*values)

Bases: Enum

This enum lets the user define how the code interface manages its fields update with time.

APPEND_DATA = 1

If applicable, the supporting mesh is keep constant during the simulation. The data is stored and associated to the current time.

APPEND_MESH = 3

If applicable, the supporting mesh is changes during the simulation: The data and its mesh are stored and associated to the current time. otherwise, the behavior is equivalent to APPEND_DATA.

UPDATE_DATA = 2

If applicable, the supporting mesh is keep constant during the simulation. The data is stored and replaces the last data.

UPDATE_MESH = 4

If applicable, the supporting mesh is changes during the simulation: The data and its mesh are stored and replace the last data. Without mesh, the behavior is equivalent to UPDATE_DATA.

class scivianna.enums.VisualizationMode(*values)

Bases: Enum

How is the color mapped on an input value.

FROM_STRING = 1

The color is got randomly based on the string value.

FROM_VALUE = 0

The color is got from a colormap based on a float value.

NONE = 2

Only the mesh is displayed

scivianna.notebook_tools module

scivianna.slave module

class scivianna.slave.ComputeSlave(code_interface: Type[GenericInterface], allow_errors: bool = False)

Bases: object

Class that creates a subprocess to interface with the code.

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

call_custom_function(function_name: str, arguments: Dict[str, Any])

Call an custom function meant to ease extension developments

Parameters:
  • function_name (str) – Name of the interface function

  • arguments (Dict[str, Any]) – Kwargs of the custom function

Returns:

Function return

Return type:

Any

code_interface: Type[GenericInterface]

Code interface class

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

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, coloring_label: str, options: Dict[str, Any], caller: str = 'API') Tuple[Data2D, bool]

Get the geometry from the interface

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.

  • coloring_label (str) – Field label to display

  • options (Dict[str, Any]) – Additional options for frame computation.

  • caller (str) – Identifier of the caller requesting the computation (default: “API”)

Returns:

Data2D object containing the geometry, whether the polygons were updated

Return type:

Tuple[Data2D, bool]

duplicate() ComputeSlave

Returns a duplicate of the current ComputeSlave. The copy is reseted, and reads the file history.

Returns:

ComputeSlave copy.

Return type:

ComputeSlave

file_read: List[Tuple[str, str]]

List of file read and their associated key.

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]]

get_file_input_list() List[Tuple[str, str]]

Get from the interface the list of files labels and their description

Returns:

List of (file label, description)

Return type:

List[Tuple[str, str]]

get_geometry_type() GeometryType

Returns the interface geometry type

Returns:

Interface geometry type

Return type:

GeometryType

get_label_coloring_mode(field_name: str) VisualizationMode

Returns the coloring mode of the plot

Parameters:

field_name (str) – Name of the displayed field

Returns:

Coloring mode

Return type:

VisualizationMode

get_labels() List[str]

Get from the interface the list of displayable labels (fields list)

Returns:

List of labels

Return type:

List[str]

get_result_or_error()

Gets the return value from the process. If an error was sent, raise the error instead.

Returns:

Any returned data from the process

Return type:

Any

Raises:

error – Any error sent by the slave

get_template(name: str)

Returns the template for the C3PO getOutputxxxFieldTemplate functions

Parameters:

name (str) – Field name

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_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]

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]]

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

p: Process

Subprocess hosting the worker

q_returns: Queue

Queue to get the results

q_tasks: Queue

Queue in which the tasks are pushed

read_file(file_path: str, file_label: str)

Forwards to the worker a file path to read and its associated label

Parameters:
  • file_path (str) – File to read

  • file_label (str) – File label

reset()

Kills the worker and create a new one.

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

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)

Set the current time in an interface to associate to the received value.

Parameters:

time (float) – Current time

terminate()

Terminates the subprocess

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

property update_policy

Returns the update_policy attribute from the interface

Returns:

The update_policy value

Return type:

Any

wait_available()
class scivianna.slave.SlaveCommand

Bases: object

Class defining the available commands that are forwarded to the compute slaves

APPEND_DATA = 'append_data'

Appends interface data

APPEND_MESH = 'append_mesh'

Appends interface mesh

COMPUTE_1D_LINE_DATA = 'compute_1d_line_data'

Compute a 1D result along a line

COMPUTE_2D_DATA = 'compute_2d_data'

Compute a 2D slice of the geometry

CUSTOM = 'custom'

Custom call to transfer to the interface to ease extension development

GET_1D_VALUE = 'get_1D_value'

Returns the 1Dvalue at a location/cell

GET_FILE_INPUT_LIST = 'get_file_input_list'

Returns the list of read input files

GET_GEOMETRY_TYPE = 'get_geometry_type'

Returns the geometry type

GET_LABELS = 'get_labels'

Returns the list of displayable fields

GET_LABEL_COLORING_MODE = 'get_label_coloring_mode'

Returns the coloring mode of a field

GET_TEMPLATE = 'get_template'

Gets field template

GET_UPDATE_POLICY = 'get_update_policy'

Gets the update policy attribute

GET_VALUE = 'get_value'

Returns the value at a location/cell

GET_VALUES = 'get_values'

Returns the value at a set of locations/cells

GET_VALUE_DICT = 'get_value_dict'

Returns the values of a field at cells

LOAD = 'load'

Pickle loads the slave state from a file

READ_FILE = 'read_file'

Reads an input file

SAVE = 'save'

Pickle saves the slave state to a file

SET_TEMPLATE = 'set_template'

Sets field template

SET_TIME = 'set_time'

Sets the current time

SET_UPDATE_POLICY = 'set_update_policy'

Sets the update policy attribute

UPDATE_DATA = 'update_data'

Updates interface data

UPDATE_MESH = 'update_mesh'

Updates interface mesh

scivianna.slave.worker(q_tasks: Queue, q_returns: Queue, q_errors: Queue, code_interface: Type[GenericInterface])

Creates a worker that will forward the panel requests to the GenericInterface on another process

Parameters:
  • q_tasks (mp.Queue) – Queue containing the tasks

  • q_returns (mp.Queue) – Queue to return the results

  • code_interface (Type[GenericInterface]) – GenericInterface to instanciate.

Module contents