Coupled Object with Coordinator Functionalities
stored in DEVS_PATH/00-simulator/coupled.p
Is provided as p-code.
Contents
Based on modified parallel DEVS algorithms (Zeigler, Schwatinski). |
User defined coupled models can be created as instances of this class directly or can be derived from it alternatively. For initialization, the modeler has to define input and output portnames. Components and coupling information are defined after instantiation via the methods *addcomponents(obj,comps)* and *set_Zid(obj,Zid)*. |
C. Deatcu 2016 |
Description
Class definition file for a coupled DEVS model and it's associated coordinator
constructor call: obj = coupled(name,xportnames,yportnames), where xportnames and yportnames are optional
Superclass
devs
Inherited properties
- sub_of : string, name of the superordinate model --> for debugging purposes
- tnext : float, time of next event
- tlast : float, time of last event
- name : string, (unique) name of this model --> for debugging purposes max. 12 characters for "nice" debug-look ;-)
- x : structure, set of inport name/input value (cell array) pairs
- y : structure, set of outport name/output value (cell array) pairs
- debug_flag: 0|1|2|3, no messages|messages|steps|visualize x, y, and s of atomic subcomponents (default 0)
- observe_flag: 0|1, log states of atomic subcomponents or not (default 0)
Properties
- Da : cell array of strings, names of atomic subcomponents
- Dc : cell array of strings, names of coupled subcomponents
- Zid : cell array of strings, "i-to-d-matrix" (couplings)
- components: array of objects, subcomponents
- eventlist : matrix with information on future events of subcomponents, eventlist = [a,b,c;...]
eventlist = [a,b,c;...] a - time for next transition b - {1,2} | 1 if atomic DEVS, 2 if coupled DEVS c - index for eventlist (position in Da or Dc)
Class methods
Simulation Messages
- i_msg(obj,gt) : initialization message - sets tlast and tnext at all subcomponents and sets matrix eventlist
- s_msg(obj,gt,flag): star message - called when coupled is imminent, sets tlast and tnext
- x_msg(obj,gt) : x message - called, if external event arrives
- y_msg(obj,gt) : inperpellation y message
Methods to Define Components and Couplings
- add_c_component(obj, comps): add one coupled subcomponent
- add_a_component(obj, comps): add one atomic subcomponent
- addcomponents(obj, comps): add one or more subcomponents of any kind ;-)
- set_Zid(obj, Zid): set Zid (one or more Lines)
Set Methods for Flags
- set_debug(obj,debug_flag): set debug flag to 0|1|2
- set_observe(obj,observe_flag): set observe flag to 0|1 (for tracking states of atomic subcomponents)
i_MSG
function i_msg(obj,gt)
WHAT HAPPENS IN I_MSG?
- set times tlast and tnext at all objects
- set matrix eventlist
eventlist = [a,b,c;...] a - time for next transition b - {1,2} | 1 if atomic DEVS, 2 if coupled DEVS c - index for eventlist (position in Da or Dc)
eventlist is NOT sorted by smallest tnext
S_MSG
function s_msg(obj,gt,flag)
WHAT HAPPENS IN S_MSG?
- copy all elements from matrix eventlist which are imminent to local matrix imminents (same structure like eventlist)
- delete all copied rows (look at step before) in eventlist
- carry out interpellation y-message (only for imminents) -> set all relevant output ports to input ports
- transmit relevant input ports from parent to all children -> delete all input ports from parent
- carry out x-message of relevant (all which have inputs) elements in matrix eventlist and delete the input ports
- carry out s-message or x-message (if there are also inputs) for relevant elements in matrix imminents and then delete the input ports
- set times tlast an tnext at THIS coupled and build a new matrix eventlist
flag == 1 --> s_msg from ROOT, flag == 0 --> s_msg from other
Y_MSG
function y_msg(obj,gt)
it is an interpellation y_msg
WHAT HAPPENS IN Y_MSG?
- copy all elements from matrix eventlist which are imminent to local matrix imminents (same structure like eventlist)
- carry y-message out for all elements in imminents -> set relevant input/output ports
X_MSG
function x_msg(obj,gt)
WHAT HAPPENS IN X_MSG?
- transmit relevant input ports from parent to all children -> delete all input ports from parent
- carry out x-message of influenced subcomponents
- set times tlast and tnext at parent and build a new matrix eventlist
Methods for Displaying the Coupled Objects
- showxports(obj): display x-ports
- showyports(obj): display y-ports
- showsubcomponents(obj): display atomic and coupled subcomponents
- showcouplings(obj): display coupling matrix
- showeventlist(obj): display eventlist
- showall(obj): display the entire object
These functions can be called to get some information during or after simulation.
Example: How to Create a Coupled Model
>> newcoupled = coupled('model', {'inport1', 'inport2'}, {'outport1'});% incarnate with portnames
OR
>> newcoupled = coupled('model'); % incarnate without portnames >> set_x_ports(newcoupled, {'inport1','inport2'}); % set x and y ports >> set_y_ports(newcoupled, {'outport1'});
then add subcomponents
>> subcomponent1 = coupled('sub1', {'in1','in2'},{'out1'}); % incarnate subcomponents >> set_Zid(subcomponent1,{'parent','in2','parent','out1'}); % dummy Zid >> subcomponent2 = coupled('sub2', {'in1'}, {'out1'}); >> set_Zid(subcomponent2,{'parent','in1','parent','out1'}); % dummy Zid >> addcomponents(newcoupled, {subcomponent1, subcomponent2}); % add components to model
then add couplings
>> Zid = {'parent','inport2','sub1','in1';... % define Zid 'parent','inport1','sub2','in1';... 'sub2','out1','sub1','in2';... 'sub2','out1','parent','outport1'}; >> set_Zid(newcoupled, Zid);
check your model
>> Check(newcoupled); % check recursively if all names and ports really exist
DEVS Tbx Home Examples Modelbase << Back