Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Trying to include an external dll (compiled from c)

Maximilian Hohenberger

Please login with a confirmed email address before reporting spam

Hello,

I am trying to use a custom function in comsol. For testing purposes, I have written a short c file:

double f(double x, double y, double z);

double f(double x, double y, double z) {

    double r;

    r = x * (1 + 1*(y-z) + 1*(y-z));

    return r;
}

Then I compiled my code as adviced on suggested on cygwin with the commands gcc -c test.c and then gcc -shared -o test.dll test.o.

Now in Global Definitions, I created a new instance with right click -> functions -> extern, filled out function name with "f" and arguments with "x, y, z" and finally created 3 entries in plot parameters ranging from 0 to 10 for every entry.

Now if I click "plot" or "create plot" I get an error saying "Symbol not found". I have googled and asked Bing "to google for me" but I dont find any resource that helps me here.

How do I make this work?


3 Replies Last Post 16 gen 2024, 10:07 GMT-5
Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 10 months ago 15 gen 2024, 04:32 GMT-5

Hi Maximilian,

For an external function in COMSOL Multiphysics, you must define three functions: init, eval, and getLastError, and for the numerical evaluation, the input and output arguments must be arrays (x, y, and z in your example and in general are numerical arrays). See the COMSOL Multiphysics Programming Reference Manual for more information and an example.

Best regards,

Magnus

Hi Maximilian, For an external function in COMSOL Multiphysics, you must define three functions: `init`, `eval`, and `getLastError`, and for the numerical evaluation, the input and output arguments must be arrays (x, y, and z in your example and in general are numerical arrays). See the *COMSOL Multiphysics Programming Reference Manual* for more information and an example. Best regards, Magnus

Maximilian Hohenberger

Please login with a confirmed email address before reporting spam

Posted: 10 months ago 16 gen 2024, 08:37 GMT-5

Hi Maximilian,

For an external function in COMSOL Multiphysics, you must define three functions: init, eval, and getLastError, and for the numerical evaluation, the input and output arguments must be arrays (x, y, and z in your example and in general are numerical arrays). See the COMSOL Multiphysics Programming Reference Manual for more information and an example.

Best regards,

Magnus

Thank you for your anwser. Could you tell me where exactly you found the example in the manual? I search for a bit, but couln't locate it.

>Hi Maximilian, > >For an external function in COMSOL Multiphysics, you must define three functions: `init`, `eval`, and `getLastError`, and for the numerical evaluation, the input and output arguments must be arrays (x, y, and z in your example and in general are numerical arrays). See the *COMSOL Multiphysics Programming Reference Manual* for more information and an example. > >Best regards, > >Magnus Thank you for your anwser. Could you tell me where exactly you found the example in the manual? I search for a bit, but couln't locate it.

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 10 months ago 16 gen 2024, 10:07 GMT-5

Thank you for your anwser. Could you tell me where exactly you found the example in the manual? I search for a bit, but couln't locate it.

Hi Maximilian,

It's located in the COMSOL Multiphysics Programming Reference Manual, under General Commands>About General Commands>model.func(). Then scroll down to External.

Best regards,

Magnus

>Thank you for your anwser. Could you tell me where exactly you found the example in the manual? I search for a bit, but couln't locate it. Hi Maximilian, It's located in the *COMSOL Multiphysics Programming Reference Manual*, under *General Commands>About General Commands>model.func()*. Then scroll down to *External*. Best regards, Magnus

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.