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.

Memory problems with mphinterp

Please login with a confirmed email address before reporting spam

I have a large RF simulation, and I need to get the value of the electric field on a rather dense rectilinear grid. For this, I have been using mphinterp. However, I have been running into the problem that if I make the grid too large I run out of heap memory.

At first I thought that this was due to evaluating too many points simultaneously, so I split the evaluations up but got the same problem. I played around with this a bit and noticed that ANY call to mphinterp seems to permanently (as far as I can tell) increase the amount of RAM being used by comsolserver.exe. So, even if I call mphinterp at a single point over and over the RAM being used by COMSOL will steadily increase until I hit my heap limit and get an error. At this point, trying to do pretty much anything with my model returns the out of memory error, since there seems to be no way to unallocate this RAM, and I have to quit and restart COMSOL.

This is quite a problem for me, since I do in fact need a large number of points in this grid. I can manually set the heap allocation to be larger, but I'm rather curious why this is occurring in the first place. As far as I can determine from the documentation mphinterp is supposed to interpolate the value of a given expression based on the existing solution vector, so I see no reason why it should need to permanently increase the amount of memory used by the model.

Does anyone know why this is happening? Is this a bug (memory leak, or something else)? If not, is there any way to free up the memory used once I have the interpolated values?

28 Replies Last Post Sep 1, 2012, 9:32 a.m. EDT
COMSOL Moderator

Hello Sean Meenehan

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 Sep 29, 2010, 10:50 a.m. EDT
I too have been fighting a similar problem. The one thing I have noticed is that if you run several calls to mphinterp and then save your model to an .m file, each one of the calls generates multiple lines of m code. I wonder if this is what is causing the "memory leak", the fact that a log of commands is building up somewhere. I wish I could figure out how to turn this logging function off.

Anyone know how to do this?
I too have been fighting a similar problem. The one thing I have noticed is that if you run several calls to mphinterp and then save your model to an .m file, each one of the calls generates multiple lines of m code. I wonder if this is what is causing the "memory leak", the fact that a log of commands is building up somewhere. I wish I could figure out how to turn this logging function off. Anyone know how to do this?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 6, 2010, 12:09 p.m. EDT
I contacted support and they told me this memory leak is a known issue with COMSOL 4.0a with no work around (other than increasing the java heap memory allocation size). Apparently, it'll be fixed in version 4.1.
I contacted support and they told me this memory leak is a known issue with COMSOL 4.0a with no work around (other than increasing the java heap memory allocation size). Apparently, it'll be fixed in version 4.1.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Dec 3, 2010, 10:58 a.m. EST
Unfortunately, this problem is not resolved in Comsol version 4.1.

I am also running a pretty big model (on Comsol4.1 with Matlab) and I've already increased the java heap size. Still, by using the "mphinterp" command the memory usage of the comsolserver.exe process increases continually as desribed above by Sean. After several iteration steps the heap is full and a receive a "out of memory" error.

Does anyone now if there is a possibility or a command to free the heap (for example after each iteration step)?

Appreciate any help!

Cheers
Arthur
Unfortunately, this problem is not resolved in Comsol version 4.1. I am also running a pretty big model (on Comsol4.1 with Matlab) and I've already increased the java heap size. Still, by using the "mphinterp" command the memory usage of the comsolserver.exe process increases continually as desribed above by Sean. After several iteration steps the heap is full and a receive a "out of memory" error. Does anyone now if there is a possibility or a command to free the heap (for example after each iteration step)? Appreciate any help! Cheers Arthur

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 Dec 4, 2010, 7:41 a.m. EST
Hi

if you have the 4.1.0.112 patch then pls report to support so they can fix it rapidly, if not get the latest patch on the main site

--
Good luck
Ivar
Hi if you have the 4.1.0.112 patch then pls report to support so they can fix it rapidly, if not get the latest patch on the main site -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 6, 2011, 12:46 p.m. EST
Even with the latest patch applied (4.1.0.112), I have found that the memory leak is still present and that it is not limited to mphinterp, but will show up with any repeated requests through the Matlab-Comsol LiveLink. I have notified support and will post whatever I may learn from them.
Even with the latest patch applied (4.1.0.112), I have found that the memory leak is still present and that it is not limited to mphinterp, but will show up with any repeated requests through the Matlab-Comsol LiveLink. I have notified support and will post whatever I may learn from them.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 10, 2011, 5:49 a.m. EST
I have the same problems. Any solutions so far?
I have the same problems. Any solutions so far?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 10, 2011, 8:26 a.m. EST
Here is the message I have received from COMSOL:

