A few years ago, I wrote a blog post about writing tidy code, pointing out that it’s a good idea to be disciplined when laying out a code layer. After all, you (or someone else) will be coming back to look at this code in the future, so laying it out in a clear, consistent way is smart and avoids headaches down the line. In today’s blog post I will cover the dirty code layer’s cousin, the dysfunctional Dymola graphics layer.
Being organized in your modeling isn’t only a good idea with regards to the text layer. Much of Dymola modeling is done in the graphics layer, where bad habits can also yield frustration caused by completely unnecessary confusion. Here are a few sensible rules to follow which will make you or your teammates’ lives easier in the long run:
- Avoid hybrid modeling if possible
- Lay out graphical connections in the least cluttered way possible
- Create distinctive icons
- Add unique identifiers on extended models
- Maintain consistency of input methods
Hybrid Modeling
Hybrid modeling is where both the text layer and the graphical layer are used to build the model. Sometimes, this can be unavoidable, such as when dealing with component arrays, where manual collation of connect statements in the text layer is needed. Controller models are a good example of where the best practice should be used to avoid unnecessary hybrid modeling, as many of the math functions could be undertaken in the text layer. By using math blocks, the calculation is easier to understand for the user.

Graphics layer connections
Connections between components are shown in the graphical layer, with lines of various colours and thicknesses for connections of different connector types. If there are only a few components in the model, organizing the connections can be easy. If there are many, you should be careful to lay them out, so it is easy to see which output is connected to which input.

Create distinctive icons
When components are instantiated within a model, the icon is responsible for identifying the component in the graphical layer. An appropriate and descriptive icon is thus vital to helping quickly identify the component in use. Over the years I’ve seen some highly dysfunctional Dymola graphics layers. In my early years of learning to use Dymola, I made plenty of them myself… eek!

One simple way to help identify a sub-model is by typing the string “%name” in a text box on the icon layer. This will yield an icon which displays the component name once instantiated.

Figure 4: Using %name” in a model’s icon layer makes the instantiated icon display the instantiated component name.
Add unique identifiers on extended models
Often, models with slightly different characteristics are extended from a common parent, reducing the library maintenance overhead by promoting model reuse. Icons are passed down from the parent to extended model, therefore all models derived from the common parent will have the parent’s icon by default. It’s thus sensible to add something simple to the icon layer to highlight the unique characteristic of the model.

Consistency of input methods
Inputs, unlike parameters, can vary during a simulation. They are used in a component to allow data to be passed to it during simulation. There are two primary ways for inputs to be passed into a model. The first way is in the graphics layer (via a connector). The second way is through the text layer (via the parameter dialog window). Mixing these two approaches in a single model is generally something to avoid, as during debugging determination of the origin of the data can be less obvious.

Closing remarks
Following best practices when working in the graphical layer, as well as the text layer will help you to create models which are easy to understand, and (possibly even more importantly) easy for others to understand. Much wasted effort down the line can be avoided by taking a few extra moments to avoid a dysfunctional Dymola graphics layer.
Nate Horn – Vice President
Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion.