Search code examples
modelicadymola

Absolute and relative path conflict in Modelica


I want to build up a tests library and keep it separated from the libraries under development. My first thought is to go for a structure like the following:

PensLib
--Variants
----BallPoint
----FountainPen
----Tests
------TB_BallPoint

HammocksLib
--Variants
----SingleHammock
----DoubleHammock
----Tests
------TB_DoubleHammock
--Systems
----IndoorWalls
----OutdoorWallAndTree
----CoconutPalms
----Tests
------TB_IndoorWalls
Tests
--PensLib
----Variants
------Test_BallPoint      // extends PensLib.Variants.Tests.TB_BallPoint
--HammocksLib
----Variants
------Test_DoubleHammock  // extends HammocksLib.Variants.Tests.TB_DoubleHammock
----Systems
------Test_IndoorWalls    // extends HammocksLib.Systems.Tests.TB_IndoorWalls

For now let's assume that the way I structure my libraries make sense (which most likely doesn't). I will soon ask more questions on good practices in setting up the testing environment in Dymola and with the Testing Library.

My question is about the correct way to handle relative and absolute paths within models, if possible at all.

  • The model PensLib.Variants.Tests.TB_BallPoint is used for developing the variant BallPoint
  • The model Tests.PensLib.Variants.Tests_BallPoint is used for automated testing

I want the model Test_BallPoint to extend the model TB_BallPoint, but I cannot link them. I guess the absolute path PensLib.Variants.Tests.TB_BallPoint is treated as a relative one, since PensLib is found "on the way out" of the Tests library, and from there it goes looking for the rest of the path. Is there perhaps a way to control the path, kind of ..\..\..\PensLib\Variants\Tests\TB_BallPoint?


Solution

  • As you already noted such a setup makes troubles. There are ways around that, namely global name lookup and imports, which I explain briefly further below.

    Both solutions are nice when you have such a case in a few situations. But if you have to use it all the time, you make your setup unnecessarily complicated.

    Hence, I suggest to make yourself the live easier and change your package structure:

    • Either create a dedicated test library for every library, maybe PensLib_Tests and HammocksLib_Tests
    • Or rename the packages in the Tests library and don't use the exact library names
    Global name lookup

    You can use absolute class paths. They are denoted with a leading ., so this should work:

      extends .PensLib.Variants.Tests.TB_BallPoint;
    

    See Modelica Specification chapter 5: Scoping, Name Lookup, and Flattening for details, especially 5.3.3 Global Name Lookup

    Importing

    You can simply import the library. Lookup of imports is always performed globally.

      import PensLib;
      extends PensLib.Variants.Tests.TB_BallPoint;