----------------
There are unfortunately some memory leaks that we are working on right now to remove for the next release.

For the current release you have a couple of options. One is mentioned in this knowledge base entry:
www.comsol.com/support/knowledgebase/1092/

Alternatively you can try to inset this line at the top of your m-file:
model.hist().disable();

This line will disable the storage of history information (which is rarely used by script anyway) and may help you. Note that this statement is undocumented, experimental and may disappear in a future release of Comsol.
----------------

I have found a hard way around this through MATLAB by making a script that will start a new MATLAB session which runs the COMSOL Link. This script monitors the write activity of a file created by the new MATLAB session. This session writes to the file before every COMSOL request. If the file does not update its timestamp within five minutes (assumes COMSOL has crashed) or if there is a java heap error, then the script will close all processes belonging to matlab.exe (except for the original session) along with the comsolserver process. Once closed, the original session will restart a new MATLAB session and COMSOL Link. It isn't easy to implement, I had to use a bunch of DOS commands, but it works.
Here is the message I have received from COMSOL: ---------------- There are unfortunately some memory leaks that we are working on right now to remove for the next release. For the current release you have a couple of options. One is mentioned in this knowledge base entry: http://www.comsol.com/support/knowledgebase/1092/ Alternatively you can try to inset this line at the top of your m-file: model.hist().disable(); This line will disable the storage of history information (which is rarely used by script anyway) and may help you. Note that this statement is undocumented, experimental and may disappear in a future release of Comsol. ---------------- I have found a hard way around this through MATLAB by making a script that will start a new MATLAB session which runs the COMSOL Link. This script monitors the write activity of a file created by the new MATLAB session. This session writes to the file before every COMSOL request. If the file does not update its timestamp within five minutes (assumes COMSOL has crashed) or if there is a java heap error, then the script will close all processes belonging to matlab.exe (except for the original session) along with the comsolserver process. Once closed, the original session will restart a new MATLAB session and COMSOL Link. It isn't easy to implement, I had to use a bunch of DOS commands, but it works.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 10, 2011, 11:03 a.m. EST
It doesn't work for me to restart all processes. And it also doesn't help to copy this java.opt file into the starting directory or switching off the history as suggested.
When can we expect that this issue will be solved?
It doesn't work for me to restart all processes. And it also doesn't help to copy this java.opt file into the starting directory or switching off the history as suggested. When can we expect that this issue will be solved?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 11, 2011, 12:13 a.m. EST
Is there no way around? I am working with 4.0a and tried starting and shutting down comsol server every iteration through matlab's system command like this

begin loop

system('comsol server')
mphstart

%code

ModelUtil.disconnect

end loop

With the model I have it usually takes five iterations to get out of memory error. This way, however, it manages to go past five iterations but in the very next it generates an error log file containing following message:

Operating System: Linux 2.6.18-128.7.1.el5_lustre.1.8.1.1 #1 SMP Tue Oct 6 05:48:57 MDT 2009 x86_64
Processor ID: x86 Family 6 Model 12 Stepping 2, GenuineIntel
Host Name: node234
Exception in thread "main" Exception in thread "main"

Did anyone successfully try this method or any other?
Is there no way around? I am working with 4.0a and tried starting and shutting down comsol server every iteration through matlab's system command like this begin loop system('comsol server') mphstart %code ModelUtil.disconnect end loop With the model I have it usually takes five iterations to get out of memory error. This way, however, it manages to go past five iterations but in the very next it generates an error log file containing following message: Operating System: Linux 2.6.18-128.7.1.el5_lustre.1.8.1.1 #1 SMP Tue Oct 6 05:48:57 MDT 2009 x86_64 Processor ID: x86 Family 6 Model 12 Stepping 2, GenuineIntel Host Name: node234 Exception in thread "main" Exception in thread "main" Did anyone successfully try this method or any other?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 11, 2011, 12:22 a.m. EST
A small correction, comsol server should rather be started following way

system('nohup comsol server > nohup.txt' &)

Otherwise the terminal might not be released for the next command. This is how it is in usual shell scripts and might be so through matlab as well.

A small correction, comsol server should rather be started following way system('nohup comsol server > nohup.txt' &) Otherwise the terminal might not be released for the next command. This is how it is in usual shell scripts and might be so through matlab as well.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 9, 2011, 9:18 a.m. EST
Hy all!
I'm having the same problem using Comsol 4.0a with Matlab (through LiveLink). In my case the problem is the function "mphint()". To test the problem I've created and simulated a simple fiber model, then I've run a simple Matlab script:


while (1)
for i = 1:6
mphint(model,'emw.Poavz','solnum',i,'selection','all','Edim',2);
end
end


I know that this script is really useless, but it stresses the real problem of the program. If I start this script in Matlab and I look to memory usage of "comsolserver.exe", I see that the program start to fill memory until Matlab becames unstable and crashes.
I think that the problem is inside the Comsol's function. I've also experienced a similar problem with Comsol 3.5 with the function "posteval()", but I didn't find a solution.
Have you any ideas?
Thanks
Hy all! I'm having the same problem using Comsol 4.0a with Matlab (through LiveLink). In my case the problem is the function "mphint()". To test the problem I've created and simulated a simple fiber model, then I've run a simple Matlab script: while (1) for i = 1:6 mphint(model,'emw.Poavz','solnum',i,'selection','all','Edim',2); end end I know that this script is really useless, but it stresses the real problem of the program. If I start this script in Matlab and I look to memory usage of "comsolserver.exe", I see that the program start to fill memory until Matlab becames unstable and crashes. I think that the problem is inside the Comsol's function. I've also experienced a similar problem with Comsol 3.5 with the function "posteval()", but I didn't find a solution. Have you any ideas? Thanks

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 10, 2011, 5:20 a.m. EST
Have you tried the solution presented on comsol's knowledge base? It worked practically for me when I needed to interpolate over thirty iterations. Can't say if it will work for a thousand though :)

Here is the KB entry. Hope it works for you

www.comsol.com/support/knowledgebase/1092/
Have you tried the solution presented on comsol's knowledge base? It worked practically for me when I needed to interpolate over thirty iterations. Can't say if it will work for a thousand though :) Here is the KB entry. Hope it works for you http://www.comsol.com/support/knowledgebase/1092/

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 10, 2011, 10:27 a.m. EST
Yes, I've tryed that solution. In MATLAB 2010 it's easy to define the heap space that java allocate for Matlab through the GUI in "File->Preferencies->...". I've changed the default value of 128MB to 512MB, but the problem obviusly remains if ou consider many iterations. It simply changes the maximum memory that can be used by "comsolserver.exe" before matlab crashes. For example:

- with 128MB of heap space, comsolserver.exe stop working between 300-400MB of RAM space
- with 512MB of heap space, it reaches little more than 1GB of RAM but it still crashes

Anyway the solution that they suggest isn't very usefull: it simply moves the limit of the crash a little bit further, but it does not resolve the problem at all. In my scripts I need to invocate the function "postint()" (and ohters) many times, and the number of time that I call it should change depending on the number of frequency steps that I want in my simulations. A real general purpose script must work for every number of frequency steps, not a limited one!

Thanks for your answer
Yes, I've tryed that solution. In MATLAB 2010 it's easy to define the heap space that java allocate for Matlab through the GUI in "File->Preferencies->...". I've changed the default value of 128MB to 512MB, but the problem obviusly remains if ou consider many iterations. It simply changes the maximum memory that can be used by "comsolserver.exe" before matlab crashes. For example: - with 128MB of heap space, comsolserver.exe stop working between 300-400MB of RAM space - with 512MB of heap space, it reaches little more than 1GB of RAM but it still crashes Anyway the solution that they suggest isn't very usefull: it simply moves the limit of the crash a little bit further, but it does not resolve the problem at all. In my scripts I need to invocate the function "postint()" (and ohters) many times, and the number of time that I call it should change depending on the number of frequency steps that I want in my simulations. A real general purpose script must work for every number of frequency steps, not a limited one! Thanks for your answer

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 10, 2011, 3:51 p.m. EST
I fully concur with you. Let us hope that this problem will be resolved in the future update or version. But do try to see if you could kill and then restart comsol server in each iteration through matlab. It didn't work for me back then but may be your experience would be more fruitful.

In case you or some other reader wants to try out his/her luck with the method I suggested above, do make sure not to use nohup command, contrary to what I earlier suggested. The following linux command easily starts the comsol server

