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

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



1 Reply Last Post Jun 1, 2021, 7:41 a.m. EDT
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Jun 1, 2021, 7:41 a.m. EDT
Updated: 3 years ago Jun 1, 2021, 7:42 a.m. EDT

Hi Max

Saving the model as an M-file as a way to learn about the COMSOL API syntax is the recommended way of learning about how things work since that is the fastest approach.

Setting up everything or most of your model using the COMSOL GUI is also the recommended way of working with Comsol model since MPH-files tend to load faster than running the entire script that recreates the model fram scratch.

The COMSOL API is based on Java, which is easily accessible in Matlab. You use the import statement to make it possible for Matlab to find the libraries it needs. If you don't like to use import statement you can also resort to using statements like this one:

com.comsol.model.util.ModelUtil.showProgress(true)

Note that there is no difference in working with a model using LiveLink for Matlab compared to working with the model using the COMSOL GUI. At any time you can use either environment to interact with your model and e.g. redefine any parts of your model. You can even use the two environments simultaneously. Use this command to see how:

help mphlaunch
-------------------
Lars Gregersen
Comsol Denmark
Hi Max Saving the model as an M-file as a way to learn about the COMSOL API syntax _is_ the recommended way of learning about how things work since that is the fastest approach. Setting up everything or most of your model using the COMSOL GUI _is_ also the recommended way of working with Comsol model since MPH-files tend to load faster than running the entire script that recreates the model fram scratch. The COMSOL API is based on Java, which is easily accessible in Matlab. You use the import statement to make it possible for Matlab to find the libraries it needs. If you don't like to use import statement you can also resort to using statements like this one: com.comsol.model.util.ModelUtil.showProgress(true) Note that there is no difference in working with a model using LiveLink for Matlab compared to working with the model using the COMSOL GUI. At any time you can use either environment to interact with your model and e.g. redefine any parts of your model. You can even use the two environments simultaneously. Use this command to see how: help mphlaunch

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.