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.
Use of progress bar through prompt ModelUtil.showProgress(true) in COMSOL livelink
Posted 26.05.2021, 15:39 GMT-4 1 Reply
Please login with a confirmed email address before reporting spam
The below post is related to an archived discussion
Hi all,
I just started working with COMSOL-Matlab livelink. Quite frankly, the manual has been extremely useless for me as every prompt I've used from it has been red flagged by Matlab. In my experience saving the mph-file as an m-file has been most useful (and very time consumming I must add) to reverse engineer the process.
Every prompt introduced by the manual or the navigator (accessible through mphnavigator in Matlab) has a specific location in your model as COMSOL goes through the simulation setup sequentially. The simulation sequence can be seen in COMSOL Model Builder window. This means that it is important to know what portion of your simulation is carried out in Matlab. This how I did it; it is important to know that this is not the only way as users define the level at which these two engines collaborate. I created the core of my simulation in COMSOL. This includes defining parameters, materials, and boundary conditions, creating geometry, determining the study and physics, and meshing. The only steps left were therefore adding parametric sweep(s) (if needed) and running the simulation, which were done through Matlab. Note that at this point, most of our model is already defined in the COMSOL file, so redefining anything from the model would result in an error in Matlab. I opened the mph-file in Matlab, added a aparemtric sweep, and ran it without the progress bar. My code is as follows:
%% Open file mphopen('v0.mph') %% Adding primary parametric sweeps model.study('std1').create('param', 'Parametric'); model.study('std1').feature('param').set('sweeptype', 'filled'); model.study('std1').feature('param').set('pname', {param1 param2}); model.study('std1').feature('param').set('plistarr', {range1 range2}); model.study('std1').feature('param').set('punit', {'m' 'm'}); %% Run sim model.study('std1').run
ModelUtil.showProgress(true) belongs to a COMCOL library that needs to be imported into Matlab. This is done through "import com.comsol.model.util.*". Note that this is also done in the MPH-file. If you open the m-file of your mph-file, it is your second line. For some strange reason, Matlab likes to have the libraries before openning the mph-file. I did so and it worked! Now I see the progress bar without any error throughout the simulation. Here is the final code:
%% Importing library import com.comsol.model.util.* ModelUtil.showProgress(true);
%% Openning file mphopen('v0.mph')
%% Adding primary parametric sweep model.study('std1').create('param', 'Parametric'); model.study('std1').feature('param').set('sweeptype', 'filled'); model.study('std1').feature('param').set('pname', {param1 param2}); model.study('std1').feature('param').set('plistarr', {range1 range2}); model.study('std1').feature('param').set('punit', {'m' 'm'});
%% Run the sim model.study('std1').run
The progress window does not pop out as it is a subcategory of the DOS command window that creates the livelink. Windows however notifies you where you can find it. This is what has worked for me and hope works for you too. I wish the COMSOL sopport team spent more time on explaining how these prompts work together.
Cheers, Max
Attachments: