Generating a Modelica Model from an Engineering Model

You can generate a Modelica model from an engineering model.

The engineering model can be any of:

  • A 3D piping model in Piping & Tubing 3D Design.
  • A 3D HVAC model in HVAC 3D Design.
  • A schematic P&ID model in Functional & Logical Design.

For general information, see About Generating a Modelica Representation of an Engineering Model.

Notes:
  • The following scenarios describe how to open a physical product containing an engineering model and generate a Modelica model of it, and how complete this model to be able to simulate it. The first and second scenario describes how to use a command to generate the model in a stand-alone package and in a behavior, respectively. The third scenario describes how to use scripting to generate the model in a behavior.
  • If the engineering model is later modified, you can update the generated Modelica model. See Updating, from the Physical or Logical Model, a Generated Modelica Model of a Kinematic Mechanism or an Engineering Model.

This task shows you how to:

Generating a Modelica Model from an Engineering Model, in a Stand-Alone Package, Using a Command

You can generate a Modelica model from an engineering model in a stand-alone Modelica package, using a command.

Before you begin:

The following apply:

  • The engineering model objects and the related parameters must be mapped to Modelica libraries. See Mapping Engineering Model Objects and Parameters to Modelica Libraries.
  • The Modelica libraries used for the mapping must be installed.
  • Make sure that you have access to the following apps:
    • For the generation of 3D Piping, both the Dymola Behavior Modeling app and the Piping & Tubing 3D Design app.
    • For the generation of 3D HVAC, both the Dymola Behavior Modeling app and the HVAC 3D Design app.
    • For the generation of schematic P&ID, both the Dymola Behavior Modeling app and the Functional & Logical Design app.

  1. From the top bar, search the source model in the following way, depending on the model:
    • If the model contains a physical product, you can search for that physical product. For example, you can search for a physical product with the name Piping_Product by typing prd:*Piping_* in the Search field and click Search .
    • If the model contains only a logical part, that is the case for some schematic P&ID models, you can search for the logical part. For example, you can search for a logical part with the name My_P_ID_Model by typing log:*My_P_ID_Model* in the Search field and click Search .

    For more information about searching, see 3DEXPERIENCE Native Apps: Native Apps Top Bar.

    The Search Results panel appears.
  2. To open the product, right-click it in the Search Results panel and select Open With > Smart Open in RFLP .
    The product is opened in authoring mode.
    Notes:
    • For a 3D piping product, if the product is not opened in Piping & Tubing 3D Design, open that app from the Compass.
    • For a 3D HVAC product, if the product is not opened in HVAC 3D Design, open that app from the Compass.
  3. Optional: If you are to generate Modelica code for a subsystem of the 3D piping or HVAC model, select the piping or HVAC objects in the subsystem the following way:

    Important: For a schematic P&ID model, use instead the filtering in the mapping to select subsystem.

    1. Expand the tree for the physical product to see the piping objects.
    2. In the tree, select the piping or HVAC objects in the subsystem.
  4. To store the generated model, create a new Dymola Behavior library, with the name MyGeneratedModels. See Create a Dymola Behavior Library.
    The result is:
    • You enter Dymola Behavior Modeling in a new tab.
    • A Dymola Behavior Library MyGeneratedModels is created in the new tab.
    Tip: To work more comfortably between the apps, make both tabs visible on the screen.
  5. In Dymola Behavior Modeling, open the Modelica libraries that you have stored your mapping tables in.
  6. To generate the Modelica model, from the Behavior Tools section of the action bar, click Generate from Engineering Model .
    The Generate Modelica from Engineering Model dialog box appears.
    Note: If you already have an active model that is generated by this command, the dialog is prefilled with the setup used for generating this model.
  7. Click the Engineering Model field and select any of:
    • For a piping or HVAC model: In the tab where the model is seen, under the Physical node of the tree, select any part of the model to be used for the Modelica model generation.
    • For a schematic P&ID model: In the tab where the model is seen, in the tree, select the relevant logical schematic view to be used for the Modelica model generation.
      Important: Select the same logical view as the logical view selected as the working model for the mapping.
    The name of the model appears in the Engineering Model field.
  8. Select the parent class where the generated model should be inserted the following way:
    1. Click the Insert in field.
    2. In Dymola Behavior Modeling, from the Package Browser, or in the tree, click the package where you want to insert the Modelica representation. In this scenario, click the library you created.
  9. Click the Output class name field and enter a name for the Modelica model to be created. In this scenario, enter MyGeneratedPipingModel.
  10. Select Mapping to use for the model generation.

    Note: You can select from:
    • The default mapping tables.
    • Mapping tables that you have saved in Modelica libraries that are open in session.
    • If you have mapping tables saved in the database in older versions than 3DEXPERIENCE R2022x GA, they are available as well.

  11. Optional: Click More >> to see optional selections.
  12. Optional: To generate Modelica code for a subsystem, do the following:

    Important: In the 3D piping or HVAC model, you must select subsystems before using the Generate from Engineering Model command. See Step 3.

    Important: For a schematic P&ID model, use instead the filtering in the mapping to select subsystem.

    1. Activate Advanced Selection.

      By default, this option is not activated.

      The following is the result:
      • A Multi-Selection dialog box appears.
        Important: The Multi-Selection is grayed and is not used when selecting subsystems this way when you have the piping model in a separate tab. Compare with the next task where you use behaviors instead.
      • The selection of Engineering Model is reset.
    2. Reselect the piping or HVAC model, see Step 7.
    You have selected subsystems to generate Modelica code for.
  13. Optional: To rebuild the model when performing any general update command, that is, any of the commands Update or Update Assistant, activate the Rebuild at PLMUpdate.

    By default, this option is activated.

    A reason for clearing this option can be if you want to compare two alternatives of a model without risking that an update command updates the wrong model.

  14. Optional: To use thumbnail pictures from the 3D model, activate Generated Icons from Model.

    By default, this option is activated.

    If this option is cleared, the icons of the components from the 2D diagram are used instead.

    Note: The selection is kept when closing and opening the dialog box, unlike for the other options. When you start a new session, the default setting is used.

  15. Optional: Select Layout algorithm:
    • Force-based (default selection for generation from a 3D Piping or HVAC model)
    • Projection
    • From Schematics (default selection for generation from a schematic P&ID model)
    • No Diagram

    For information about the alternatives, see Generated Diagram Layer and 3D Representation.

  16. Click OK to start the model generation.
    The following is displayed in the Package Browser under the selected target package MyGeneratedModels:

    • A package InternalGenerated that contains a package MyGeneratedPipingModel. This package contains:
      • A base class MyGeneratedPipingModel that is the generated main model. The class is represented by the icon . Under this base class, there is a subpackage containing the media of the model.
        Notes:
        • Do not edit this class. It is for internal use.
        • If you have selected to generate Modelica code for subsystems, the generated main model contains the subsystems.
      • A number of subpackages containing the generated Modelica component classes corresponding to the engineering model components. These components can be used to build new models. The components also include records containing data from the physical model; this means that this data can be used in new models.
        Note: These classes are by default hidden. For information on how to display these classes, and how to use them, see Overview with Protected Classes Displayed, For Advanced Users.
    • An extended class MyGeneratedPipingModel. The class is represented by the same icon as the base class: .
      Note: This is the class that you can edit to, for example, extend the model or replace components. It is by default opened when the model is generated.
    Tip: For more information about the features of the generated classes, see About Generating a Modelica Representation of an Engineering Model. Examples of such features are:
    • Modifying the mapping from a selected class in the generated model
    • Handling animation
    • Replacing of components
    • Using generated components in other models
    • Reusing data from the physical model in other models
  17. To prepare the generated main model for testing, do the following:

    Important: This step describes how you can set up a very simple generated main model for simulation. For more information about creating simulation models from more realistically generated models and components, see Building a Simulation Model.

    Note: Usually generated components are just components. You must connect them to test them.

    1. In MyGeneratedModels, create a new model TestMyGeneratedPipingModel. See Create a New Class or Extend from an Existing Class Using the New Class Command.
    2. To instantiate MyGeneratedPipingModel, drag it into the TestMyGeneratedPipingModel model.

      Important: Drag the right model, the top-level model, do not drag the model inside the InternalGenerated package.

    3. Connect the parameters that need connection.

      You might need to drag other components into the model and connect them, depending on the model.

    The MyGeneratedPipingModel model is now connected to a simple "test rig" to test it.
    Note: The structure of libraries is often more elaborate. For example, it is common to have a separate library for some generated models, and another library to use them in customer models.
    Tip: It is useful to view the diagram of the generated model. As an example, you can see if connections between components are missing.
  18. Simulate the model. See Simulating a Behavior.

