Template for a pure discrete ATOMIC PDEVS

stored in DEVS_PATH/01-modelbase/am_discrete_template.m

Adopt this template to create your own atomic models.

Contents

Description

Template for a class definition file of an atomic PDEVS model with pure discrete behaviour

constructor call: obj = am_discrete_template(name,inistates,elapsed,sysparams)

To define your own model adopt this file. You need to define ports, states, system parameters and fill characteristic functions with your model specific behaviour. First step is to alter the class name in classdef section, the constructor call and save the class definition to a new m-file with the name of your user-defined class.

Superclass

atomic (superclass acts as associated simulator)

Class Methods

characteristic functions:

display functions:

Inherited Properties

inherited from atomic:

Ports

just an example:

has three inputs x: in1, in2 and in3

has two outputs y: out1 and out2

States in s

s.sigma (example state)

System Parameters in sysparams

sysparams.param1 (example system parameter)

More

global SIMUSTOP : can be used to stop allover simulation, e.g. when a predifined number of pallets have been produced

Class File

classdef am_discrete_template < atomic

    methods

        function obj = am_discrete_template(name,inistates,elapsed,sysparams)
            if nargin == 4
                x = {'in1', 'in2','in3'}; % example inports
                y = {'out1','out2'};% example outports
                s = {'sigma'}; % example state
                sysparams = struct('param1',sysparams(1));
            else
                error(['mistake at constructor method for class ',mfilename]);
            end
            obj = obj@atomic(name,x,y,s,elapsed,sysparams);% incarnate the associated simulator
            % initialize the states
            obj.s.sigma = inistates.sigma;
        end

        function ta = tafun(obj)
            %**** USER CODE GOES HERE ****
            ta = obj.s.sigma; % example code: set ta by some calculations
            %**** END USER CODE       ****
        end

        function deltaconffun(obj,gt)
            %**** USER CODE GOES HERE ****
            % example code: if internal and external events occur simultaneously,
            % first call external transition then internal transition
            deltaextfun(obj,gt);
            deltaintfun(obj);
            %**** END USER CODE
        end

        function deltaextfun(obj,gt) %#ok<INUSD>
            % gt ist current time, specify reactions on external events
            %**** USER CODE GOES HERE ****
            % example code: read from input port
            inmessage = obj.x.in2{1};  %#ok<NASGU>
            %**** END USER CODE
        end

        function deltaintfun(obj) %#ok<*MANU>
            % specify reactions on internal events
            %**** USER CODE GOES HERE ****

            %**** END USER CODE
        end

        function lambdafun(obj)
            % specify outputs
            %**** USER CODE GOES HERE ****
            % example code: set the output ports
            obj.y.out1 = {1};
            obj.y.out2 = {'message'};
            %**** END USER CODE
        end

    end
end





DEVS Tbx Home      Examples      Modelbase           << Back