simulation_classes.pipeline

This module defines the Pipeline class, which simulates the flow of liquid in a pipeline system. These pipelines can operate in two modes: 'sink' for draining liquid from a storage tank and 'source' for filling it. This pipelines only connect storage tanks and not tanker vessels.

 1"""
 2This module defines the Pipeline class, which simulates the flow of liquid in a pipeline system.
 3These pipelines can operate in two modes: 'sink' for draining liquid from a storage tank and 'source' for filling it.
 4This pipelines only connect storage tanks and not tanker vessels.
 5"""
 6
 7import constants
 8
 9
10class Pipeline:
11    """
12    Pipeline class to simulate the flow of liquid in a pipeline system.
13    Args:
14        run_id (int): Unique identifier for the simulation run.
15        env (simpy.Environment): Simulation environment.
16        tank (simpy.Container): Container representing the storage tank.    
17        mode (str): Mode of operation, either 'sink' or 'source'.
18        rate (float): Rate at which the pipeline operates, in units per time step.
19    """
20
21    def __init__(self, run_id, env, tank, mode, rate):
22
23        self.env = env
24        self.run_id = run_id
25        self.capacity = tank.capacity
26        self.storage = tank
27        self.mode = mode
28        self.rate = rate
29        self.process = env.process(self.run())
30
31    def run(self):
32        """
33        Simulate pipeline operation.
34        Logic is as follows --
35        If mode is 'sink', empty the storage at the rate of 'rate' units per time step unless the storage is empty.
36        If mode is 'source', fill the storage at the rate of 'rate' units per time step unless the storage is full.
37        Args:
38            None
39        Yields:
40            simpy.Timeout: Waits for 1 time unit before the next operation.
41        Raises:
42            ValueError: If the rate exceeds the storage level or capacity limits.
43        """
44        if self.mode == "sink" and constants.LIQ_PIPELINE_OVERRIDE == True:
45            while self.storage.level > 0.7 * self.capacity:
46
47                # ensure rate is not greater than the storage level
48                if self.storage.level <= self.rate:
49                    raise ValueError(
50                        f"SINK: Rate cannot be greater than the  0.2 * self.capacity; rate: {self.rate}, storage level: {self.storage.level}, capacity: {self.capacity}")
51
52                yield self.storage.get(self.rate)
53                yield self.env.timeout(1)
54
55        elif self.mode == "source" and constants.LIQ_PIPELINE_OVERRIDE == True:
56
57            # ensure rate is not greater than the storage level
58            if self.storage.level + self.rate >= self.capacity:
59                raise ValueError(
60                    f"SOURCE: Rate cannot be greater than the  0.2 * self.capacity; rate: {self.rate}, storage level: {self.storage.level}, capacity: {self.capacity}")
61
62            while self.storage.level <= 0.3 * self.capacity:
63                yield self.storage.put(self.rate)
64                yield self.env.timeout(1)
class Pipeline:
11class Pipeline:
12    """
13    Pipeline class to simulate the flow of liquid in a pipeline system.
14    Args:
15        run_id (int): Unique identifier for the simulation run.
16        env (simpy.Environment): Simulation environment.
17        tank (simpy.Container): Container representing the storage tank.    
18        mode (str): Mode of operation, either 'sink' or 'source'.
19        rate (float): Rate at which the pipeline operates, in units per time step.
20    """
21
22    def __init__(self, run_id, env, tank, mode, rate):
23
24        self.env = env
25        self.run_id = run_id
26        self.capacity = tank.capacity
27        self.storage = tank
28        self.mode = mode
29        self.rate = rate
30        self.process = env.process(self.run())
31
32    def run(self):
33        """
34        Simulate pipeline operation.
35        Logic is as follows --
36        If mode is 'sink', empty the storage at the rate of 'rate' units per time step unless the storage is empty.
37        If mode is 'source', fill the storage at the rate of 'rate' units per time step unless the storage is full.
38        Args:
39            None
40        Yields:
41            simpy.Timeout: Waits for 1 time unit before the next operation.
42        Raises:
43            ValueError: If the rate exceeds the storage level or capacity limits.
44        """
45        if self.mode == "sink" and constants.LIQ_PIPELINE_OVERRIDE == True:
46            while self.storage.level > 0.7 * self.capacity:
47
48                # ensure rate is not greater than the storage level
49                if self.storage.level <= self.rate:
50                    raise ValueError(
51                        f"SINK: Rate cannot be greater than the  0.2 * self.capacity; rate: {self.rate}, storage level: {self.storage.level}, capacity: {self.capacity}")
52
53                yield self.storage.get(self.rate)
54                yield self.env.timeout(1)
55
56        elif self.mode == "source" and constants.LIQ_PIPELINE_OVERRIDE == True:
57
58            # ensure rate is not greater than the storage level
59            if self.storage.level + self.rate >= self.capacity:
60                raise ValueError(
61                    f"SOURCE: Rate cannot be greater than the  0.2 * self.capacity; rate: {self.rate}, storage level: {self.storage.level}, capacity: {self.capacity}")
62
63            while self.storage.level <= 0.3 * self.capacity:
64                yield self.storage.put(self.rate)
65                yield self.env.timeout(1)

Pipeline class to simulate the flow of liquid in a pipeline system.

Arguments:
  • run_id (int): Unique identifier for the simulation run.
  • env (simpy.Environment): Simulation environment.
  • tank (simpy.Container): Container representing the storage tank.
  • mode (str): Mode of operation, either 'sink' or 'source'.
  • rate (float): Rate at which the pipeline operates, in units per time step.
def run(self):
32    def run(self):
33        """
34        Simulate pipeline operation.
35        Logic is as follows --
36        If mode is 'sink', empty the storage at the rate of 'rate' units per time step unless the storage is empty.
37        If mode is 'source', fill the storage at the rate of 'rate' units per time step unless the storage is full.
38        Args:
39            None
40        Yields:
41            simpy.Timeout: Waits for 1 time unit before the next operation.
42        Raises:
43            ValueError: If the rate exceeds the storage level or capacity limits.
44        """
45        if self.mode == "sink" and constants.LIQ_PIPELINE_OVERRIDE == True:
46            while self.storage.level > 0.7 * self.capacity:
47
48                # ensure rate is not greater than the storage level
49                if self.storage.level <= self.rate:
50                    raise ValueError(
51                        f"SINK: Rate cannot be greater than the  0.2 * self.capacity; rate: {self.rate}, storage level: {self.storage.level}, capacity: {self.capacity}")
52
53                yield self.storage.get(self.rate)
54                yield self.env.timeout(1)
55
56        elif self.mode == "source" and constants.LIQ_PIPELINE_OVERRIDE == True:
57
58            # ensure rate is not greater than the storage level
59            if self.storage.level + self.rate >= self.capacity:
60                raise ValueError(
61                    f"SOURCE: Rate cannot be greater than the  0.2 * self.capacity; rate: {self.rate}, storage level: {self.storage.level}, capacity: {self.capacity}")
62
63            while self.storage.level <= 0.3 * self.capacity:
64                yield self.storage.put(self.rate)
65                yield self.env.timeout(1)

Simulate pipeline operation. Logic is as follows -- If mode is 'sink', empty the storage at the rate of 'rate' units per time step unless the storage is empty. If mode is 'source', fill the storage at the rate of 'rate' units per time step unless the storage is full.

Arguments:
  • None
Yields:

simpy.Timeout: Waits for 1 time unit before the next operation.

Raises:
  • ValueError: If the rate exceeds the storage level or capacity limits.