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.
External function in C - error "Wrong architecture"
Posted Sep 17, 2010, 9:48 a.m. EDT 11 Replies
Please login with a confirmed email address before reporting spam
I am using COMSOL 4.0a on mac os X.
I want to write external functions in C and use these in COMSOL.
Here is an exemple
file add.c
#include "add.h"
int add(int a, int b)
{
return a+b;
}
file add.h
int add(int,int)
I get my library by using
cc -o libadd.dylib add.c -dynamiclib
But when I try to use my library in comsol, I have the error
"wrong architecture"
Does anyone knows what's the trick ?
Thanks for your help,
Sébastien
Hello Sébastien Janas
Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.
If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
if you are trying to solve a numerical problem in C
I suggest you use matlab.
there have been more success with matlab working with comsol than functions written is C.
Please login with a confirmed email address before reporting spam
Thanks for your answer.
I have tried this possibility, but I didn't managed to make matlab functions working. Do you have somewhere a good tuto on the use of matlab functions in comsol ?
For exemple, here is what I have tried
a simple function add.m
--------------------------------
function F = add(a,b)
F = a+b;
--------------------------------
I put this file on my desktop, and my desktop is in the path of matlab.
Then I lauch COMSOL and COMSOL SERVER, I connect COMSOL to the server.
I create a MATLAB function with global definitions->function where I put "add" in the function case, and the two arguments a,b in the arguments case.
When I want to use my add function, I have an error "Failed to load library".
Please login with a confirmed email address before reporting spam
I contacted the support and it came down to these things:
1. you're function should be able to receive vectors and return vectors.
when you solve your model with a matlab function included, a matlab window need to pop up. if it doesn't you need to check these things:
2. the path where the m file is have to be added to the matlab path.
3. the comsol's setting to know where matlab is should point to where matlab's bin library is
for example C:\Program Files\MATLAB\R2010a\bin
I hope my advices are helful
Please login with a confirmed email address before reporting spam
I tried, but it don't works.
Do you connect Comsol to the server when you use a matlab function ?
I have changed the comsol settings in comsol.ini and comsolserver.ini, is there an other file ?
Best regards,
Sébastien
Please login with a confirmed email address before reporting spam
the comsol-matlab connection is made by comsol when you run a matlab function
in comsol. the manual connection is not needed. a small window of matlab should appear when
you run the model.
I suggest you change the comsol settings in all the ini files.
try this as well -
Open a Command Prompt (DOS box) and exeute the following commands
cd C:\Program Files\MATLAB\R2010a\bin
matlab -regserver
then restart
Zvika
Please login with a confirmed email address before reporting spam
--------------------------------
function F = add(a,b)
F = a+b;
--------------------------------
Sébastien
1. you're function should be able to receive vectors and return vectors.
when you solve your model with a matlab function included, a matlab window need to pop up. if it doesn't you need to check these things:
Zvika
Hi Zvika
please if you guys don't mind i am interest in this discussion also,
going back to Sébastien's matlab function above given a =[2 18 4 0]'; b=[-2 0.051 0 -1]';, hence F is a 4x1 vector
Zvika, were you successful in calling this function in COMSOL40a? if so can you share a simple mph file implementing this matlab function call?
thanks in advance, i just want to make sure we are not pursing a "ghost idea".
--
merci
XIfe
Please login with a confirmed email address before reporting spam
In fact, the problem for me was that I am using MATLAB 2008, and it seems that the use of matlab function is only possible with MATLAB 2009. I tried with a version of MATLAB 2009 and it works fine.
Best regards,
Sébastien
Please login with a confirmed email address before reporting spam
awesome! please can describe how you did this? i will really be grateful.
did you use Definition - Functions - Analytic or what? to call "add.m" file?
--
merci
Please login with a confirmed email address before reporting spam
In fact it's really simple if you use MATLAB 2009.
In global definition -> function -> matlab I just wrote add in the "function" case and a,b in the "arguments" case.
I have added the path of my function in matlab.
I can use my function add.m in a analytic function of comsol, or in a global variable.
It's a pity that you have to get the last version of matlab to use this functionality. My lab can't buy the new version every year.
Please login with a confirmed email address before reporting spam
indeed the comsol only works with the most recent matlab 2009,2010.
I forgot to ask if youre using one of those.
I'm happy it works for you.
Zvika
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.