comsol server > output.txt &

I have noticed that using nohup could be problematic in simple situations where it proves to be too sophisticated.
I fully concur with you. Let us hope that this problem will be resolved in the future update or version. But do try to see if you could kill and then restart comsol server in each iteration through matlab. It didn't work for me back then but may be your experience would be more fruitful. In case you or some other reader wants to try out his/her luck with the method I suggested above, do make sure not to use nohup command, contrary to what I earlier suggested. The following linux command easily starts the comsol server comsol server > output.txt & I have noticed that using nohup could be problematic in simple situations where it proves to be too sophisticated.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 8, 2011, 5:34 p.m. EST
The problem seems to exist in v4.1.0.154, too.
The problem seems to exist in v4.1.0.154, too.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 13, 2011, 6:19 p.m. EDT
I got the same problem here. I'm optimizing a geometry using matlab with comsol, i.e., i'm simulating thousands of design in a matlab loop, and I reach Java Heap Space memory problem after 50 designs.

Does anyone found a clean workaround to this problem ?


----------------
Université Laval
I got the same problem here. I'm optimizing a geometry using matlab with comsol, i.e., i'm simulating thousands of design in a matlab loop, and I reach Java Heap Space memory problem after 50 designs. Does anyone found a clean workaround to this problem ? ---------------- Université Laval

Sven Friedel COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 27, 2011, 4:11 a.m. EDT
Hello,

the most likely reason for that observation is that Comsol (incl. v 4.2)
stores history information for all steps you perform in Comsol. This
includes calls to mphint, mphinterp etc. When you run these commands in a
for loop the recorded history fills up the memory.

In Comsol 4.1 (and 4.2) you can switch off history cording by executing
this command:

model.hist.disable

In Comsol 4.2 this statement is automatically executed when loading a model
using mphload, but you have to execute it yourself if you create a model
using ModelUtil.create.

Sven Friedel
Hello, the most likely reason for that observation is that Comsol (incl. v 4.2) stores history information for all steps you perform in Comsol. This includes calls to mphint, mphinterp etc. When you run these commands in a for loop the recorded history fills up the memory. In Comsol 4.1 (and 4.2) you can switch off history cording by executing this command: model.hist.disable In Comsol 4.2 this statement is automatically executed when loading a model using mphload, but you have to execute it yourself if you create a model using ModelUtil.create. Sven Friedel

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 15, 2011, 5:23 p.m. EDT
I have tried executing model.hist.disable in v 4.2 however, the memory problem still presists.

Are there anyother suggestion around this problem?
I have tried executing model.hist.disable in v 4.2 however, the memory problem still presists. Are there anyother suggestion around this problem?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 28, 2011, 3:09 p.m. EDT
I've tried implementing the suggestion to stop and start the server within a loop using 4.2.0.228 but this doesn't work -
when you try to run a mphinterp call after stopping and restarting I get an error
java.lang.IllegalStateException: Not active: CDOTransaction(1)
suggesting that even though mphstart is going there is something else that means the command isn't correctly referred to the server. Anyone else seen something similar?
I've tried implementing the suggestion to stop and start the server within a loop using 4.2.0.228 but this doesn't work - when you try to run a mphinterp call after stopping and restarting I get an error java.lang.IllegalStateException: Not active: CDOTransaction(1) suggesting that even though mphstart is going there is something else that means the command isn't correctly referred to the server. Anyone else seen something similar?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 28, 2011, 3:14 p.m. EDT
What worked for me is to remove the model with ModelUtil.remove('model'); and then reload a clean model with mphload('model.mph') where all solutions and meshes have been removed before saving. A restart of the server was unnessecary and also did not work from matlab correctly in 4.1, only workaround was a python script, to contiously restart the server after ModelUtil.disconnect();
What worked for me is to remove the model with ModelUtil.remove('model'); and then reload a clean model with mphload('model.mph') where all solutions and meshes have been removed before saving. A restart of the server was unnessecary and also did not work from matlab correctly in 4.1, only workaround was a python script, to contiously restart the server after ModelUtil.disconnect();

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 28, 2011, 7:04 p.m. EDT
Yes, that works! How does that clear the java heap?
Yes, that works! How does that clear the java heap?

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 5, 2011, 6:02 a.m. EDT
Hi

Very, very large loops may have problems due to large models and their complexity and may require extra steps such as restarting the Comsol Server or remove'ing the model from the server.

