Use of the Model Management Library

With the installation of Dymola there is the Model Management library, which allows users to be able to gain data about models and even create and modify models. This can be a very powerful and useful tool, if used correctly. This post will go through a couple of examples and my favorite use of the library.

Abilities within the Library

The functions within the library are divided up into 3 categories:

  • Check – Library quality checking functions, to ensure existence of documentation and descriptions, check class name quality, create regression results and more library maintenance functions
  • Compare – Compare 2 models/packages, in terms of contents, equations and documentation and generate report.
  • Structure – Create, modify, and gain information from classes.

The application and use of the structure functions is the main focus of this blog post.

Creating and Modifying Double Pendulum Example

For this blog post I created a set of steps that will extend and then modify a double pendulum experiment. The set of functions can be used within a function or within a script. The unformatted code is below, but these are the steps, describing each function call:

  1. Create a new package called ModelManagementTests with the description “Package containing models to test modelManagement”
  2. Create a new model called DoublePendulum within the new ModelManagementTests package with the description “Test of the model management on double pendulum model”
  3. Add an extends statement to DoublePendulum which extends from “Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum”
  4. Add a new “Modelica.Mechanics.Rotational.Components.Spring” instance called revolute2Spring to the model, with a description of “Spring applied to revolute 2”
  5. Add diagram placement of revolute2Spring to be {{20,20},{40,40}} so that it can be seen on the diagram layer
  6. Within revolute2, change the parameter useAxisFlange=true
  7. Create a connection between revolute2Spring.flange_b and revolute2.axis
  8. Create a connection between revolute2Spring.flange_a and revolute2.support
  9. Within revolute2Spring, change the parameter c=10
  ModelManagement.Structure.AST.Classes.CreateClass(
    "",
    "ModelManagementTests",
    "Package containing models to test modelManagement",
    "package");

  ModelManagement.Structure.AST.Classes.CreateClass(
    "ModelManagementTests",
    "DoublePendulum",
    "Test of the model management on double pendulum model",
    "model");

  ModelManagement.Structure.AST.Classes.CreateExtends("ModelManagementTests.DoublePendulum",
    "Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum");

  ModelManagement.Structure.AST.Components.CreateComponent(
    "ModelManagementTests.DoublePendulum",
    "",
    "Modelica.Mechanics.Rotational.Components.Spring",
    "revolute2Spring",
    "Spring applied to revolute 2");

  ModelManagement.Structure.AST.Components.SetComponentPlacement(
    "ModelManagementTests.DoublePendulum",
    "revolute2Spring",
    extent={{20,20},{40,40}});

  ModelManagement.Structure.AST.Components.SetComponentModifiers(
    "ModelManagementTests.DoublePendulum",
    "revolute2",
    {"useAxisFlange=true"});

  ModelManagement.Structure.AST.Connections.CreateConnection(
    className="ModelManagementTests.DoublePendulum",
    from="revolute2Spring.flange_b",
    to="revolute2.axis");

  ModelManagement.Structure.AST.Connections.CreateConnection(
    className="ModelManagementTests.DoublePendulum",
    from="revolute2Spring.flange_a",
    to="revolute2.support");

  ModelManagement.Structure.AST.Components.SetComponentModifiers(
    "ModelManagementTests.DoublePendulum",
    "revolute2Spring",
    {"c=10"});

While this is a simple example it utilises a number of different functions within the Model Management Structure folder to perform some basic tasks. The application for this specific example could be looped to create multiple variances of different models. For example, automatically creating multiple versions of vehicles with different loads/spring/damping setups that can then be used in vehicle experiments.

Vehicle Initialisation

Personally, my favourite application of the model management library is using it to improve the ease of setting initialisation variables, building upon last month’s blog post from Theo about dynamic initialisation. Consider vehicle data, like hardpoints, which are defined to produce acceptable geometry (like ride height) for a set vehicle load, commonly when the vehicle is in an unloaded condition. But durability tests require multiple load cases and with a trailer attached. With the different loads and trailers the resting height and angles of the vehicle body and suspension compression will be different each load case. For efficient simulation we want the vehicle and trailer to initialise in a steady state without any time lost to vehicle settling.

To ease development, which would call for renewing the initialisation variables following almost every change to the vehicle, functions were created to automate that process. The function runs an initialisation experiment redeclaring to the chosen vehicle, with the suspension stiffness increased to a point where the deflection would be minimal when loaded. It then reads the results from that experiment to gain the spring force and body position and angles and then, using Model Management, applies those values to the vehicle.

I created a small folder that contains the pendulum example function above and a function to perform a vehicle initialisation test and parameter population. It can be downloaded by following the link below:

ModelManagementExample

Written by: David Briant – Senior Project Engineer

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?