Abstract
Advances in computer technology have made it possible to simulate various phenomena. In this study, we propose a meta-structure of a physical phenomenon as a pattern for efficient development of simulation systems. We first focus on dynamic phenomena such as simulations of physical phenomena, and clarify the pattern based on the structure of differential algebraic equations. The pattern consists of a phenomenon-independent part (Object) and a phenomenon-dependent part (Action). In addition, variables unique to each phenomenon are given to the relationship between phenomena-dependent terms. By using such a structure, it becomes possible to separate the specific and common parts of each phenomenon, and to define a structure that can be flexibly applied to various problems. In this paper, we present the effectiveness of the pattern by applying the pattern not only to a simulation of physical phenomena, but also to a simulation of infectious diseases. We also show the relationship between Objects as expressed by Action.
Introduction
Recently, the problems facing society are more complex and relate to many different domains. For example, to control the epidemic in COVID, it is not enough to discuss the medical field, but the economic field is also important. And we need to consider how the fields affect each other. In the Industrial domain, CASE is the focus of attention. This also needs to be expanded from the fields to consider now. So, we need to integrate various domains and make them easy to understand without expertise. And reusable modeling approach is important.
Numerical simulations are being used to solve a variety of problems as computer performance improves. But normally when simulating for a phenomenon, individual experts convert phenomena into mathematical expressions for their domains, program them, and study the problems (Fig. 1a). This Step need deep understanding of the phenomenon at the expert level, and thus it is difficult to use by expert of a different domain. So it is important to decompose the phenomena and build libraries by experts and reuse this library by non-experts (Fig. 1b).
(a) Individual domain model. (b) Componetaized phenomena by Domain Expert and assembled components by non-expert.
Features of physical modeling. (a) Component-based representation of phenomena (Car simulation model). (b) Acausal Connection (Mass-Spring-Damper model). (c) Process to calculation in Modelica language.
In the physical domain, they use physical modeling to increase the reusability of simulation (e.g., Modelica Language [1], Bond graph method [3], VHDL-AMS [4]). Physical modeling is the way of modeling and simulating physical phenomena by componetizing them. But this way of being constructed is based on conservation laws and it isn’t clear how to build libraries for phenomena without conservation laws. So, to reusable numerical simulation libraries for problems outside the physical domain need the pattern independent of conservation laws.
To solve this problem, we proposed the pattern without conservation laws based on physical modeling for physical domain [8]. In this paper, we show that when this pattern is applied to multiple “Objects”, the relationship between “Objects” is expressed by “Action”.
This paper is organized as follows.
Section 2. Overview of the Modelica modeling and previous research applying design patterns.
Section 3. Describe proposed pattern: “Object-Action Pattern”.
Section 4. Show examples of the pattern applied to non-physical domain and the relationship between Objects as represented by an Action.
Section 5. Summarizes and discusses prospects.
Physical modeling
This section describes the features of physical modeling, with the Modelica language as an example.
The Modelica language is the object-oriented language designed to simulate large, complex physical phenomena [1, 2]. To improve readability, the physical phenomena to be reproduced are modeled graphically and intuitively by means of diagrams called object diagrams. In addition, we create elements that reproduce the phenomenon in a section called a library, and in the elements, mathematical expressions are defined. We use these elements as instances to build simulation models.
To enable graphical representation and calculation, the Modelica language has the following characteristics of thinking/implementing formulas.
Object-Action pattern.
Component-based representation of phenomena
In Modelica, individual phenomena are represented as components, and mathematical expressions are constructed in each component (Fig. 2a). This feature allows one the model to be created by selecting the elements that compose the phenomenon. This feature allows to focus only on the mathematical expression of the phenomenon without worrying about the order of processing.
Acausal connections and through/across variables
The Modelica language has a special meaning for a connection between elements. In the normal block diagram, the value of the output port is assigned to the value of the input ports to which it is connected (e.g. Simulink [5]). On the other hand, through variables and across variables are defined in Modelica language, and through variables equal to zero (so-called conservation law) and across variables are equal in the connections (Fig. 2b). This feature allows one to avoid considering about the input-output relationship between components, but it is difficult to find the through variables.
The actual calculation method of the formula is not defined
Modelica language specification does not define how to solve the model. Therefore, each Modelica supported tool interprets and analyzes the mathematical expressions (Fig. 2c). This feature allows one to focus on only creating models.
These features allow non-experts to model simply by connecting the relationships if non-physical phenomena are componentized.
With the goal of designing reusable classes and libraries, Gamma et al. classify their experiences in designing object-oriented software as 23 design patterns [6]. Clauß et al. have also applied this design pattern to Modelica with the goal of creating highly reusable libraries for different physical domains [7]. They provide examples of three design patterns.
Adapter: To adapt interfaces to different physical domains. Strategy: To adapt different algorithm signals with time dependence. Abstract Factory: To provide a unique interface for creating/using different parameter sets and equations for models.
On the other hand, they did not consider patterns that included feature of acausal connections in the previous section. And their pattern does not focus on how to choose Through variables, so conservation laws in that domain are assumed. Therefore, this pattern does not focus on non-physical phenomena for which conservation laws are not known.
In subsequent chapters, we will describe the proposed pattern without conservation laws based on physical modeling [8].
In this section we explain the proposed pattern for improving reusability in numerical simulation models: Object-Action Pattern. The scope of the pattern is the simulation model for phenomena depending on the time. The model described by the Differential-algebraic system of equations (DAEs, Fig. 3 right equations). Proposed pattern consists of four steps (Fig. 3 left diagram).
Adpted Object-Action pattern to moving ball.
Adopted Object-Action pattern Step. 1–2 to SIR model.
In the first, the phenomenon is decomposed to Object and Action. The purpose of this step is to decompose the independent phenomena to Object and the dependent one to Action terms. In the time evolving phenomena, the universal relationship is time derivative, so the Object calculate the time derivative, and the Action calculates the change value over time.
This decomposition becomes able to simulate different phenomena by changing Action.
Define Through/Across variables
Decompose/compose Action (Step. 3).
Extract common relations (Step. 4).
Modelica diagram of SIR model (upper left) and results (upper right), SIR 
Next, we define the variables between two elements. The Across Variable is defined to describe the attribute of Object for example displacement x, and velocity v. The Through Variable is defined the time variation of the Across Variable. The Across Variables are calculated in the Object using the through variables and input to the Action. Through variables calculate the Action using the Across variable and input the Object. The model defines the relationship as connection.
In physical modeling in the physical domain, the two variables are derived from conservation laws. So, in domains without known conservation law, it was not clear what to choose for these variables. But this proposed pattern gives a good view of what variables should be chosen.
By the previous step, it is still necessary to create an Action for each phenomenon, that is not reusable. So in the next step, Action is decomposed to Sub Actions by each term to improve reusability. For example, falling ball Action is decomposed change velocity over time by gravity and air damping. For decomposed Action, we re-define the connection. The connection calculates the sum of through variables and inputs the sum of these Objects. This calculation is the same as the one in Modelica’s acausal connections described in the previous chapter.
Extract common relations
In Step 4, Abstract Action is defined to extract common relations in Actions. For example, Abstract Action is defined to action and reaction laws in the dynamical system. And damping or gravity extends this abstract action.
Step 3 and 4 are also related to interactions and are discussed in detail in the next section.
Figure 4 shows how to create the library using this pattern and simulation using the library. Ball is defined as calculation of time derivative of displacement and velocity, MovingConnector is defined as Through/Across variables. AbstractMoving Element is defined as Action and reaction laws. Individual elements define the acceleration in individual phenomena and extend AbstractMoving.
Right Diagram and results show two phenomena, Falling Ball and Rolling Ball. It demonstrates that the combination of Action can be expressed by the various phenomena.
Adopted Object-Action pattern to Objects (interaction)
Next, we apply the patterns to the SIR model, a basic mathematical model that models the epidemic dynamics of infectious diseases transmitted directly from person to person (Eq. (1)). It shows an example of application to a non-physical phenomenon and also shows that “Action” expresses the relationship between “Objects”.
Figure 5 shows the same study as Step. 1 and Step. 2 in the previous section. The equations include susceptible, infectious, and recovered populations. Since they all refer to population quantity, we select population p as the across quantity. Also, the time derivative of the population dp is selected as the through variable.
Figure 6 shows about Step. 3. On the left, Action is decomposed into its individual SubAction. Looking at each SubAction, Inf1 calculates the through variable
In Step. 4, we should consider whether there are any common relationships other than the through and across variables to the outside. For both the infection and recovery terms, the relationship is such that if the through variable related to one Object increases, the Through variable related to the other Object decreases by the same. Thus this relationship is defined in “Abstract Action” Class (Fig. 7 Left).
Upper Fig. 8 shows the model and simulation results using this library. The solid(red) line shows the change of susceptible populations and dash(green) shows infected ones and dash-dot(blue) shows recovered populations.
Next, when considering death, the model can be easily changed like the bottom Fig. 8. The relationship between time variation of deaths and each population are the same as in recovery, so it can be reused without modification.
In this paper, we proposed the pattern so called “Object-Action Pattern” for reusable numerical simulation libraries for problems outside the physical domain. This pattern consists of 4 Steps. First step is to decomposed phenomena to Object and Action. Next is to define Through and Across variables to be passed between Object and Action. Then Action is decomposed and the sub-Action is composed for reusability. Finally, common relations are extract of from Action. We also showed that when a pattern is applied to multiple Objects, Action is expressed as a time-varying relationship between Objects. The pattern was also applied to non-physical phenomena, and then we showed the example of how to reuse the model for another one. Usually, it is difficult to change the equation a little for non-expert in the domain. But this way makes it possible to change the phenomenon by only adding elements.
In the future, we will investigate experts in non-physical domains to build models and verify the ease of use. And we will investigate the possibility of applying proposal pattern across multiple domains.
