Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistency between Modelica language external functions, and source code FMUs #545

hubertus65 opened this Issue Mar 8, 2019 · 1 comment


None yet
3 participants
Copy link

hubertus65 commented Mar 8, 2019

For all Modelica tools, it should be possible to generate a source code FMU from Modelica. Therefore, source code FMUs should allow at least the same languages as the Modelica external function interface.

This will also have consequences for Modelica Libraries, where sources for external dependencies are not always included. This is handled separately in the Modelica specification repo.


This comment has been minimized.

Copy link
Collaborator Author

hubertus65 commented Mar 8, 2019

For reference, here is the text from the Modelica external function interface. Unfortunately, in latex source, but probably still readable.
\section{External Function Interface}\doublelabel{external-function-interface}

Here, the word function is used to refer to an arbitrary external
routine, whether or not the routine has a return value or returns its
result via output parameters (or both). The Modelica external function
call interface provides the following:

Support for external functions written in C (specifically C89) and
FORTRAN 77. Other languages, e.g. C++ and Fortran 90, may be supported
in the future, and provided the function is link-compatible with C89
or FORTRAN 77 it can be written in any language.
Mapping of argument types from Modelica to the target language and
Natural type conversion rules in the sense that there is a mapping
from Modelica to standard libraries of the target language.
Handling arbitrary parameter order for the external function.
Passing arrays to and from external functions where the dimension
sizes are passed as explicit integer parameters.
Handling of external function parameters which are used both for input
and output, by passing an output that has a declaration assignment to
the external function. {[}\emph{Declaration assignments are executed
prior to calling the external function.}{]}

The format of an external function declaration is as follows.

function IDENT string-comment
{ component-clause ";" }
[ protected { component-clause ";" } ]
external [ language-specification ] [
external-function-call ] [annotation ] ";"
[ annotation ";" ]
end IDENT;
Components in the public part of an external function declaration shall
be declared either as input or output. {[}\emph{This is just as for any
other function. The components in the protected part allow local
variables for temporary storage to be declared.}{]}

The language-specification must currently be one of "builtin", "C",
"C\ldots{}" (for one of the specific C-standards like C89, C99, and C11
-- which specifies that it relies on the C standard library of that
version) or "FORTRAN 77". Unless the external language is specified, it
is assumed to be "C". \emph{{[}The intended use of e.g. "C99" is to
detect if the user tries to link with a C99-function using a C89
compiler.{]} }

The "builtin" specification is only used for functions that are defined
to be built-in in Modelica. The external-function call mechanism for
"builtin" functions is implementation-defined. {[}\emph{Typically, for
functions from the standard C-library, the prototype of the function is
provided but no library annotation. Currently, there are no other
builtin functions defined in Modelica.}{]}


package Modelica
package Math
function sin
input Real x;
output Real y;
external "builtin" y=sin(x);
end sin;
end Math;
end Modelica;

model UserModel
parameter Real p=Modelica.Math.sin(2);
end UserModel;

The external-function-call specification allows functions whose
prototypes do not match the default assumptions as defined below to be
called. It also gives the name used to call the external function. If
the external call is not given explicitly, this name is assumed to be
the same as the Modelica name.

The only permissible kinds of expressions in the argument list are
component references, scalar constants, and the function size applied to
an array and a constant dimension number. The annotations are used to
pass additional information to the compiler when necessary.

A component reference to a component that is part of an input or output
is treated the same way as a top-level input or output in the external

@chrbertsch chrbertsch assigned chrbertsch and IZacharias and unassigned chrbertsch Mar 8, 2019

@chrbertsch chrbertsch added this to the FMI3.0 milestone Mar 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.