Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

Slow Matlab LiveLink with Comsol 4.0a

Please login with a confirmed email address before reporting spam

Hi everyone,

I am migrating a model from Comsol 3.5 to Comsol 4.0a. While I am in general happy with the great changes and improvements from 3.5 to 4.0a, the Matlab interface is for some reason very slow. It is basically impossible to run an optimisation on my single computer as it takes about 11 seconds to compute the solution for a single set of parameters using Matlab Livelink. Furthermore, the Matlab interface is much slower than the Comsol 4.0a GUI which again appears to be slower than Comsol 3.5.
Has anyone else experienced this behaviour? Are there ways to improve the speed of my simulation in Matlab (or in general)?

Many thanks in advance
Dominik

6 Replies Last Post Nov 2, 2010, 10:17 a.m. EDT
COMSOL Moderator

Hello Dominik Wild

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

Posted: 1 decade ago Aug 24, 2010, 6:13 p.m. EDT
Dear Dominik,

I'm facing the exactly same problem as you, with COMSOL 4.0a + Matlab Livelink. Could find a solution for this problem?

I'm running the topolgy optimization inside matlab and using COMSOL simply as the FEM solver for each iteration. When I compute the problem by the COMSOL interface it takes about 5s and when I do it from the Livelink it takes about 30s to solve the same problem.

Does anyone contacted the support regarding this issue?

Thanks in advance,
Andre
Dear Dominik, I'm facing the exactly same problem as you, with COMSOL 4.0a + Matlab Livelink. Could find a solution for this problem? I'm running the topolgy optimization inside matlab and using COMSOL simply as the FEM solver for each iteration. When I compute the problem by the COMSOL interface it takes about 5s and when I do it from the Livelink it takes about 30s to solve the same problem. Does anyone contacted the support regarding this issue? Thanks in advance, Andre

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 25, 2010, 1:52 a.m. EDT
Hello Andre,

I am glad I am not the only one experiencing this issue. Unfortunately, I have not yet been able to solve the problem.

COMSOL generates a lot of garbage when you generate the .m file and you need to make sure that you remove all the unnecessary parts. For instance, if you created an object using the COMSOL interface and then deleted it, it will appear exactly like that in the .m file. I do not understand why this happens and it would be great to see an improved .m file generator in a future version.

Nevertheless, even with all the unnecessary parts removed, the simulation still appears to be significantly slower if it is run from the MATLAB interface. I suppose it has to do with the way Matlab communicates with the COMSOL server - is it TCP? - but I do not have any strong evidence for that.

Regards,
Dominik
Hello Andre, I am glad I am not the only one experiencing this issue. Unfortunately, I have not yet been able to solve the problem. COMSOL generates a lot of garbage when you generate the .m file and you need to make sure that you remove all the unnecessary parts. For instance, if you created an object using the COMSOL interface and then deleted it, it will appear exactly like that in the .m file. I do not understand why this happens and it would be great to see an improved .m file generator in a future version. Nevertheless, even with all the unnecessary parts removed, the simulation still appears to be significantly slower if it is run from the MATLAB interface. I suppose it has to do with the way Matlab communicates with the COMSOL server - is it TCP? - but I do not have any strong evidence for that. Regards, Dominik

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 25, 2010, 5:03 a.m. EDT

COMSOL generates a lot of garbage when you generate the .m file and you need to make sure that you remove all the unnecessary parts. For instance, if you created an object using the COMSOL interface and then deleted it, it will appear exactly like that in the .m file. I do not understand why this happens and it would be great to see an improved .m file generator in a future version.


Hi Dominik,

You can always reset the m files from the file menu. That should get rid of the garbage.

Nevertheless, I also notice the sluggishness of livelink interface, not to mention the comsol interface itself (when there are some moderate mesh or after a period of the UI being open). I am not sure if they can improve it or is it because of java interface. Also regarding the server I am not sure if this server can handle big files and bring it back and forth without a big memory footprint. I'll to try it later.

Danial
[QUOTE] COMSOL generates a lot of garbage when you generate the .m file and you need to make sure that you remove all the unnecessary parts. For instance, if you created an object using the COMSOL interface and then deleted it, it will appear exactly like that in the .m file. I do not understand why this happens and it would be great to see an improved .m file generator in a future version. [/QUOTE] Hi Dominik, You can always reset the m files from the file menu. That should get rid of the garbage. Nevertheless, I also notice the sluggishness of livelink interface, not to mention the comsol interface itself (when there are some moderate mesh or after a period of the UI being open). I am not sure if they can improve it or is it because of java interface. Also regarding the server I am not sure if this server can handle big files and bring it back and forth without a big memory footprint. I'll to try it later. Danial

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 25, 2010, 7:01 a.m. EDT
Hi Danial,

