.OpenIPSL.Examples.Tutorial.Example_4.Instructions.PFRecordCreation

Creating the PF Structure

Information

Creating and Integrating the Power Flow Structure

After completing the instructions in Assembling a SMIB System, you should have a SMIB folder inside your working directory.

  1. Create a directory called SMIB_Example at the same level where the SMIB folder is located.
  2. Create a directory called models below your new SMIB_Example folder.
  3. Move the SMIB folder below the previously added models folder.
  4. Copy the pf2rec folder from Resources to the SMIB_Example folder.
  5. Move the create_records.py and run_pf.py Python files one level up (i.e., to the SMIB_Example folder). The tree below shows how your folder structure should look like:
    C:\Users\...>tree /f /a SMIB_Example
    Folder PATH listing
    Volume serial number is ...
    C:\USERS\...\SMIB_Example
    |   create_records.py
    |   run_pf.py
    +---models
    |   \---SMIB
    |       |   ...
    |
    \---pf2rec
        |   create_pf_records.py
        |   generate_component_list.py
        |   gridcal2rec.py
        |   __init__.py
        |   ...
        
  6. Reload your model or run Dymola, depending on what you did at the end of the previous section. Create a package inside the root package SMIB and name it Utilities.
  7. Add a new function inside Utilities called saveTotalSMIBModel. Remember that the procedure for creating functions is the same as for other kinds of classes such as Package, Model or Record.
  8. Go to the Modelica text of the function and type the following code:
    function saveTotalSMIBModel "Save the SMIB package as a total model"
      extends Modelica.Icons.Function;
      output Boolean ok "= true if succesful";
    protected
      String targetDir = "C:/Users/Miguel/SMIB_Example/models/SMIB";
    algorithm
      ok := saveTotalModel(targetDir + "/" + "SMIBTotal.mo", "SMIB", true);
    end saveTotalSMIBModel;
        

    🔨 Update the targetDir variable value with the appropriate path to reach the SMIB folder.

    📌 This function has no inputs and only one boolean output. The modelica standard function saveTotalModel is called inside the algorithm section with predefined arguments. You can check the information view of saveTotalModel to get to know the proper use of each of its parameters. To do that, make sure the DymolaCommands library is loaded within the Package Browser. Then navigate as shown in the picture below

    SaveTotalModelFunction


  9. Right-click the saveTotalSMIBModel function from the Package Browser. Select the " Call Function..." option and then click the OK button. As a result, you should be able to see a new file called SMIBTotal.mo in the same folder where your model files are being stored.
  10. Go to the system terminal, change the current directory to the location where the create_records Python script is placed and execute it as indicated below.
    python create_records.py
        
  11. Go back to Dymola and refresh ( RefreshButton) the SMIB package.

    📌 The Python script create_records should have created a new package inside your model that looks like this

    PFDataPackageStructure


  12. Double-click the SMIBPartial model to open its diagram view. From the new PFData package, drag and drop one PowerFlow element on your canvas. For convenience, rename it as pf.

    PowerFlowRecordInstantiation

  13. Link the power flow variables to the different components as indicated below. Yes, unfortunately you must type them!

    ComponentReferenceToPFRecord

    Component V_0 A_0 P_0 Q_0
    B01 (bus) pf.powerflow.bus.v1 pf.powerflow.bus.A1 N/A N/A
    B02 (bus) pf.powerflow.bus.v2 pf.powerflow.bus.A2 N/A N/A
    B03 (bus) pf.powerflow.bus.v3 pf.powerflow.bus.A3 N/A N/A
    B04 (bus) pf.powerflow.bus.v4 pf.powerflow.bus.A4 N/A N/A
    load (load) pf.powerflow.bus.v3 pf.powerflow.bus.A3 pf.powerflow.load.PL1 pf.powerflow.load.QL1
    InfiniteBus (gen) pf.powerflow.bus.v2 pf.powerflow.bus.A2 pf.powerflow.machine.PG2 pf.powerflow.machine.QG2

         If you check your model now, you should see an error because we have not defined the power flow values. We have just pointed to the container which will have it. Next, we generate the power flow results using GridCal.

  14. Now open the diagram layer of your SMIB model inside the Experiments package. Link the power flow variables to genunit as specified in the following table:
    Component V_0 A_0 P_0 Q_0
    genunit (gen) pf.powerflow.bus.v1 pf.powerflow.bus.A1 pf.powerflow.machine.PG1 pf.powerflow.machine.QG1

Generated at 2026-03-12T19:14:05Z by OpenModelicaOpenModelica 1.26.3 using GenerateDoc.mos