Skip to content

module

A Module class that represents a generic gas management module.

Module

Module()

A class that represents a generic gas management module.

Contains the step method that is called in each time step.

Children classes should implement the following methods:

  • check_failure
  • produce
  • consume
  • calculate_maintenance_time
Source code in src/bsm2_python/energy_management/module.py
def __init__(self) -> None:
    self.global_time: float = 0.0
    self._runtime: float = 0.0
    self._remaining_maintenance_time: float = 0.0
    self._time_since_last_maintenance: float = 0.0
    self._under_maintenance: bool = False
    self._total_maintenance_time: float = 0.0
    self.maintenance_cost_per_hour: float = 0.0
    self.mttf: float = 0.0  # Mean Time To Failure
    self.mttr: float = 0.0  # Mean Time To Repair
    self.load_change_time: float = 0.0
    self._remaining_load_change_time: float = 0.0
    self._previous_load: float = 0.0
    self._ready_to_change_load: bool = True
    self._load: float = 0.0
    self._products: np.ndarray = np.array([0.0])
    self._consumption: np.ndarray = np.array([0.0])

runtime

runtime

Return the runtime of the module.

Returns:

Type Description
float

Runtime of the module [hours].

load

load

Return the load of the module.

Returns:

Type Description
float

Load of the module.

total_maintenance_time

total_maintenance_time

Return the total maintenance time of the module.

Returns:

Type Description
float

Total maintenance time of the module [hours].

remaining_maintenance_time

remaining_maintenance_time

Return the remaining maintenance time of the module.

Returns:

Type Description
float

Remaining maintenance time of the module [hours].

time_since_last_maintenance

time_since_last_maintenance

Return the time since the last maintenance of the module.

Returns:

Type Description
float

Time since the last maintenance of the module [hours].

under_maintenance

under_maintenance

Return the maintenance status of the module.

Returns:

Type Description
bool
  • True: If the module is under maintenance.
  • False: Otherwise.

ready_to_change_load

ready_to_change_load

Return weather the module is ready to change load.

Returns:

Type Description
bool
  • True: If the module is ready to change load.
  • False: Otherwise.

products

products

Returns the products of the module.

Returns:

Type Description
ndarray

Products of the module.

[products]

consumption

consumption

Returns the consumption of the module.

Returns:

Type Description
ndarray

Consumption of the module.

[consumption]

check_failure

check_failure()

Checks if the module has failed.

Returns:

Type Description
bool
  • True: If the module has failed.
  • False: Otherwise.
Source code in src/bsm2_python/energy_management/module.py
def check_failure(self):
    """Checks if the module has failed.

    Returns
    -------
    bool
        - True: If the module has failed.
        - False: Otherwise.
    """

    raise NotImplementedError('The check_failure method must be implemented by the child class.')

check_load_change

check_load_change()

Checks if the module has changed its load in the previous timestep.

Returns:

Type Description
bool
  • True: If the module has been shut down.
  • False: Otherwise.
Source code in src/bsm2_python/energy_management/module.py
def check_load_change(self):
    """Checks if the module has changed its load in the previous timestep.

    Returns
    -------
    bool
        - True: If the module has been shut down.
        - False: Otherwise.
    """

    return self._load != self._previous_load

reduce_remaining_load_change_time

reduce_remaining_load_change_time(time_delta)

Reduces the remaining load change time based on the time delta.

Parameters:

Name Type Description Default
time_delta float

Time difference [hours].

required
Source code in src/bsm2_python/energy_management/module.py
def reduce_remaining_load_change_time(self, time_delta: float):
    """Reduces the remaining load change time based on the time delta.

    Parameters
    ----------
    time_delta : float
        Time difference [hours].
    """

    self._remaining_load_change_time = max(self._remaining_load_change_time - time_delta, 0)

check_ready_for_load_change

check_ready_for_load_change()

Checks if the module is ready to change load.

Returns:

