uml-sp

Object-oriented simulation language UML2 SP

This project is maintained by vgurianov

Decomposition of clock

Terms view on Wikipedia.

Introduction

The SSP (Simulation with Scientific Profile) is analog of Unified Process to development a simulation models. The main principle of the SSP is a decomposition principle [1]. First of all, we define context and system. Farther, we make decomposition of system to subsystems. In the end, we have atomic objects. The atomic object is an anolog of ABS-agent. For decomposition, we use Composite pattern.
In the SSP, the particularity feature of decomposition is a decomposition of time. For any subsystem need to define a minimal change of subsystem (quantum of exist, can say ). In the UML2 SP, it is a operation with «Exist» stereotype. In this section we will discurse it topic.

Encapsulate of time

In nature, often different processes have different scale of time. For instance, the time of the turn of the Earth around the axis is small in comparison with the time of turn of the Earth around of the Sun. You can approximately take a day as event, ie for a point. This is very similar to the definition of a point particle. This is simulated in that one procedure is called from another procedure. From the point of view of the first procedure, the process of the second procedure will be an event. We can say that the second procedure encapsulates the time of the second process.
Encapsulate of time is called Tempo-world. Sergei P. Kurdyumov proposed this term [2].
We will view example of a time decomposition.

Problem domain

In the pendulum clock, the work of a constant external force (gravity acting on the weight) periodically compensates for the loss of mechanical energy of the pendulum. For details, see Wikipedia.

Figure 1. Pendulum clock (picture from http://fizportal.ru/)

First of all, we are interested in a gear train. The gear ratios of the gear train divide the rotation rate down to give wheels that rotate once every hour and once every 12 hours, to turn the hands of the clock.
Where are two objects such that their time is sinhronize. First object is the hour hand (and dial), second object is the minute hand (and dial).

Analysis model

Also consider seconds hand. Let the seconds hand by directly connected with the pendulum. A conceptual model in UML2 SP is an analysis class diagram. This diagram considered as ontology. Model the gear train is depicted in Fig.2.

Figure 2. The model of gear train

The ontology consist as frames and links between them. Frames define concepts: Timepiece, Time-measure device, Second hand, Minute hand, Hour hand, and Clock. The Item class do not a frame, it is definition of type for attributes of Component class.
The Root, BottomNode, TopNode, Leaf instances are nested inside each other (see aggregate association). Time of these objects also nested inside each other. Decomposition of time is the following.
The «Exist»Run() operation of BottomNode class (in C#) is

public override void Run()
{
   this.component.Run();
   if (cur == null) { cur = list; counter = 0; };
   probe = "Haur:"+counter.ToString() + this.component.probe;
   cur = cur.next; counter++;
} ,

where component variable is object of TopNode class and cur = list in begin.
The «Exist»Run() operation of TopNode class is

public override void Run()
        {
            while (cur != null)
            {
                cur = cur.next; counter++;
                this.component.Run();
            }
            cur = list; counter = 0;
            probe = ".minute: " + counter.ToString() + this.component.probe;
        }

where component variable is object of Leaf class and cur = list in begin.
The «Exist»Run() operation of Leaf class is a similar code.
For observer of BottomNode, process «Exist»Run() of TopNode is an event and this.component.probe variable will show 0 minutes because 60-minutes cycle is the end. For observer of TopNode, process «Exist»Run() of Leaf is an event and this.component.probe variable will show 0 seconds because 60-seconds cycle is the end.

Verification

Figure 3. Results of observe the simulation model

The simulation model in C# code:

ClockClass.cs

Alternative model of analysis

Let the Researcher be located in an atomic object. In this case, the model is changes. Model the gear train is depicted in Fig.4.

Figure 4. The alternative class diagram

The atomic object becomes a context object, and the context object becomes an atomic object. Now the Researcher can observe all the processes, but both TopNode and Leaf processes will go very slowly.

Verification

Figure 5. Results of observe the simulation model

The simulation model in C# code:

ClockClassAlt.cs

Note

The «Exist» stereotype mark a operation of thread execution, of example Run() in Java and C#. The objects of Leaf, Root, TopNode, BottomNode classes have concurrent threads. The threads interact as busy waiting [3, P.94], i.e. process repeatedly checks a condition until it becomes true.

Conclusion

The main principle of the SSP is a decomposition principle. The particularity feature of decomposition is a decomposition of time. For any subsystem need to define a minimal change of subsystem. It is a operation with «Exist» stereotype.

References

  1. V.I. Gurianov, Simulation with UML SP. Cheboksary: SPbSEU, branch in Cheboksary, 2014. - 136 p.(In Russian)
  2. S.P. Kurdyumov, H.N. Knyazeva, Foundations of Synergetics: Blow-up Regimes, Self-organization, Tempo-worlds, Saint-Petersburg: Aletheia, 2002
  3. Gregory R. Andrews, Foundations of Multithreaded, Parallel, and Distributed Programming, 1st Edition, 472 pages, ISBN: 0201357526,9780201357523