Discussion ClosedThis 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 oncygwinwith the commandsgcc -c test.cand thengcc -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 2024年1月16日 GMT+1 16:07
Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 7 months ago 2024年1月15日 GMT+1 10:32

Hi Maximilian,

For an external function in COMSOL Multiphysics, you must define three functions:init,eval, andgetLastError, 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 theCOMSOL Multiphysics Programming Reference Manualfor 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: 7 months ago 2024年1月16日 GMT+1 14:37

Hi Maximilian,

For an external function in COMSOL Multiphysics, you must define three functions:init,eval, andgetLastError, 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 theCOMSOL Multiphysics Programming Reference Manualfor 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: 7 months ago 2024年1月16日 GMT+1 16:07

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 theCOMSOL Multiphysics Programming Reference Manual, underGeneral Commands>About General Commands>model.func(). Then scroll down toExternal.

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 theSupport Centerfor a more comprehensive response from the Technical Support team.

Baidu
map