Generating a Modelica Model from an Engineering Model, in a Behavior, Using a Command

You can generate a Modelica model from an engineering model in a Dymola behavior using a command.

Before you begin: The following apply:
  • The engineering model objects and the related parameters must be mapped to Modelica libraries. See Mapping Engineering Model Objects and Parameters to Modelica Libraries.
  • The Modelica libraries used for the mapping must be installed.
  • Make sure that you have access to the following apps:
    • For mapping of 3D Piping, both the Dymola Behavior Modeling app and the Piping & Tubing 3D Design app.
    • For mapping of 3D HVAC, both the Dymola Behavior Modeling app and the HVAC 3D Design app.
    • For the generation of schematic P&ID, both the Dymola Behavior Modeling app and the Functional & Logical Design app.
  1. From the top bar, search the source model in the following way, depending on the model:
    • If the model contains a physical product, you can search for that physical product. For example, you can search for a physical product with the name Piping_Product by typing prd:*Piping_* in the Search field and click Search .
    • If the model contains only a logical part, that is the case for some schematic P&ID models, you can search for the logical part. For example, you can search for a logical part with the name My_P_ID_Model by typing log:*My_P_ID_Model* in the Search field and click Search .

    For more information about searching, see 3DEXPERIENCE Native Apps: Native Apps Top Bar.

    The Search Results panel appears.
  2. To open the product, right-click it in the Search Results panel and select Open With > Smart Open in RFLP .
    The product is opened in authoring mode.
    Notes:
    • For a 3D Piping product, if the product is not opened in Piping & Tubing 3D Design, open that app from the Compass.
    • For a 3D HVAC product, if the product is not opened in HVAC 3D Design, open that app from the Compass.
  3. On the Logical node in the tree, create a new logical reference containing a Dymola behavior, the following way:

    The following is a short description, for details see the corresponding documentation in Functional & Logical Design User´s Guide: Managing Behaviors in Functions and Logical Components.

    1. In the tree, right-click the Logical node and select Insert New Logical Component.
      The New Content panel appears.
    2. In this panel, expand Logical and select Logical Reference.
      A logical reference appears under the Logical node in the tree.
    3. From the Behaviors section of the action bar, click Insert New Behavior Representation .
    4. In the tree, click the logical reference you just created.
      The New Content panel appears.
    5. In this panel, select Dymola Behavior.
      A Dymola behavior is created under the logical reference.
    You have created a logical reference (component) with a Dymola behavior inside it.
  4. In the Dymola behavior, create a package that is to be the target for the Modelica representation of the engineering model, in the following way:

    The following is a short description, for details see Create a New Class or Extend from an Existing Class Using the New Class Command.

    1. In the tree, expand the logical reference you created and double-click the node MainModel .

      The MainModel represents the Dymola behavior.

      The behavior is opened in the Dymola Behavior Modeling app.
    2. From the Behavior Authoring section of the action bar, click New Modelica Class .
      The New Class dialog box appears.
    3. In this dialog box, do the following:

      1. In the Name field, enter, for this scenario, MyGeneratedModels.
      2. From the Class type list, select the Package type.
      3. Make sure that the Insert in field displays MainModel, otherwise select this model from the Package Browser.
      4. Click Ok to validate the selections.

    You have created the empty target package MyGeneratedModels in the Dymola behavior. You can see it under MainModel in the tree.
  5. In Dymola Behavior Modeling, open the Modelica libraries that you have stored your mapping tables in.
  6. To generate the Modelica model, from the Behavior Tools section of the action bar, click Generate from Engineering Model .
    The Generate Modelica from Engineering Model dialog box appears.
    Note: If you already have an active model that is generated by this command, the dialog is prefilled with the setup used for generating this model.
  7. Click the Engineering Model field and select any of:
    • For a piping or HVAC model: In the tab where the model is seen, under the Physical node of the tree, select any part of the model to be used for the Modelica model generation.
    • For a schematic P&ID model: In the tab where the model is seen, in the tree, select the relevant logical schematic view to be used for the Modelica model generation.
      Important: Select the same logical view as the logical view selected as the working model for the mapping.
    The name of the model appears in the Engineering Model field.
  8. Select the parent class where the generated model should be inserted the following way:
    1. Click the Insert in field.
    2. From the Package Browser, or in the tree, click the package where you want to insert the Modelica representation. In this scenario, click the package MyGeneratedModels you created.
  9. Click the Output class name field and enter a name of the Modelica model to be created. In this scenario, enter MyGeneratedPipingModel.
  10. Select Mapping to use for the model generation.

    Note: You can select from:
    • The default mapping tables.
    • Mapping tables that you have saved in Modelica libraries that are open in session.
    • If you have mappings saved in the database in older versions than 3DEXPERIENCE R2022x GA, they are available as well.

  11. Optional: Click More >> to see optional selections.
  12. Optional: To generate Modelica code for a subsystem, do the following:

    Important: For a schematic P&ID model, use instead the filtering in the mapping to select subsystem.

    1. Activate Advanced Selection.

      By default, this option is not activated.

      A Multi-Selection dialog box appears.
    2. In the tree, under the Physical node of the tree, click the piping or HVAC submodels to be used for the Modelica model generation.
      The selected submodels appear in the list of the Multi-Selection dialog box.
    3. To see the list of selected submodels, click List of selected elements.
      An Element List appears.
    4. To validate the list of selected submodels, click Finish.
      The list is validated and the Multi-Selection dialog box is grayed.
    You have selected subsystems to generate Modelica code for.
  13. Optional: To rebuild the model when performing any general update command, that is, any of the commands Update or Update Assistant, activate the Rebuild at PLMUpdate.

    By default, this option is activated.

    A reason for clearing this option can be if you want to compare two alternatives of a model without risking that an update command updates the wrong model.

  14. Optional: To use thumbnail pictures from the 3D model, activate Generated Icons from Model.

    By default, this option is activated.

    If this option is cleared, the icons of the components from the 2D diagram are used instead.

    Note: The selection is kept when closing and opening the dialog box, unlike for the other options. When you start a new session, the default setting is used.

  15. Optional: Select Layout algorithm
    • Force-based (default selection for generation from a 3D Piping or HVAC model)
    • Projection
    • From Schematics (default selection for generation from a schematic P&ID model)
    • No Diagram

    For information about the alternatives, see Generated Diagram Layer and 3D Representation.

  16. Click OK to start the model generation.
    The result is the same as in the previous task (except that the package is now generated in a Dymola behavior). See Step 16 in the previous task.
  17. Perform Step 17 and Step 18 from the task above to test the generated model.