Type Description
bool
  • True: If the module is ready to change load.
  • False: Otherwise.
Source code in src/bsm2_python/energy_management/module.py
def check_ready_for_load_change(self):
    """Checks if the module is ready to change load.

    Returns
    -------
    bool
        - True: If the module is ready to change load.
        - False: Otherwise.
    """

    return self._remaining_load_change_time <= 0

produce

produce()

Produces energy based on the load and time delta.

Returns:

Type Description
ndarray

Production of the module at the current load.

[production]

Source code in src/bsm2_python/energy_management/module.py
def produce(self) -> np.ndarray:
    """Produces energy based on the load and time delta.

    Returns
    -------
    np.ndarray
        Production of the module at the current load. \n
        [production]
    """

    raise NotImplementedError('The produce method must be implemented by the child class.')

consume

consume()

Consumes energy based on the load and time delta.

Returns:

Type Description
ndarray

Consumption of the module at the current load.

[consumption]

Source code in src/bsm2_python/energy_management/module.py
def consume(self) -> np.ndarray:
    """Consumes energy based on the load and time delta.

    Returns
    -------
    np.ndarray
        Consumption of the module at the current load. \n
        [consumption]
    """

    raise NotImplementedError('The consume method must be implemented by the child class.')

maintain

maintain(time_delta)

Maintains the module based on the time delta.

Parameters:

Name Type Description Default
time_delta float

Time difference [hours].

required
Source code in src/bsm2_python/energy_management/module.py
def maintain(self, time_delta: float):
    """Maintains the module based on the time delta.

    Parameters
    ----------
    time_delta : float
        Time difference [hours].
    """

    self.remaining_maintenance_time -= time_delta

calculate_maintenance_time

calculate_maintenance_time()

Calculates the maintenance time of the module.

Returns:

Type Description
float

Time it takes to maintain the module.

Source code in src/bsm2_python/energy_management/module.py
def calculate_maintenance_time(self) -> float:
    """Calculates the maintenance time of the module.

    Returns
    -------
    float
        Time it takes to maintain the module.
    """

    raise NotImplementedError('The calculate_maintenance_time method must be implemented by the child class.')

report_status

report_status()

Reports the status of the module.

Returns:

Type Description
ndarray

Status of the module.

[load, remaining maintenance time, products, consumption]

Source code in src/bsm2_python/energy_management/module.py
def report_status(self) -> np.ndarray:
    """Reports the status of the module.

    Returns
    -------
    np.ndarray
        Status of the module. \n
        [load, remaining maintenance time, products, consumption]
    """

    status = [
        self.load,
        self._remaining_maintenance_time,
        *self._products,
        *self._consumption,
    ]
    return np.array(status)

step

step(time_delta)

Updates the module based on the load and time delta.

Parameters:

Name Type Description Default
time_delta float

Time difference [hours].

required
Source code in src/bsm2_python/energy_management/module.py
def step(self, time_delta: float):
    """Updates the module based on the load and time delta.

    Parameters
    ----------
    time_delta : float
        Time difference [hours].
    """

    self.global_time += time_delta
    if not self._under_maintenance:
        if self.check_failure():
            self.remaining_maintenance_time = self.calculate_maintenance_time()
            self._total_maintenance_time += self.remaining_maintenance_time
            self.maintain(time_delta)
            self._products = np.zeros_like(self.products)
            self._consumption = np.zeros_like(self.consumption)
        else:
            self._time_since_last_maintenance += time_delta
            self._runtime += time_delta
            self._products = self.produce()
            self._consumption = self.consume()
    else:
        self.maintain(time_delta)
        self._products = np.zeros_like(self.products)
        self._consumption = np.zeros_like(self.consumption)
    if self.check_load_change():
        self._remaining_load_change_time = self.load_change_time
    self.reduce_remaining_load_change_time(time_delta)
    self._ready_to_change_load = self.check_ready_for_load_change()
    self._previous_load = self._load