pytanksim.classes.basesimclass

Contains classes related exclusively to the dynamic simulations.

This includes SimParams, BoundaryFlux, and BaseSimulation.

Classes

SimParams

A class to store simulation parameters.

BoundaryFlux

Stores information of the mass and energy fluxes on the tank boundaries.

BaseSimulation

An abstract base class for dynamic simulations.

Module Contents

class pytanksim.classes.basesimclass.SimParams

A class to store simulation parameters.

This data class stores the parameters of the tank at the start of the simulation as well as the conditions specified to stop the simulation. Additionally, it also stores the setting for the number of data points to be reported at the end of the simulation.

init_temperature

The temperature (K) of the tank being simulated at the beginning of the simulation.

Type:

float

init_pressure

The pressure of the tank being simulated (Pa) at the beginning of the simulation. The default value is 1E5. This parameter was made optional as the two-phase simulations did not require it to be filled, rather pytanksim will automatically calculate the saturation pressure given a starting temperature.

Type:

float, optional

final_time

The time (seconds) at which the simulation is to be stopped.

Type:

float

init_time

The time (seconds) at which the beginning of the simulation is set to. The default value is set to 0 seconds.

Type:

float, optional

displayed_points

The number of data points to be reported at the end of the simulation. The default is 200.

Type:

int, optional

target_temp

The target temperature (K) at which the simulation is to be stopped. The default value is 0, which effectively means the simulation does not have a set temperature at which the simulation is stopped.

Type:

float, optional

target_pres

The target pressure (Pa) at which the simulation is to be stopped. The default value is 0, which effectively means the simulation does not have a set pressure at which the simulation is stopped.

Type:

float, optional

stop_at_target_pressure

If True, it will stop the simulation when the target pressure is met. The default is False.

Type:

bool, optional

stop_at_target_temp

If True, it will stop the simulation when the target temperature is met. The default is False.

Type:

bool, optional

target_capacity

The amount of fluid (moles) stored in the tank at which the simulation is to be stopped. The default is 0.

Type:

float, optional

init_ng

The initial amount of gas (moles) stored in the tank at the beginning of the simulation. The default value is 0.

Type:

float, optional

init_nl

The initial amount of liquid (moles) stored in the tank at the beginning of the simulation. The default value is 0.

Type:

float, optional

init_q

The initial quality of the fluid being stored. It can vary between 0 and 1. The default is None.

Type:

float, optional

Parameters:
  • inserted_amount (float, optional) – The amount of fluid which has been previously inserted into the tank (moles) at the beginning of the simulation. Used to track refueling processes across multiple simulations. The default value is 0.

  • vented_amount (float, optional) – The amount of fluid which has been previously vented from the tank (moles) at the beginning of the simulation. Used to track discharging and boil-off processes across multiple simulations. The default value is 0.

  • cooling_required (float, optional) – The cumulative amount of required cooling (J) to maintain a constant pressure prior to the start of a simulation. The default value is 0. Useful when restarting a stopped cooled refuel simulation.

  • heating_required (float, optional) – The cumulative amount of required heating (J) to maintain a constant pressure prior to the start of a simulation. The default value is 0. Useful when restarting a stopped heated discharge simulation.

  • vented_energy (float, optional) – Cumulative amount of enthaloy (J) contained in the fluid vented prior to the start of the simulation. The default is 0. Useful when stopping and restarting discharge simulations.

  • flow_energy_in (float, optional) – Cumulative amount of enthalpy (J) contained in the fluid inserted prior to the start of the simulation. The default is 0. Useful when stopping and restarting refueling simulations.

  • cooling_additional (float, optional) – The cumulative amount of user-specified cooling (J) prior to the start of a simulation. The default value is 0. Useful when stopping and restarting simulations with user-specified cooling.

  • heating_additional (float, optional) – The cumulative amount of user-specified cooling (J) prior to the start of a simulation. The default value is 0. Useful when stopping and restarting simulations with user-specified heating.

  • heat_leak_in (float, optional) – The cumulative amount of heat (J) which has leaked into the tank prior to the start of a simulation. The default value is 0. Useful when stopping and restarting simulations involving heat leakage.

  • verbose (bool, optional) – Whether or not the simulation will print out its progress bars and give a notification once it has finished. The default value is True.

classmethod from_SimResults(sim_results: pytanksim.classes.simresultsclass.SimResults, displayed_points: float = None, init_time: float = None, final_time: float = None, target_pres: float = None, target_temp: float = None, stop_at_target_pressure: bool = None, stop_at_target_temp: bool = None, target_capacity: float = None, verbose: bool = None) SimParams

