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.3a
Posted 13.03.2013, 05:47 GMT-4 LiveLink for MATLAB Version 4.3a 4 Replies
Please login with a confirmed email address before reporting spam
I have a Comsol 4.3a model which takes about 4½ minutes to run. I would like to run it through MatLab to do sweeps over several parameters and only save a few results from each run. However when I try to run the .M file I've saved from Comsol it takes over 14 minutes.
Does anyone know if this is a general problem? I've heard it had similar problems in Comsol 4.0. (from this thread: www.comsol.com/community/forums/general/thread/7330/ )
The MatLab version I'm using is 2012b.
Many thanks in advance
Mathias
Please login with a confirmed email address before reporting spam
Creating a model from scratch by running an M-file can take much longer time than loading the MPH-file.
If your model allows it, you should load the MPH-file, update whatever parameter values that needs to be updated and solve the model. This should be the fastest way for you to obtain results.
In Comsol 4.3a we have introduced a new method "model.disableUpdates" that can be used to speed up M-files where setting up the model takes a long time. You can read more about this method in the API Reference Guide.
--
Lars Gregersen
Technical Product Manager
Comsol Denmark
Please login with a confirmed email address before reporting spam
Thanks a lot for the fast reply! I have tried loading the model and that seemed to work fine but I'm having trouble as to how to proceed from there. The user manual only seems to cover how to use the .M files, i cannot eg find a command to simply run the model again as you suggest. And after the model is loaded is it then possible to use the standard set.parameter() commands to update the parameter?
I do not know if this matters but my model has very simple geometry, the only time consuming part should be the solving of 3 coupled partial differential equations.
Edit
I have been working on the load idea you had. The only way i have found to solve the system again is by the model.run command, however, this gives me the following error:
model = mphload('filename');
>> model.run
Warning: Inputs must be character arrays or cell arrays of strings.
> In run at 33
Error using fileparts (line 34)
Input must be a row vector of characters.
Error in run (line 36)
[fileDir,script,ext] = fileparts(scriptname);
I have also tried to just create a parameter sweep in comsol (without matlab) to see if this was a better way, but even here comsol gets slowed down. As soon as i create create a parameter sweep over just 1 parameter which only takes 1 value (so that it should only solve the model ones), it takes several times longer to solve the problem.
Please login with a confirmed email address before reporting spam
I am not commenting on the error you have but more on the time issue.
Your observation of sluggishness is true from my experience too. But it is hard to generalise the statement.
For example, I did a simple analysis (simple geometry and several 100 nodes) by coupling 4.3a with MATLAB and 4.3a with java and compared it with 3.5a with MATLAB (of course not simple in terms of formulation). I did not do any calculations within MATLAB or java but just used it to loop a transport problem to check for the communication time between COMSOL-MATLAB and comsol-java. I run a test with java only to see if 4.3a-java coupling works faster compared to COMSOL-MATLAB. Of course I developed the mph file beforehand and used mphload.
The following were my preliminary observations:
(a) For the given geometry and mesh (this aspect is important), there was no significant difference between working in Java or MATLAB environment linked to COMSOL4.3a.
(b) Working in Java or MATLAB takes slightly more time – for the tested case 0.7 to 1 second in excess per time step compared to running COMSOL in the GUI alone. This excess was due to the overhead to communicate with Comsol 4.3a server.
(c) When compared with my colleague's work, MATLAB -COMSOL3.5a was found to be far superior – i.e. at least 10-20 times faster for the given problem. This was fundamentally because version 3.5a was much faster than 4.3a for the specific problem and not so much because of Java or MATLAB coupling for my case.
(d) Of course, with the above limited calculation one should not conclude that COMSOL4.3a is slower compared to 3.5a.
When I run another problem in which there is a real coupling between COMSOL-MATLAB I found that using model.disableUpdates did not do much favour. Again I don’t mean to counter that disable updates don’t work but for the specific problem it did not.
Indeed I also had a response from COMSOL support some time ago where they acknowledged that previously in 3.5a, COMSOL was built within the MATLAB structure and hence coupling between COMSOL-MATLAB was much more efficient. But as you already know that now there is a separate COMSOL server that communicates with MATLAB .
I am not sure if 4.3b has improved the communication speed. This is something that COMSOL support can tell us.
Suresh
Please login with a confirmed email address before reporting spam
...If your model allows it, you should load the MPH-file, update whatever parameter values that needs to be updated and solve the model. This should be the fastest way for you to obtain results.
In Comsol 4.3a we have introduced a new method "model.disableUpdates"
Dear Lars,
When the model is loaded using mphload, do we still need model.disableupdates ?
If yes, where should this be placed.
I have a mph file (which I loop 10,000 times) with more than 200 variables (basically expressions which are functions of primary variables) but not all of them are used always. Sometimes I only use let us say about 30 variables but I do not want to trim the mph file or delete those variables but rather would like to use the master mph file where only 30 variables are automatically made active. Or is it that the model.disableupdates is not applicable for my type of problem.
I am sorry I read the manual but could not understand it entirely.
Thank you,
Suresh
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.
Suggested Content
- FORUM Parametric sweeps LiveLink for MATLAB
- BLOG Thank You for Attending the COMSOL Conference Bangalore 2012
- KNOWLEDGE BASE COMSOL Does Not Start with the Latest MATLAB Version
- BLOG Extend Your Modeling Capacity with LiveLink™ for Excel®
- FORUM How to continue the study after stopped using livelink for matlab?