Developing Component Models

To complete the project model it is necessary to develop models of all components we have created. At their creation they are empty and are represented by theirs word models, i.e. the components defined by their names (titles) and the ports. We need to add their model document. We show it on the example of Body component. In the similar way we can do it for the other components.

The components in BondSim are the containers of their model documents. To open its document we simply double click the component title. In this case we double clisk "Body" title. We can do it by selecting it first (i.e. by clicking its title) and then by applying Open Next command in Document menu, or applying the shortcuts (Open Component toolbar, or pgup key). Because it is a new component its document does not exists and program asks if we wish to edit a new model of Body. If we agree a new tabbed document is created and shown in the central part of the frame next to the project document (see the Figure below).

A new document created when opening Body component
Developing Component Models

It is similar to the project document we met earlier. It is empty, but contains on the outside of the document bounding rectangle the document ports. These ports are in the form of narrow rectangles with attached half-arrows and exactly correspond to the component ports. Thus, power is transferred from outside through the component ports and then out of the document ports into the component document. In the same way the power is transferred back from the inside thorough the document port and out of the component port. In this way the component and its document are two sides of the same coin.

To define the model of the body we insert the components, which constitute its model, into the document and connect them internally and to the document ports. To start with we insert 1 junction, which serves as the balance of forces acting on the body. It is also common velocity junction, i.e. its ports have the same flows - the body velocity. To create it we drag 1 junction tool from Bond Graph Components in Editing Box and drop it at the intersection of line connecting the left and right power ports and the vertical line through the bottom power port. We click outside of the component to retain its default title (‘1’). The component already has three power ports and we change their senses of the power transfer to correspond to that of the document ports (using Change Port toolbar button). Thus, the right one has to be the power-in port, and the left and bottom ports are the power-out. We connect then the ports of the junction to the document ports (see figure below on the left). 

The body has inertia. We, thus, insert an inertial component by dragging the corresponding tool and dropping it above the 1 junction. Again, we accept the default symbol (‘I’). The component has a single port on the left, and we drag it to face the 1 junction. To connect it to the junction we need to insert a power-out port at top of the 1 junction and connect it to the inertial component (see the figure below on the right). Thus, the input force acting on the body is equal to sum of body inertial force, and spring and damper forces. In Bond Graphs this is represented neatly.

Body model: (left) Efforts branching, (right) Added body inertia

Because we need to output information on the body velocity and its position, we will drag Control-out port tool and drop it at the lower-right corner of the 1 junction (see the figure below). This port extracts the body velocity. To branch this signal we insert a Node by dragging the corresponding tool from Continuous Signal Components and dropping it to the right and below of 1 junction. We connect the component input port to the output port of 1 junction. Its right output port we connect to the bottom right document output port. Thus, the body delivers its velocity to the right Body output port.

To generate the body position we need first to integrate the body velocity over time. To that end we drag and drop Integrator from Continuous Signal Components and drop it below the Node. We move the integrator input port from left to the top and the output port from the right to the bottom. We may need to move the Integrator so that its upper port lines up with the lower Node's port. Now we connect these two ports by a bond, and its lower port to the corresponding document output port. In this way we generated the Body position signal and deliver it to the output port.

The model of Body
Developing Component ModelsTo complete the Body model we need to define the constitutive relations that describe the elementary components, which make the model. We start with the inertial component and open its port by double clicking it. (We may also do it by selecting the port and applying command Open Next from Document menu.) The Inertial Port dialog opens as shown below.
Editing Body inertia
Developing Component Models

At the lower-left part of the dialog window there are the blocks that define the port variables; they have predefined local names. These variables are used to define the constitutive relation at the top of the dialog. We may change these freely. Thus, we change the flow to v (for velocity), and the state variable to p (momentum). Now we modify the constitutive relation at the top too. It defines the body momentum p as product of body mass m and its velocity v. It uses I0 as the inertial parameter and we change it to m and flow to v. Note that the effort variable was already set as time derivative of the momentum (per Newton’s second law). Finally, we need to define the body mass as a new parameter. We did it similarly as we did with the force parameter in SE component earlier using Parameters button. We insert the new parameter m and define its value as 5.0 (kg). Close these dialogs.

Note also that in Inertial Port dialog there is also a field which defines the initial value of the body momentum. By default it is set to zero. We assume that the body starts from the rest and, thus, we accept this value. Now we close the dialog by OK button. The all changes we have made including the new parameter are stored in I component object in the memory.

We will apply similar operations to Integrator ( ∫ ) ports. First we will define the integrator’s input symbol. Thus, we double click the input port and in the dialog that opens we type-in v as the symbol of the body velocity (see the figure below on the left) and accept it by OK. Next, we double click the integrator’s output port (see Figure below on the right). We change the output variable name to x (for the position). The integrator constitutive relation is automatically set. Its initial value was already set to 0.0. We may accept this, which means that the body displacement is measured from its zero initial position. We close dialog by OK button.

Integrator input (left) and output (right) dialogs
Developing Component Models Developing Component Models

Now we can close the Body document by clicking document window control (×) button. Because the document was changed, before closing the document the program asks us what we wish to do next by showing the following message dialog.

Save dialog options
Developing Component Models

To choose the proper button it is necessary to know how BondSim stores the projects. The project title that was created at beginning is stored in the project index (really a map, dictionary). Every project has a different name and corresponding files are stored in the corresponding BondSim program model directory in the corresponding file. The program generates the filenames automatically. We communicate with the program by the project name. The program locates the name in the project index, finds the corresponding filename and opens the project. These files, however, are not common files, but the special compounded files that have the structure of file system inside the file. They contain storages, which have roles of the directories, and streams which play the roles of the files.  

In the current implementation the project file has structure of the corresponding model tree. At the first level there is a storage, which corresponds to the project. It contains a stream that store the project document. Every component, which is not an elementary one, corresponds to the storage which contains a stream that store the component document. This document contains the other components, etc. In this way the structure of the project is stored in the same way in the storage medium (a disk) as in the memory. The elementary component, because they are rather simple, stores all data in the component object itself. When we close a document it is normally stored in its component. The stored document is not saved on the disk yet. We must store it down the model tree until the project document is reached and then the complete structure is saved to the disk. 

Thus, returning to the Save Dialog shown above, if we select Save button the dialog closes and the current document is stored in its component storage. If on other hand Save to all button is clicked the documents are stored down the model three until the project document is reached, and then the complete structure is saved to the disk in the corresponding file. We may also select Don’t save button, which means the rejecting of the changes made and closing the document. If we select Cancel button the document closing is rejected and the document stays open.