Take final conditions from a previous simulation as new parameters.

Parameters:
  • sim_results (SimResults) – An object containing previous simulation results.

  • displayed_points (float, optional) – The number of data points to be reported at the end of the simulation. The default is 200.

  • init_time (float, optional) – The time (seconds) at which the beginning of the simulation is set. The default value is None.

  • final_time (float, optional) – The time (seconds) at which the simulation is to be stopped. If None, then the final_time setting from the previous simulation is used. The default is None.

  • target_pres (float, optional) – The target pressure (Pa) at which the simulation is to be stopped. If None, then the target_pres setting from the previous simulation is used. The default is None.

  • target_temp (float, optional) – The target temperature (K) at which the simulation is to be stopped. If None, then the target_temp setting from the previous simulation is used. The default is None.

  • stop_at_target_pressure (bool, optional) – If True, it will stop the simulation when the target pressure is met. If None, then the stop_at_target_pressure setting from the previous simulation is used. The default is None.

  • stop_at_target_temp (bool, optional) – If True, it will stop the simulation when the target temperature is met. If None, then the stop_at_target_temp setting from the previous simulation is used. The default is None.

  • target_capacity (float, optional) – The amount of fluid (moles) stored in the tank at which the simulation is to be stopped. If None, then the target_capacity value from the previous simulation is used. The default is None.

Returns:

A SimParams object containing the final conditions taken from sim_results set as the new starting parameters.

Return type:

SimParams

class pytanksim.classes.basesimclass.BoundaryFlux(mass_flow_in: Callable[[float, float, float], float] | float = 0.0, mass_flow_out: Callable[[float, float, float], float] | float = 0.0, heating_power: Callable[[float, float, float], float] | float = 0.0, cooling_power: Callable[[float, float, float], float] | float = 0.0, pressure_in: Callable[[float, float, float], float] | float = None, temperature_in: Callable[[float, float, float], float] | float = None, environment_temp: float = 0, enthalpy_in: Callable[[float, float, float], float] | float = None, enthalpy_out: Callable[[float, float, float], float] | float = None)

Stores information of the mass and energy fluxes on the tank boundaries.

mass_flow_in

A function which returns mass flow into the tank (kg/s) as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere.

Type:

Callable[[float, float, float], float], optional

mass_flow_out

A function which returns mass flow exiting the tank (kg/s) as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere.

Type:

Callable[[float, float, float], float], optional

heating_power

A function which returns heating power added to the tank (W) as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere.

Type:

Callable[[float, float, float], float], optional

cooling_power

A function which returns cooling power added to the tank (W) as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere.

Type:

Callable[[float, float, float], float], optional

pressure_in

A function which returns the pressure (Pa) of the fluid being inserted into the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None.

Type:

Callable[[float, float, float], float], optional

temperature_in

A function which returns the temperature (K) of the fluid being inserted into the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None.

Type:

Callable[[float, float, float], float], optional

environment_temp

The temperature (K) of the environment surrounding the tank. This value is used in the dynamic simulation to calculate heat leakage into the tank. The default is 0, in which case heat leakage into the tank is not considered.

Type:

float, optional

enthalpy_in

A function which returns the enthalpy (J/mol) of the fluid being inserted into the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None.

Type:

Callable[[float, float, float], float], optional

enthalpy_out

A function which returns the enthalpy (J/mol) of the fluid exiting the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None.

Type:

Callable[[float, float, float], float], optional

Initialize a BoundaryFlux object.

