Modules vs. packages
Release 2.0 of Mosel introduced the possibility to write libraries for Mosel directly in the Mosel language, such a library is called a package. Packages are included into models with the uses statement for dynamic loading (the package BIM needs to be present for model execution), in the same way as this is the case for modules (DSO). Alternatively, packages can be loaded statically via imports in which case they get included in the model BIM file (this option is not available for modules that are always dynamic).
From the implementation and functionality points of view the two ways of writing Mosel libraries are not the same and the choice between packages and modules depends largely on the contents and intended use of the library. In some cases it may be convenient to split the implementation of a library into two parts, one as a module and the other as a package. If a module and a package on the specified DSO path have the same name, the package will be loaded by Mosel.
The following list summarizes the main differences between packages and modules.
- Definition
- Package
- library written in the Mosel language
- Module
- dynamic library written in C that obeys the conventions of the Mosel Native Interface
- Package
- Functionality
- Package
- define
- symbols
- subroutines
- types
- control parameters
- define
- Module
- extend the Mosel language with
- constant symbols
- subroutines
- operators
- types
- control parameters
- IO drivers
- extend the Mosel language with
- Package
- Efficiency
- Package
- like standard Mosel models
- Module
- faster execution speed
- higher development effort
- Package
- Use
- Package
- making parts of Mosel models re-usable
- deployment of Mosel code whilst protecting your intellectual property
- Module
- connection to external software
- time-critical tasks
- definition of new I/O drivers and operators for the Mosel language
- Package
With every module example in this manual we shall discuss the possibilities of implementing similar functionality as a package. For a detailed introduction to writing packages the reader is refered to the chapter 'Packages' of the Mosel User Guide.