Creating and Using Resource Tables

You can create and use resource tables.

In this scenario you create a resource table in the first task, then use it in the second task.

This task shows you how to:

Create a Resource Table

You can create resource tables.

In this part of the scenario, you create a resource table.

Before you begin: Do the following to create the model to work in and the table to be included in the resource table:
  1. Create a library MyLib with an empty model MyModel. See Create a Modelica Library and Create a New Class or Extend from an Existing Class Using the New Class Command.
  2. On your computer, in a folder of your choice, create a table as a text file MyTable.txt. For this scenario, to be able to later use it in the component CombiTable1D, insert the following text in the text file:
    #1
    double tab1(5,2)   # comment line
      0   0
      1   1
      2   4
      3   9
      4  16
    double tab2(5,2)   # another comment line
      0   0
      2   2
      4   8
      6  18
      8  32
  1. From the Tools section of the action bar, click Resource Table .

    Notes:
    • You can only have one resource table for each Modelica library.
    • For full information about creating and editing resource tables, see Engineering Rules Capture Users Guide: Creating a Resource Table.

    The Resource table management dialog box appears.
  2. In this dialog box, to add a new item in the table, click Add a new resource item .
    A new row appears in the table.
  3. Define the content of your new resource item by editing the new row:
    1. To assign a name to your new resource, double-click the Logical Name box and enter MyResource_MyTable1.
    2. Double-click the Resource Type box and select, for this scenario, Document.
    3. To find your resource, double-click the Resource box.
      A Content Chooser appears.
      Note: For more information about the Content Chooser, see Using the Content Chooser.
    4. In the Content Chooser, for this scenario, click the link Import a file and browse to the file MyTable.txt that you created earlier and then click Open.

      Note: You may have to change the file format to Text files in the dialog.

      An Engineering Document dialog box appears.
    5. In this scenario, leave the data in the Engineering Document dialog box unchanged and click OK.
      The following is the result:
      • The file is defined as an Engineering Document.
      • A new line appears in the Content Chooser.
    6. In the Content Chooser, click Accept All .
      The file is added in the Resource box.
  4. Click OK to validate the editing in the Resource table management dialog box.
    The following is the result:
    • The resource table is created.
    • In the tree, under the Relations.1 node, the resource table is displayed with an icon .
  5. Save your resource table and other work by Save.
  6. To edit the resource table, perform Step 1 again.

Use the Resource Table

You can use resource tables to get access to resources.

In this part of the scenario, you use the resource table to select the table file as interpolation settings for the output from a clock.

Before you begin: Do the following to set up a clock and a combitable component to interpolate the output from the clock:
  1. Perform the previous task to create the table and the model to work in.
  2. In MyModel, instantiate, to the left, Modelica.Blocks.Sources.Clock and to the right, Modelica.Blocks.Tables.CombiTable1D. For instantiation, see Instantiate from Any Package Browser.
  3. Connect them to each other.
    Tip: In the Connection dialog that appears, set the index to [1]. For more information, see Connect an Array of Connectors.

You can now define the data used to define the interpolation by using the table in the resource file.

  1. In the diagram, right-click the combitable component and select Edit Component Parameters to display the parameter dialog.

    For general information about this dialog, see Displaying and Editing Modelica Parameters.

  2. For tableOnFile, select true from the list.
  3. In the tableName box, type "tab1"

    This is the name of the first table in the table file, see the text in the table file you created previously.

  4. For fileName, click Edit after the text box.
    The Select Resources dialog box appears.
  5. In this dialog, click Select a resource contained in a Document in a resource table .
    A Select Resources dialog box appears. The columns corresponds to the columns in the Resource table management dialog box you used when you created the resource table, except for the last column that displays the library that the resource table is related to.
  6. Select the resource by clicking the line, and then click OK.
    The path to the resource appears in the fileName box of the parameter dialog.

    The path is:

    ModelicaServices.ExternalReferences.loadResource
    ("3dexperience://dbl/MyLib/resourcesset/MyResource_MyTable1")

    The first part is a built-in function for loading resources, the second part is the path to the resource, where dbl stands for Dymola Behavior Library.

  7. In the parameter dialog, click OK to validate the changes.
    You have now defined the interpolation setup by the table in the resource table.
  8. Optional: Save the model by Save.
  9. Optional: To test the interpolation, do the following:
    1. To define a suitable stop time, from the Behavior Authoring section of the action bar, click Execution Setup .
    2. From the General tab, set Stop time to 5s and click OK.
    3. To simulate, click Execute .
    4. From the Variable Browser, plot the input combiTable1D.u[1] and the output combiTable1D.y[1] and compare the resulting curves with the interpolation table you defined in the previous task.

      For plotting, see Plot One or Several Variables.