Support Knowledge Base

Solution Number: 1005
Title: Linking COMSOL to external functions
Platform: All Platforms
Applies to: All Products
Versions: 3.3, 3.4
Created: January 18, 2007
Last Modified: February 11, 2008
Categories: Import, Product Information
Keywords: function functions API C++ C FORTRAN Excel call link

Problem Description

Can COMSOL Multiphysics be connected to external functions written in other languages?

Solution

Yes, it is possible to link COMSOL Multiphysics to external functions written in other languages. Through the external API, COMSOL Multiphysics can be interfaced with shared libraries written in e.g. C, C++ or FORTRAN. This is useful if an external database is needed or a function that does not exist in COMSOL Script is available in another language.

More information about this can be found in the chapter External API in COMSOL Script User’s Guide. Below is a short overview.

An m-file must be created that describes the interface and contains the link to the external library, this is called the m-file Interface. An m-file Interface functions as a bridge between COMSOL and the external library. If no comments are added it is only one line long and could look like:

function s = sinsum{'sinsum', 'work'}(A)

This syntax links the function work from the shared library sinsum to COMSOL Multiphysics.

The function work must have a special format regarding the (input and output) parameters. Due to this it is often necessary to write a new function to match these requirements. This new function can then call the function that was originally wanted.

All the external functions must be compiled to a shared library, i.e. a DLL-file. For this reason the external API is practical to use when the source code to the external function is available, or if the function is available in a shared library.

The external API is not used to call executable files. This can be done using the DOS or SYSTEM command. For more information, see Knowledge base 1006.

Feedback

Poor | Excellent
Document quality?




« Back to Support Knowledge Base

Disclaimer

COMSOL makes every reasonable effort to verify the information you view on this page. Resources and documents are provided for your information only, and COMSOL makes no explicit or implied claims to their validity. COMSOL does not assume any legal liability for the accuracy of the data disclosed. Any trademarks referenced in this document are the property of their respective owners. Consult your product manuals for complete trademark details.

© 1997-2008 COMSOL AB.
COMSOL, COMSOL Multiphysics, COMSOL Reaction Engineering Lab, COMSOL Script and
FEMLAB are registered trademarks of COMSOL AB. Other product or brand names are
trademarks or registered trademarks of their respective holders. All Rights Reserved.