I always reset my model before saving it as .m file but it doesn't improve the the solution time. I think COMSOL should automatically reset the model before saving the .m file.

Anyway, I think this really has to do with the way COMSOL communicates with Matlab (if that is the case, it should definitely be improved for the next releases). In my case, when I refine the mesh to extra fine, the solution time is almost the same as when I use a much coarser mesh - the communication time dominates the solution time.

Andre
Hi Danial, I always reset my model before saving it as .m file but it doesn't improve the the solution time. I think COMSOL should automatically reset the model before saving the .m file. Anyway, I think this really has to do with the way COMSOL communicates with Matlab (if that is the case, it should definitely be improved for the next releases). In my case, when I refine the mesh to extra fine, the solution time is almost the same as when I use a much coarser mesh - the communication time dominates the solution time. Andre

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 2, 2010, 4:02 p.m. EDT
I've also noticed the speed issue. I have my model drawn using the Matlab interface and it seems to take quite a bit of time as compared to 3.5a. Before drawing the model and adding physics / applying constraints happened very quickly. Now, for whatever reason, this takes almost as much time as meshing or running the solution.

All in all, my time is up to over 2 minutes per iteration compared to about 30 seconds with Comsol 3.5a.

Mark
I've also noticed the speed issue. I have my model drawn using the Matlab interface and it seems to take quite a bit of time as compared to 3.5a. Before drawing the model and adding physics / applying constraints happened very quickly. Now, for whatever reason, this takes almost as much time as meshing or running the solution. All in all, my time is up to over 2 minutes per iteration compared to about 30 seconds with Comsol 3.5a. Mark

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 2, 2010, 10:17 a.m. EDT
Hi, I may just be adding my voice to the croud, but if it serves our case, then good!

I have developped a model that calculates a capacitance matrix for a nano-electronic component. The simulation takes about 2-3 minutes, mainly because there are 7 parametric steps in it. I exported it as a .m file and cleaned it up. Then when I run it with the Comsol with Matlab, it takes 5-6 minutes. This time was actually measured by matlab only for the comsol call.

Has some have said, I would think it may be the communication between Matlab and the comsol server that slows down the calculation. I wonder why Matlab "has" to send the calculation to the server instead of using the comsol core installed on the computer. I'm not an expert in the field yet, but I would think that Matlab should not have to get to external server when all the necessary algorithms are available on the computer directly. (this is a suggestion for future versions.)

In my case, it isn't so bad since the post treatment I have to do in comsol and the "copying" of data to matlab does take 1-2 minutes in the end. it therefore ends up not being very much longer when matlab does it all itself!

Gabriel

edit*
After I used comsol's "reset history" function, the simulation mentionned above took about 3 minutes with matlab, a similar time as for a comsol direct simulation. Although I'm not quite sure what did the trick, but the main changes where to remove most of the "model.geom(...).feature(...).run" lines, most of the 'descr' lines (changing names in the comsol GUI - useless in matlab) and shortened the model.sol() part of the code.
I use v4.0 by the way.
Hopes this helps a bit!
Hi, I may just be adding my voice to the croud, but if it serves our case, then good! I have developped a model that calculates a capacitance matrix for a nano-electronic component. The simulation takes about 2-3 minutes, mainly because there are 7 parametric steps in it. I exported it as a .m file and cleaned it up. Then when I run it with the Comsol with Matlab, it takes 5-6 minutes. This time was actually measured by matlab only for the comsol call. Has some have said, I would think it may be the communication between Matlab and the comsol server that slows down the calculation. I wonder why Matlab "has" to send the calculation to the server instead of using the comsol core installed on the computer. I'm not an expert in the field yet, but I would think that Matlab should not have to get to external server when all the necessary algorithms are available on the computer directly. (this is a suggestion for future versions.) In my case, it isn't so bad since the post treatment I have to do in comsol and the "copying" of data to matlab does take 1-2 minutes in the end. it therefore ends up not being very much longer when matlab does it all itself! Gabriel edit* After I used comsol's "reset history" function, the simulation mentionned above took about 3 minutes with matlab, a similar time as for a comsol direct simulation. Although I'm not quite sure what did the trick, but the main changes where to remove most of the "model.geom(...).feature(...).run" lines, most of the 'descr' lines (changing names in the comsol GUI - useless in matlab) and shortened the model.sol() part of the code. I use v4.0 by the way. Hopes this helps a bit!

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.