Avoiding the Dysfunctional Dymola Graphics Layer

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.

Figure 1: This block, calculates a desired yaw rate for stability control applications.  It is a good example of using a block based approach to a math calculation, making it easy for the user to understand what is happening.
Figure 1: This block, calculates a desired yaw rate for stability control applications. It is a good example of using a block based approach to a math calculation, making it easy for the user to understand what is happening.

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.

Figure 2: This Electronic Stability Control model is a good example of well laid out connections. Colour coding also helps to understand which connection leads where.
Figure 2: This Electronic Stability Control model is a good example of well laid out connections. Colour coding also helps to understand which connection leads where.

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!

Figure 3: An image of the system, can be a good icon. This quarter car linkage is fairly easily identifiable as a MacPherson strut.
Figure 3: An image of the system, can be a good icon. This quarter car linkage is fairly easily identifiable as a MacPherson strut.

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.

Figure 5: All VeSyMA vehicle models are derived from common templates. This vehicle is extended from the Small Family FWD MT model, with an added ESP system. Addition of the text identifier ESP helps to quickly identify the model type and configuration.
Figure 5: All VeSyMA vehicle models are derived from common templates. This vehicle is extended from the Small Family FWD MT model, with an added ESP system. Addition of the text identifier ESP helps to quickly identify the model type and configuration.

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.

Figure 6: In the VeSyMA libraries, summary records feature inputs to enable important data to be easily identified in the simulation results. Rather than some input connectors and some inputs typed in the parameter dialog window, all the inputs are entered via the parameter dialog window.
Figure 6: In the VeSyMA libraries, summary records feature inputs to enable important data to be easily identified in the simulation results. Rather than some input connectors and some inputs typed in the parameter dialog window, all the inputs are entered via the parameter dialog window.

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.

CONTACT US

Got a question? Just fill in this form and send it to us and we'll get back to you shortly.

Sending

© Copyright 2010-2023 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?