Modelica Standard Library

repository·master·Indexed 20 days ago

https://github.com/modelica/modelicastandardlibrary

A foundational collection of physical models and mathematical functions for Modelica-based simulation environments. It provides standardized components for mechanics, electronics, fluid dynamics, thermal systems, control systems, and mathematical utilities. The library includes C-source code for object libraries such as ModelicaExternalC, ModelicaIO, ModelicaMatIO, and ModelicaStandardTables, as well as zlib for data compression.

Tokens
4.2K
Snippets
6
Records
33
Agent score
69%

What's inside Modelica Standard Library

  1. Overview of the Modelica Standard Library

    master

    The Modelica Standard Library (package Modelica) is a free, comprehensive library developed by the Modelica Association. It provides standardized model components and interfaces across multiple engineering domains, including:

    • Mechanical: 1D and 3D modeling.
    • Electrical: Analog, digital, and electrical machines.
    • Magnetic & Thermal: Modeling of magnetic and thermal systems.
    • Fluid: Fluid dynamics and flow components.
    • Control Systems: Control logic and hierarchical state machines.
    • Mathematical/Utility: Numerical functions, string handling, file I/O, and stream functions.

    Each component in the library includes official documentation available at doc.modelica.org.

  2. Requirements for using the Modelica Standard Library

    master

    To use the Modelica Standard Library, you must have a Modelica simulation environment installed.

    • Most commercial Modelica tools include the standard library by default.
    • You can find a list of supported tools on the Modelica tools page.
    • Note: Some demo versions of commercial simulation tools may have limitations that prevent simulating non-trivial examples from the library.
  3. Build object libraries from C-sources

    master

    The Modelica/Resources/BuildProjects directory provides build projects intended to help tool vendors construct object libraries from the C source code located in ../C-Sources.

    These projects can be used as a starting point to generate binary libraries (such as .lib, .dll, .a, or .so files) required for Modelica tool integration. Note that tool vendors are responsible for the actual compilation and inclusion of these binaries into their respective software tools.

  4. Configure Visual Studio for Modelica C sources on Windows

    master

    When compiling libraries (.dll, .lib) or executables (.exe) on Windows that include gconstructor.h (specifically for ModelicaInternal.c or ModelicaStandardTables.c), apply these settings in the Release configuration of Visual Studio 2013, 2015, or 2017:

    • Compiler: The option /Zc:inline (Remove unreferenced COMDAT) must not be set. Either omit the option or explicitly use /Zc:inline- to unset it.
    • Linker: If /GL (Whole Program Optimization) and /LTCG (Link-time Code Generation) are enabled, you must set /OPT:NOREF (Keep unreferenced functions).
  5. Use comparison signals for testing models

    master

    The ModelicaTest/Resources/Reference/ directory contains variable names for all test models. These names are used as comparison signals to verify model behavior during testing.

    To implement a new test case, follow these requirements:

    1. Directory Structure: The directory structure must mirror the library tree of the ModelicaTest package.
    2. File Naming: Each directory must contain a file named exactly comparisonSignals.txt.
    3. File Content: The comparisonSignals.txt file must list the variable names to be used as signals. The first line of the file must be the time signal.
    time
    variable_name_1
    variable_name_2
  6. Link Modelica external C libraries

    master

    When a Modelica model uses the library annotations ModelicaExternalC, ModelicaIO, or ModelicaStandardTables in an external function, the corresponding object library must be provided by the linker or dynamically linked to the simulation environment.

    Backwards-compatibility (MSL v3.2.1): To support MSL v3.2.1 and later, tool vendors must ensure that the ModelicaStandardTables library automatically resolves its dependencies on ModelicaIO, ModelicaMatIO, and zlib. This is typically achieved by building shared object libraries (.dll, .so) and linking them in the following chain:

    • ModelicaStandardTables $\rightarrow$ ModelicaIO $\rightarrow$ ModelicaMatIO $\rightarrow$ zlib.
  7. Compile C sources into Modelica object libraries

    master

    Tool vendors must compile the *.c files in the Modelica/Resources/C-Sources/ directory into specific object libraries. The required libraries and their constituent files are:

    • ModelicaExternalC (.lib, .dll, .a, or .so):
      • ModelicaFFT.c
      • ModelicaInternal.c
      • ModelicaRandom.c
      • ModelicaStrings.c
      • win32_dirent.c (required for Visual C++ on Windows)
    • ModelicaIO (.lib, .dll, .a, or .so):
      • ModelicaIO.c
    • ModelicaMatIO (.lib, .dll, .a, or .so):
      • ModelicaMatIO.c
      • snprintf.c
    • ModelicaStandardTables (.lib, .dll, .a, or .so):
      • ModelicaStandardTables.c
      • ModelicaStandardTablesUsertab.c
    • zlib (.lib, .dll, .a, or .so):
      • All files in zlib/*.c
  8. Use comparison signals for testing example models

    master

    The Modelica/Resources/Reference/ directory contains text files used for testing purposes. These files store variable names of example models that serve as comparison signals.

    To implement a new set of comparison signals:

    1. Follow the library tree structure of the Modelica package.
    2. Name each file comparisonSignals.txt.
    3. Ensure the first line of every file contains the time signal.
    time
    variable_name_1
    variable_name_2
  9. Build C-code object libraries using Visual Studio 2005 projects

    master

    The Modelica/Resources/BuildProjects/VisualStudio2005/ directory contains Microsoft Visual Studio project files used to compile C source code into object libraries. These libraries are located in the Resources/C-Sources directory and are intended for use in environments like Dymola.

    To ensure compatibility with Dymola, use the LIB Release configuration, which builds static libraries (*.lib) using the /MT (Multi-threaded) runtime flag.