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.

com.comsol.nativejni.FlNativeException: Incorrect size of returned vector

Please login with a confirmed email address before reporting spam

Dear all,

I'm working on a 2D PDE in coefficient form. In my model, one of the coefficients is set up by an external matlab function fun(t,x,y) according to:
model.physics('...').feature('...').set('a','1','fun(t,x,y)');

Comsol and Matlab have no trouble finding the function and calling it when running the script. However, I get - RANDOMLY - a crash in my simulation with the following error message:

'com.comsol.nativejni.FlNativeException: Incorrect size of returned vector. 6000 elements were expected, but the returned matrix was 1 x 1
- Function : fun
- Feature : Time-Dependant Solver 1 (sol1/t1)
- Error : Incorrect size of returned vector. 6000 elements were expected, but the returned matrix was 1 x 1'

Here is the script of my function and what I discovered so far.

function out = fun(t,x,y)
for i=1length(x)
out(i) = some-crazy-bullshit-computed-using-(t,x,y);
end
end

I decided to investigate why, it was crashing randomly because of an incorrect size of retuned vector. I first decided to turn the previous function into the most simple function one can create:

function out = fun(t,x,y)
out = x;
end

Still the same problem (restarted COMSOL+Matlab, clear functions, whatever... did not work out)
I then decided to have a look at what was being computed in my function, by saving all the interesting variables into a mat file in order to have a look at it later.

function out = fun(t,x,y)
out = x;
save('error.mat','x','y','t','out');
end

Here is what I found
x = {1}
y = {40}
t = {40}
out = {1}

Still, Comsol is telling me : 'com.comsol.nativejni.FlNativeException: Incorrect size of returned vector. 6000 elements were expected, but the returned matrix was 1 x 1.'
I'm afraid there might be no mistake in here. My function returned one element, because t, x and y were singletons...!
What can I do to get rid of this error message ? Can't find anything on the forum or the documentation about this...

Thanks

Matthieu

2 Replies Last Post 18 ott 2012, 11:40 GMT-4
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18 ott 2012, 07:17 GMT-4
Hi

probably you need to submit it to support (with your model) so they can dig into it ;)

--
Good luck
Ivar
Hi probably you need to submit it to support (with your model) so they can dig into it ;) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18 ott 2012, 11:40 GMT-4
Uninstalled and reinstalled Comsol solved the problem.
I still have no idea what went wrong...

But Anyway... Fixed. :)
Uninstalled and reinstalled Comsol solved the problem. I still have no idea what went wrong... But Anyway... Fixed. :)

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.