Skip to content

Discrete Time Worker

feral3gp.feral.get_discrete_time_director()

Returns:

Type Description

The predefined discrete time director of the simulation

Source code in feral3gp/feral/core/simulation.py
58
59
60
61
62
def get_discrete_time_director():
    """
    :returns: The predefined discrete time director of the simulation
    """
    return Simulation.director_dt

feral3gp.feral.set_step_size(duration_in_nanos=JSimulationTime.ms(1))

Set the step size of the preconfigured discrete time director. The default step size is 1 millisecond

Source code in feral3gp/feral/core/simulation.py
51
52
53
54
55
def set_step_size(duration_in_nanos=JSimulationTime.ms(1)):
    """
    Set the step size of the preconfigured discrete time director. The default step size is 1 millisecond
    """
    Simulation.director_dt.setStepSize(duration_in_nanos)

feral3gp.feral.TimeTriggeredWorker

Bases: JavaDelegate

Time Triggered Workers integrate discrete time behavior/simulation models into a FERAL simulation.

Source code in feral3gp/feral/core/dt_worker.py
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
class TimeTriggeredWorker(JavaDelegate):
    """
    Time Triggered Workers integrate discrete time behavior/simulation models into a FERAL simulation.
    """

    def __init__(self, name: str, parent=Simulation.director_dt):
        java_delegate = TimeTriggeredWorkerDelegate(self, name, parent)
        self.set_java_delegate(java_delegate)
        self.in_port = self.create_input_port("input")
        self.out_port = self.create_output_port("output")

    def time_step(self):
        """
        Execution of a time step. This method is called by the controlling MOCC with the defined step width.
        """
        pass

    def initialize(self):
        """
        This method will be called by the controlling MOCC during the initialization phase of the simulation.
        """
        pass

    def terminate(self):
        """
        This method will be called by the controlling MOCC during the termination phase of the simulation.
        """
        pass

    def get_simulation_time(self):
        """
        :return: The current simulation time in nanoseconds
        """
        return self.get_java_delegate().getSimulationTime()

    def get_simulation_duration(self):
        """
        :return: The simulation duration time in nanoseconds
        """
        return self.get_java_delegate().getSimulationDuration()

    def create_input_port(self, port_name) -> JRxPortDiscreteTime:
        """
        Create a RxPort with a given name.
        :param port_name: The name of the port
        :return: The created RxPort
        """
        return self.get_java_delegate().createInputPort(port_name)

    def create_output_port(self, port_name):
        """
        Create a TxPort with a given name.
        :param port_name: The name of the port
        :return: The created TxPort
        """
        return self.get_java_delegate().createOutputPort(port_name)

    def get_input_port(self, port_name):
        """
        Get a RxPort with a given name.
        :param port_name: The name of the port
        :return: The RxPort
        """
        return self.get_java_delegate().getInputPort(port_name)

    def get_input_ports(self):
        """
        Get all RxPorts of this worker.
        :return: The RxPorts
        """
        return self.get_java_delegate().getInputPorts()

    def get_output_port(self, port_name):
        """
        Get a TxPort with a given name.
        :param port_name: The name of the port
        :return: The TxPort
        """
        return self.get_java_delegate().getOutputPort(port_name)

    def get_output_ports(self):
        """
        Get all TxPorts of this worker.
        :return: The TxPorts
        """
        return self.get_java_delegate().getOutputPorts()

    def get_console(self):
        """
        :return: The console of this worker
        """
        return self.get_java_delegate().getConsole()

    def set_console(self, console):
        """
        Set the console for this worker.
        :param console: The console to be set
        """
        self.get_java_delegate().setConsole(console)

create_input_port(port_name)

Create a RxPort with a given name.

Parameters:

Name Type Description Default
port_name

The name of the port

required

Returns:

Type Description
RxPortDiscreteTime

The created RxPort

Source code in feral3gp/feral/core/dt_worker.py
49
50
51
52
53
54
55
def create_input_port(self, port_name) -> JRxPortDiscreteTime:
    """
    Create a RxPort with a given name.
    :param port_name: The name of the port
    :return: The created RxPort
    """
    return self.get_java_delegate().createInputPort(port_name)