Parameters:
  • mass_flow_in (Callable or float, optional) –

    A function which returns mass flow into the tank (kg/s) as a functionof tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere. If a float is provided, it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def mass_flow_in_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        #Returned is the mass flow going into the tank (kg/s)
        return mass_flow_in
    

  • mass_flow_out (Callable or float, optional) –

    A function which returns mass flow exiting the tank (kg/s) as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere. If a float is provided it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def mass_flow_out_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        # Returned is the mass flow going out of the tank (kg/s)
        return mass_flow_out
    

  • heating_power (Callable or float, optional) –

    A function which returns heating power added to the tank (W) as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere. If a float is provided, it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def heating_power_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        # Returned is the heat put into the tank (W)
        return heating_power
    

  • cooling_power (Callable or float, optional) –

    A function which returns cooling power added to the tank (W) as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is a function which returns 0 everywhere. If a float is provided,it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def cooling_power_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        # Returned is the heat taken out of the tank (W)
        return cooling_power
    

  • pressure_in (Callable or float, optional) –

    A function which returns the pressure (Pa) of the fluid being inserted into the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None. If a float is provided,it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def pressure_in_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        # Returned is the pressure (Pa) of the fluid going into
        # the tank.
        return pressure_in
    

  • temperature_in (Callable or float, optional) –

    A function which returns the temperature (K) of the fluid being inserted into the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None. If a float is provided,it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def temperature_in_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        # Returned is the temperature (K) of the fluid going into
        # the tank.
        return temperature_in
    

  • environment_temp (float, optional) – The temperature (K) of the environment surrounding the tank. This value is used in the dynamic simulation to calculate heat leakage into the tank. The default is 0, in which case heat leakage into the tank is not considered.

  • enthalpy_in (Callable or float, optional) –

    A function which returns the enthalpy (J/mol) of the fluid being inserted into the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None. If a float is provided,it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def enthalpy_in_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        # Returned is the enthalpy (J/mol) of the fluid going into
        # the tank.
        return enthalpy_in
    

  • enthalpy_out (Callable or float, optional) –

    A function which returns the enthalpy (J/mol) of the fluid exiting the tank as a function of tank pressure (Pa), tank temperature (K), and time (s). The default is None. If a float is provided, it will be converted to a function which returns that value everywhere.

    If a callable is passed, it must have the signature:

    def enthalpy_out_function(p, T, time):
        # 'p' is tank pressure (Pa)
        # 'T' is tank temperature (K)
        # 'time' is the time elapsed within the simulation (s)
        ....
        # Returned is the enthalpy (J/mol) of the fluid going out
        # of the tank.
        return enthalpy_out
    

Raises:

ValueError – If the mass flow going in is specified but the parameters that specify its enthalpy (i.e., either pressure and temperature or its enthalpy value) are not specified.

Returns:

An object which stores information of the mass and energy fluxes on the tank boundaries.

Return type:

BoundaryFlux

class pytanksim.classes.basesimclass.BaseSimulation(simulation_params: SimParams, storage_tank: pytanksim.classes.storagetankclasses.StorageTank, boundary_flux: BoundaryFlux)

An abstract base class for dynamic simulations.

Other simulation classes inherit some attributes and methods from this class.

sim_type

Type of simulation (default, heated discharge, cooled refuel, etc.)

Type:

str

sim_phase

1 or 2 phases.

Type:

int

simulation_params

Object which stores simulation parameters.

Type:

SimParams

storage_tank

Object which stores the properties of the tank being simulated.

Type:

StorageTank

boundary_flux

Object which stores the amount of energy entering and exiting the tank.

Type:

BoundaryFlux

stop_reason

A string stating the reason for the simulation to have stopped. It will be passed to the SimResults object once the simulation finishes.

Type:

str

Initialize the BaseSimulation class.
heat_leak_in(T: float) float

Calculate the heat leakage rate from the environment into the tank.

Parameters:

T (float) – Temperature (K) of the storage tank.

Returns:

The rate of heat leakage into the tank from the environment (W).

Return type:

float

abstract run()

Abstract function which will be defined in the child classes.

Raises:

NotImplementedError – Raises an error since it is not implemented in this abstract base class.

Return type:

None.

enthalpy_in_calc(p: float, T: float, time: float) float

Calculate the enthalpy (J/mol) of fluid going into the tank.

Parameters:
  • p (float) – Pressure inside of the tank (Pa)

  • T (float) – Temperature inside of the tank (K)

  • time (float) – Time (s) in the simulation.

Returns:

Enthalpy of the fluid going into the tank (J/mol).

Return type:

float

enthalpy_out_calc(fluid_property_dict: Dict[str, float], p: float, T: float, time: float) float

Calculate the enthalpy (J/mol) of fluid going out of the tank.

Parameters:
  • fluid_property_dict (Dict[str,float]) – A dictionary of properties of the fluid being stored inside of the tank. In the case of the two phase simulation, it is the properties of the gas and not the liquid. For this function, this dictionary must return an enthalpy (J/mol) value given the key “hf”.

  • p (float) – Pressure inside of the tank (Pa)

  • T (float) – Temperature inside of the tank (K)

  • time (float) – Time (s) in the simulation.

Returns:

Enthalpy of the fluid going out of the tank (J/mol).

Return type:

float