For simple loops one should expect that mphinterp (and the other functions) just work. We have identified and fixed some reasons for memory leaks in Comsol 4.2a which is soon going to be released.

I you (or anyone else) experience problems in the future like this then please post a model and a script we can use for testing. Alternatively, send the files to support@comsol.com where we are sure that we will see your report.


Lars Gregersen
Comsol Denmark
Hi Very, very large loops may have problems due to large models and their complexity and may require extra steps such as restarting the Comsol Server or remove'ing the model from the server. For simple loops one should expect that mphinterp (and the other functions) just work. We have identified and fixed some reasons for memory leaks in Comsol 4.2a which is soon going to be released. I you (or anyone else) experience problems in the future like this then please post a model and a script we can use for testing. Alternatively, send the files to support@comsol.com where we are sure that we will see your report. Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 17, 2011, 4:04 a.m. EDT
What is the current status in addressing this serious problem? I am running Comsol 4.1 (4.1.0.185) together with Matlab R2011a (7.12.0.635). I have tested the solutions suggested in this thread but the memory problem remains. After calling mphinterp a few tens of times the calculation always runs into the "Java heap space" error. This is very frustrating as the combination of Matlab and Comsol would be particularly useful in automating long chains of simulations and optimization tasks. At the moment this does not seem possible.

With kind regards,

Klas