create_output_port(port_name)

Create a TxPort with a given name.

Parameters:

Name Type Description Default
port_name

The name of the port

required

Returns:

Type Description

The created TxPort

Source code in feral3gp/feral/core/dt_worker.py
57
58
59
60
61
62
63
def create_output_port(self, port_name):
    """
    Create a TxPort with a given name.
    :param port_name: The name of the port
    :return: The created TxPort
    """
    return self.get_java_delegate().createOutputPort(port_name)

get_console()

Returns:

Type Description

The console of this worker

Source code in feral3gp/feral/core/dt_worker.py
95
96
97
98
99
def get_console(self):
    """
    :return: The console of this worker
    """
    return self.get_java_delegate().getConsole()

get_input_port(port_name)

Get a RxPort with a given name.

Parameters:

Name Type Description Default
port_name

The name of the port

required

Returns:

Type Description

The RxPort

Source code in feral3gp/feral/core/dt_worker.py
65
66
67
68
69
70
71
def get_input_port(self, port_name):
    """
    Get a RxPort with a given name.
    :param port_name: The name of the port
    :return: The RxPort
    """
    return self.get_java_delegate().getInputPort(port_name)

get_input_ports()

Get all RxPorts of this worker.

Returns:

Type Description

The RxPorts

Source code in feral3gp/feral/core/dt_worker.py
73
74
75
76
77
78
def get_input_ports(self):
    """
    Get all RxPorts of this worker.
    :return: The RxPorts
    """
    return self.get_java_delegate().getInputPorts()

get_output_port(port_name)

Get a TxPort with a given name.

Parameters:

Name Type Description Default
port_name

The name of the port

required

Returns:

Type Description

The TxPort

Source code in feral3gp/feral/core/dt_worker.py
80
81
82
83
84
85
86
def get_output_port(self, port_name):
    """
    Get a TxPort with a given name.
    :param port_name: The name of the port
    :return: The TxPort
    """
    return self.get_java_delegate().getOutputPort(port_name)

get_output_ports()

Get all TxPorts of this worker.

Returns:

Type Description

The TxPorts

Source code in feral3gp/feral/core/dt_worker.py
88
89
90
91
92
93
def get_output_ports(self):
    """
    Get all TxPorts of this worker.
    :return: The TxPorts
    """
    return self.get_java_delegate().getOutputPorts()

get_simulation_duration()

Returns:

Type Description

The simulation duration time in nanoseconds

Source code in feral3gp/feral/core/dt_worker.py
43
44
45
46
47
def get_simulation_duration(self):
    """
    :return: The simulation duration time in nanoseconds
    """
    return self.get_java_delegate().getSimulationDuration()

get_simulation_time()

Returns:

Type Description

The current simulation time in nanoseconds

Source code in feral3gp/feral/core/dt_worker.py
37
38
39
40
41
def get_simulation_time(self):
    """
    :return: The current simulation time in nanoseconds
    """
    return self.get_java_delegate().getSimulationTime()

initialize()

This method will be called by the controlling MOCC during the initialization phase of the simulation.

Source code in feral3gp/feral/core/dt_worker.py
25
26
27
28
29
def initialize(self):
    """
    This method will be called by the controlling MOCC during the initialization phase of the simulation.
    """
    pass

set_console(console)

Set the console for this worker.

Parameters:

Name Type Description Default
console

The console to be set

required
Source code in feral3gp/feral/core/dt_worker.py
101
102
103
104
105
106
def set_console(self, console):
    """
    Set the console for this worker.
    :param console: The console to be set
    """
    self.get_java_delegate().setConsole(console)

terminate()

This method will be called by the controlling MOCC during the termination phase of the simulation.

Source code in feral3gp/feral/core/dt_worker.py
31
32
33
34
35
def terminate(self):
    """
    This method will be called by the controlling MOCC during the termination phase of the simulation.
    """
    pass

time_step()

Execution of a time step. This method is called by the controlling MOCC with the defined step width.

Source code in feral3gp/feral/core/dt_worker.py
19
20
21
22
23
def time_step(self):
    """
    Execution of a time step. This method is called by the controlling MOCC with the defined step width.
    """
    pass