Deck Handling

This section documents the utilities for handling OSIRIS input decks.

InputDeckIO

class osiris_utils.decks.decks.InputDeckIO(filename: str, verbose: bool = False)Source

Class to handle parsing/re-writing of OSIRIS input decks

Parameters:
  • filename (str) – Path to OSIRIS input deck file.

  • verbose (bool) – If True, prints additional information when parsing file. Helpful for debugging issues if input deck parsing fails.

filenameSource

Path to original input file used to create the InputDeckIO object.

Type:

str

sectionsSource

List of pairs (section_name: str, section_dict: dict) which contain current state of InputDeckIO object.

Type:

list[dict]

dimSource

Number of dimensions in the simulation (1, 2, or 3).

Type:

int

Class to handle parsing and modifying OSIRIS input decks.

Key Features:

  • Parse input decks into python objects

  • Modify parameters programmatically

  • Save modified decks to new files

  • Automatic handling of OSIRIS syntax idiosyncrasies

Usage Example:

from osiris_utils import InputDeckIO

# Load an input deck
deck = InputDeckIO("osiris.inp")

# Get simulation dimension
print(f"Simulation dimension: {deck.dim}")

# Modify a parameter
# (Assuming there is a 'time_step' section with 'dt' parameter)
deck.set_param("time_step", "dt", "0.05")

# Save to a new file
deck.print_to_file("osiris_modified.inp")
set_param(section, param, value, i_use=None, unexistent_ok=False)Source

Set a parameter value in the input deck.

Parameters:
  • section (str) – The name of the section where the parameter is located.

  • param (str) – The name of the parameter to set.

  • value (str or list or int or float) – The value to set. If a list, it is converted to a comma-separated string.

  • i_use (int or list of int, optional) – The index(es) of the section(s) to modify if multiple sections with the same name exist. If None, all sections with the matching name are modified.

  • unexistent_ok (bool, optional) – If True, allows setting a parameter that does not currently exist in the section. Default is False.

Raises:

KeyError – If the section is not found, or if the parameter is not found (and unexistent_ok is False).

set_tag(tag, value)Source

Replace a tag in all parameters within the input deck. This is useful for template replacement.

Parameters:
  • tag (str) – The tag substring to search for (e.g., “<TAG>”).

  • value (str or int or float) – The value to replace the tag with.

get_param(section, param)Source

Get the value(s) of a parameter from a specific section.

Parameters:
  • section (str) – The name of the section.

  • param (str) – The name of the parameter.

Returns:

values (list) – A list of values for the parameter. Returns a list because there can be multiple sections with the same name.

Raises:

KeyError – If the parameter is not found in one of the sections.

delete_param(section, param)Source

Delete a parameter from a specific section.

Parameters:
  • section (str) – The name of the section.

  • param (str) – The name of the parameter to delete.

print_to_file(filename)Source

Write the current state of the input deck to a file.

Parameters:

filename (str) – The path to the output file.

__getitem__(section)Source
property filenameSource
property sectionsSource
property dimSource
property n_speciesSource
property speciesSource

Coordinate Conversion

osiris_utils.decks.decks.deval()
deval(x)Source

Auxiliar to handle eval of Fortran formatted numbers (e.g. 1.4d-5)