What is the current status in addressing this serious problem? I am running Comsol 4.1 (4.1.0.185) together with Matlab R2011a (7.12.0.635). I have tested the solutions suggested in this thread but the memory problem remains. After calling mphinterp a few tens of times the calculation always runs into the "Java heap space" error. This is very frustrating as the combination of Matlab and Comsol would be particularly useful in automating long chains of simulations and optimization tasks. At the moment this does not seem possible. With kind regards, Klas

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 28, 2011, 5:02 p.m. EDT
I perform iterations between an external software and comsol. After I modified comsol's solution externally, I reinitialize the solution vector and solve the comsol model for another time step in. With the latest versions, the comsol server closes at a random time step and MATLAB becomes irresponsive. I have tried all previous suggestions including increasing the Java heap space at various locations (java.opts, Matlab preferences, comsol.ini).
I perform iterations between an external software and comsol. After I modified comsol's solution externally, I reinitialize the solution vector and solve the comsol model for another time step in. With the latest versions, the comsol server closes at a random time step and MATLAB becomes irresponsive. I have tried all previous suggestions including increasing the Java heap space at various locations (java.opts, Matlab preferences, comsol.ini).

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 29, 2011, 1:27 a.m. EDT
the elegant way with mphload (but you have to know the content of the .mph file in order to modify it in a loop because you don't see the content of the file on the screen with mphload, of course you can generate a .m file of your .mph and copy it in comments in your script):

1. start matlab alone
2. the code in matlab:

!C:\COMSOL42\bin\win64\comsolserver.exe &
pause(4) % some time to start the server peacefully...
addpath C:\COMSOL42\mli
mphstart
import com.comsol.model.*
import com.comsol.model.util.*

k = {'1000' '2000' '3000'} ; % thermal conductivity
for n = 1:length(k)
model = mphload('simple_heat_conduction_problem.mph') ;
pause(2)
ModelUtil.showProgress(true); % display the progress bar
pause(2) % some time to start the showProgress command peacefully...

% modify k in the loop, this is the content of the .mph file that you have to know...
model.physics('ht').feature('solid1').set('k', {k{n}; '0'; '0'; '0'; k{n}; '0'; '0'; '0'; k{n}});

model.sol('sol1').runAll;
Results = mpheval(model,'T') ;
save(['Results_',num2str(n)],'Results')
ModelUtil.remove('model')
end

3. works for me, hope it works for you, enjoy!

the elegant way with mphload (but you have to know the content of the .mph file in order to modify it in a loop because you don't see the content of the file on the screen with mphload, of course you can generate a .m file of your .mph and copy it in comments in your script): 1. start matlab alone 2. the code in matlab: !C:\COMSOL42\bin\win64\comsolserver.exe & pause(4) % some time to start the server peacefully... addpath C:\COMSOL42\mli mphstart import com.comsol.model.* import com.comsol.model.util.* k = {'1000' '2000' '3000'} ; % thermal conductivity for n = 1:length(k) model = mphload('simple_heat_conduction_problem.mph') ; pause(2) ModelUtil.showProgress(true); % display the progress bar pause(2) % some time to start the showProgress command peacefully... % modify k in the loop, this is the content of the .mph file that you have to know... model.physics('ht').feature('solid1').set('k', {k{n}; '0'; '0'; '0'; k{n}; '0'; '0'; '0'; k{n}}); model.sol('sol1').runAll; Results = mpheval(model,'T') ; save(['Results_',num2str(n)],'Results') ModelUtil.remove('model') end 3. works for me, hope it works for you, enjoy!

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 29, 2011, 1:39 a.m. EDT
the hard way (start comsolserver...connect to server...code...disconnect server...restart server... The advantage is that you see the content of your .m file):

1. start matlab alone
2. the code in matlab:

k = {'1000' '2000' '3000'} ; % thermal conductivity

for n = 1:length(k)
!C:\COMSOL42\bin\win64\comsolserver.exe &
pause(4) % some time to start the server peacefully...
if n == 1
addpath C:\COMSOL42\mli
end
mphstart
if n==1
import com.comsol.model.*
import com.comsol.model.util.*
end

model = ModelUtil.create('Model');
model.hist.disable
pause(2) % some time to start the showProgress command peacefully...
ModelUtil.showProgress(true); % display the progress bar
pause(2) % some time to start the showProgress command peacefully...

.....content of your .m model
% modify k in the loop
model.physics('ht').feature('solid1').set('k', {k{n}; '0'; '0'; '0'; k{n}; '0'; '0'; '0'; k{n}});
.....content of your .m model

model.sol('sol1').runAll ;
Results = mpheval(model,'T') ;
save(['Results_',num2str(n)],'Results')
ModelUtil.disconnect ;
dos('taskkill /IM cmd.exe') ;
pause(1)
end

3. works for me, hope it works for you, enjoy! I hope comsol will not solve this issue, it took me hours to figure it out!!!
the hard way (start comsolserver...connect to server...code...disconnect server...restart server... The advantage is that you see the content of your .m file): 1. start matlab alone 2. the code in matlab: k = {'1000' '2000' '3000'} ; % thermal conductivity for n = 1:length(k) !C:\COMSOL42\bin\win64\comsolserver.exe & pause(4) % some time to start the server peacefully... if n == 1 addpath C:\COMSOL42\mli end mphstart if n==1 import com.comsol.model.* import com.comsol.model.util.* end model = ModelUtil.create('Model'); model.hist.disable pause(2) % some time to start the showProgress command peacefully... ModelUtil.showProgress(true); % display the progress bar pause(2) % some time to start the showProgress command peacefully... .....content of your .m model % modify k in the loop model.physics('ht').feature('solid1').set('k', {k{n}; '0'; '0'; '0'; k{n}; '0'; '0'; '0'; k{n}}); .....content of your .m model model.sol('sol1').runAll ; Results = mpheval(model,'T') ; save(['Results_',num2str(n)],'Results') ModelUtil.disconnect ; dos('taskkill /IM cmd.exe') ; pause(1) end 3. works for me, hope it works for you, enjoy! I hope comsol will not solve this issue, it took me hours to figure it out!!!

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 2, 2012, 11:04 a.m. EDT
I am using COMSOL 4.2 and I still face the memory problem. I am rebuilding the model during every iteration to make it work.

Thanks,
Kapil
I am using COMSOL 4.2 and I still face the memory problem. I am rebuilding the model during every iteration to make it work. Thanks, Kapil

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 1, 2012, 9:32 a.m. EDT
Dear Mr. Friedel,

I had the same problem with the "mphinterp" command. I used to call the "mphinterp" within the loop where the code crashed after some time. The suggested command "model.hist.disable" helped to avoid this problem. However, if I use the "mphinterp" to get the data on large pre-defined 3D grids the error "out of memory" is displayed in Matlab command window. Everything was working fine on the version 3.5a even for larger grids.

Best regards,
Mladen Zec
Dear Mr. Friedel, I had the same problem with the "mphinterp" command. I used to call the "mphinterp" within the loop where the code crashed after some time. The suggested command "model.hist.disable" helped to avoid this problem. However, if I use the "mphinterp" to get the data on large pre-defined 3D grids the error "out of memory" is displayed in Matlab command window. Everything was working fine on the version 3.5a even for larger grids. Best regards, Mladen Zec

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.