Generating a Modelica Model from an Engineering Model, in a Behavior, Using a Scripting Method

You can generate a Modelica model from an engineering model in a Dymola behavior using an Engineering Knowledge Language (EKL) method.

Notes:
  • This scenario describes how to use the scripting method GenerateBehaviorModelFromPiping to generate a Modelica model from a 3D piping model when both the 3D piping model and the target Modelica package in a Dymola behavior is created and open. The creation of the target Modelica package is included in the scenario.
    Note: The handling is similar for an HVAC model or a schematic P&ID model.
  • The scripting method does not support selecting a piping submodel for generation, but there is a scripting method GenerateBehaviorModelFromSinglePipingObject that can generate a Modelica model from one piping object. This script has the same arguments as the script treated below, and it is used the same way. The difference is that for the argument of type ProductOccurence you must select a single piping object.
  • The scripting method can only use 2D diagram icons for representing equipment and piping parts in the generated model.

Before you begin: The following apply:
  • The engineering model objects and the related parameters must be mapped to Modelica libraries. See Mapping Engineering Model Objects and Parameters to Modelica Libraries.
  • The Modelica libraries used for the mapping must be installed.
  • Make sure that you have access to the following apps:
    • For mapping of 3D Piping, both the Dymola Behavior Modeling app and the Piping & Tubing 3D Design app.
    • For mapping of 3D HVAC, both the Dymola Behavior Modeling app and the HVAC 3D Design app.
    • For mapping of schematic P&ID, both the Dymola Behavior Modeling app and the Functional & Logical Design app.
  1. Perform Step 1 - Step 5 from the previous task.
  2. To start creating the scripting function, do the following:
    1. From the Compass, click 3D Modeling Apps .
    2. Expand 3DEXPERIENCE Roles and Apps.
    3. Expand My 3D Modeling apps.
    4. Select Engineering Rules Capture.
  3. From the action bar, click Action .

    For full information about actions, see Engineering Rules Capture Users Guide: Working with Actions: Creating an Action.

  4. In the Action Editor, do the following:

    In this step, you create a script with two arguments corresponding to the target Modelica package and the source mechanism.

    1. In the Argument list, do the following:

      • Right-click <Add new argument> and select Add new argument.
        Tip: You can also double-click <Add new argument>.
      • Type MyTargetModelicaPackage.
      • Click the corresponding Type field.
      • From the list, double-click ModelicaPackage

      The argument for the target Modelica package is created.
    2. Create a second argument MySourcePipingModel of type ProductOccurence in the same way as the first argument.
    3. Click the text pane to enter it.
    4. Press Enter to go to a new line.
    5. Do the following to create the text in the script:

      1. Type MyTargetModelicaPackage. and wait.

        When you have entered the period, after a short while, a list of available methods appear.

      2. From the list, double-click GenerateBehaviorModelFromPiping.

        This text is added.

      3. Enter a left bracket.

        A tooltip with an argument list appears.

      4. Type MySourcePipingModel,"MyGeneratedPipingModel").

        The script is complete, MyGeneratedPipingModel is the name you select for the model to be generated in the Modelica target package, to be consistent with the task above.

        Note: If you want to specify which mapping to file to use, other than the default one, enter the mapping file name as a last input in the script, for example, specifying the mapping file name to "New2": MySourcePipingModel,"MyGeneratedPipingModel","New2")

      The script is now
      MyTargetModelicaPackage.GenerateBehaviorModelFromPiping(MySourcePipingModel,"MyGeneratedPipingModel")
    6. Click OK.
    The result is:
    • The action is created.
    • In the tree, under the Relations.1 node, the action is displayed with an icon .
  5. In the tree, under the Relations.1 node, right-click Action.1 and select Action.1 object > Run.
    An Insert Object dialog box appears for specifying the arguments of the script.
  6. To specify the arguments and run the script:
    1. You can leave the Name blank.
    2. In the tree, click MyGeneratedModels to specify the target Modelica package for the generation.
    3. In the tree, under the Physical node, click the 3D piping representation to be used in the generation.

      Important: You must click the 3D piping model representation.

    4. Click OK.
      The script is executed with the result corresponding to the result of Step 16 in the first task above, except that the model is generated inside a behavior.
  7. To leave the Engineering Rules Capture app, do the following.
    1. From the Compass, click 3D Modeling Apps .
    2. Expand 3DEXPERIENCE Roles and Apps.
    3. Expand My 3D Modeling apps.
    4. Select Functional & Logical Design.
  8. Perform Step 17 and Step 18 from the first task above to test the generated model.