2 #ifndef SYDEVS_SYSTEMS_COMPOSITE_NODE_H_
3 #define SYDEVS_SYSTEMS_COMPOSITE_NODE_H_
61 template<data_mode dmode,
typename T>
75 template<data_mode dmode,
typename T>
89 template<data_mode dmode,
typename T>
98 void categorize_node_indices();
99 void process_flow_nodes(
bool finalize);
100 void handle_initialization_events();
102 void handle_dst_events(
const std::set<std::pair<int64, int64>>& dsts,
const pointer& val);
103 void handle_finalization_events();
105 void activate_flow_inward_links();
109 const std::set<std::pair<int64, int64>>& traverse_message_inward_links(
int64 port_index);
110 const std::set<std::pair<int64, int64>>& traverse_message_inner_links(
int64 node_index,
int64 port_index);
113 void adopt_component_print_flags(
const system_node& node)
const;
116 std::vector<int64> unprocessed_flow_node_indices_;
117 std::vector<int64> processed_flow_node_indices_;
118 std::vector<int64> uninitialized_message_node_indices_;
119 std::vector<int64> initialized_message_node_indices_;
122 std::map<int64, std::set<std::pair<int64, int64>>> inward_link_dsts_;
123 std::map<std::pair<int64, int64>, std::set<std::pair<int64, int64>>> inner_link_dsts_;
124 std::map<std::pair<int64, int64>, std::set<int64>> outward_link_dsts_;
126 mutable bool composite_dmode_calculated_;
134 , internal_context_(&const_cast<
node_interface&>(external_interface()),
136 , unprocessed_flow_node_indices_()
137 , processed_flow_node_indices_()
138 , uninitialized_message_node_indices_()
139 , initialized_message_node_indices_()
142 , inward_link_dsts_()
144 , outward_link_dsts_()
145 , composite_dmode_(
flow)
146 , composite_dmode_calculated_(false)
147 , initialized_(false)
161 return const_cast<const node_context&
>(internal_context_);
165 template<data_mode dmode,
typename T>
170 throw std::logic_error(
"Attempt to create inward link on composite node (" +
full_name() +
") that does not originate from one of the composite node's ports");
173 throw std::logic_error(
"Attempt to create inward link on composite node (" +
full_name() +
") that does not end up at one of the composite node's components");
188 template<data_mode dmode,
typename T>
193 throw std::logic_error(
"Attempt to create inner link on composite node (" +
full_name() +
") that does not originate from one of the composite node's components");
196 throw std::logic_error(
"Attempt to create inner link on composite node (" +
full_name() +
") that does not end up at one of the composite node's components");
211 template<data_mode dmode,
typename T>
216 throw std::logic_error(
"Attempt to create outward link on composite node (" +
full_name() +
") that does not originate from one of the composite node's components");
219 throw std::logic_error(
"Attempt to create outward link on composite node (" +
full_name() +
") that does not end up at one of the composite node's ports");
240 inline node_interface& composite_node::component_IO(
const system_node& node)
const
246 inline discrete_event_time& composite_node::event_time()
A data type which represents a pointer to anything.
Definition: pointer.h:29
A data type which represents the general concept of scale as a dimensionless power of 1000.
Definition: scale.h:71
A base class for all nodes defined as fixed-structure compositions of different types of nodes.
Definition: composite_node.h:24
duration handle_planned_event(duration elapsed_dt)
Invoked when the planned duration elapses; calls process_planned_event on the source node and propaga...
Definition: composite_node.cpp:55
void outward_link(const port< dmode, output, T > &src_port, const port< dmode, output, T > &dst_port)
Constructs an outward link.
Definition: composite_node.h:212
data_mode node_dmode() const
Returns flow if all component nodes have data flow elements only, and message otherwise.
Definition: composite_node.cpp:7
virtual ~composite_node()=default
Destructor.
void inward_link(const port< dmode, input, T > &src_port, const port< dmode, input, T > &dst_port)
Constructs an inward link.
Definition: composite_node.h:166
void handle_finalization_event(duration elapsed_dt)
Invoked at the end of a simulation; calls process_finalization_event on all component nodes.
Definition: composite_node.cpp:80
composite_node(const std::string &node_name, const node_context &external_context)
Constructs a composite_node.
Definition: composite_node.h:132
scale time_precision() const
Returns no_scale for all composite nodes.
Definition: composite_node.h:153
void inner_link(const port< dmode, output, T > &src_port, const port< dmode, input, T > &dst_port)
Constructs an inner link.
Definition: composite_node.h:189
const node_context & internal_context()
Returns a representation of the internal context, which is also the external context of the component...
Definition: composite_node.h:159
duration handle_initialization_event()
Invoked at the beginning of a simulation, calls process_initialization_event on all component nodes.
Definition: composite_node.cpp:24
duration handle_unplanned_event(duration elapsed_dt)
Invoked whenever a message is received; calls process_unplanned_event on receiving component nodes.
Definition: composite_node.cpp:42
A data structure which represents progress through a simulation, encapsulating both simulated time an...
Definition: discrete_event_time.h:37
Definition: node_context.h:17
discrete_event_time & event_time()
Definition: node_context.h:62
node_structure & internal_structure()
Definition: node_context.h:50
Definition: node_interface.h:17
node_context & external_context()
Definition: node_interface.h:157
Definition: node_structure.h:16
void add_flow_inward_link(int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:107
void add_message_outward_link(int64 src_node_index, int64 src_port_index, int64 dst_port_index)
Definition: node_structure.h:203
void add_message_inner_link(int64 src_node_index, int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:165
void add_flow_inner_link(int64 src_node_index, int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:146
void add_message_inward_link(int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:126
void add_flow_outward_link(int64 src_node_index, int64 src_port_index, int64 dst_port_index)
Definition: node_structure.h:184
const node_interface & external_interface() const
Returns the encomassing node_interface object.
Definition: port.h:233
int64 node_index() const
Returns the index of the node within the encompassing node_structure object.
Definition: port.h:226
int64 port_index() const
Returns the index of the port within the encompassing node_interface object.
Definition: port.h:219
A generic port class template declaration.
Definition: port.h:54
A base class for all nodes from which systems models are constructed.
Definition: system_node.h:42
system_node(const system_node &)=delete
No copy constructor.
int64 node_index() const
Returns the index of the node within the parent node.
Definition: system_node.h:147
const std::string & full_name() const
Returns the full name of the node, including parent nodes.
Definition: system_node.h:141
const std::string & node_name() const
Returns the name of the node.
Definition: system_node.h:135
node_interface & external_IO() const
Returns a non-const reference to the node's external interface.
Definition: system_node.h:288
const node_interface & external_interface() const
Returns the object responsible for exchanging information between the node and its surrounding contex...
Definition: system_node.h:153
A data structure which provides durations elapsed since past events.
Definition: time_cache.h:28
A data structure which supports the scheduling of future events.
Definition: time_queue.h:35
data_mode
Indicates the relevant data communication paradigm: dataflow (flow) or message-passing (message).
Definition: data_mode.h:16
const auto message
Equivalent to data_mode::message.
Definition: data_mode.h:23
const auto flow
Equivalent to data_mode::flow.
Definition: data_mode.h:22
int64_t int64
Definition: number_types.h:15
constexpr scale no_scale
Definition: scale.h:153