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.

Sending Feedback Controller Data From MATLAB to COMSOL Parameter

Please login with a confirmed email address before reporting spam

I am simulating the flow of gases through a pipe where domain probes were added to obtain the concentration of a specific gas. I am using COMSOL LiveLink with MATLAB in order to control the flow rate of a gas. I am trying to create a PID controller but would like to know how to send the feedback information into COMSOL via MATLAB. Is there a method of asking MATLAB to change the flow rate parameter of a gas in real time? For instance, is there a way to use mph functions in MATLAB which allows me to feedback the change in flow rate of a gas in order to obtain a desired concentration or mole fraction of a gas in the system.

Thank you for your time and help.


4 Replies Last Post Apr 19, 2022, 10:54 a.m. EDT
Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago Apr 12, 2022, 10:38 a.m. EDT

Dear Christian,

It seems that the problem you want to solve is exactly what LiveLink for Simulink is made for: running cosimulation between Simulink and COMSOL.

If you want to do it in MATLAB, you can look for the tutorial model: pseudoperiodicity_llmatlab. This model shows how to extract COMSOL result in MATLAB and set MATLAB variables back to the COMSOL model.

Dear Christian, It seems that the problem you want to solve is exactly what LiveLink for Simulink is made for: running cosimulation between Simulink and COMSOL. If you want to do it in MATLAB, you can look for the tutorial model: pseudoperiodicity_llmatlab. This model shows how to extract COMSOL result in MATLAB and set MATLAB variables back to the COMSOL model.

NafGh Tallinn University of technology

Please login with a confirmed email address before reporting spam

Posted: 2 years ago Apr 17, 2022, 1:46 p.m. EDT

Dear Christain,

Yes, this can be done. Your PID controller designed in MATLAB can a Function in COMSOL. However, to get real time the error from the concentration of gas, you would have to add to the study the Previous Solution Operator . you can get more information on this from the link below https://www.comsol.com/blogs/using-the-previous-solution-operator-in-transient-modeling/#:~:text=COMSOL%20Multiphysics%20version%205.1%20includes,default%20implicit%20time%2Dstepping%20algorithm.

Dear Christain, Yes, this can be done. Your PID controller designed in MATLAB can a Function in COMSOL. However, to get real time the error from the concentration of gas, you would have to add to the study the Previous Solution Operator . you can get more information on this from the link below https://www.comsol.com/blogs/using-the-previous-solution-operator-in-transient-modeling/#:~:text=COMSOL%20Multiphysics%20version%205.1%20includes,default%20implicit%20time%2Dstepping%20algorithm.

Dave Greve Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 2 years ago Apr 18, 2022, 1:50 p.m. EDT
Updated: 2 years ago Apr 18, 2022, 1:51 p.m. EDT

An alternate approach would be to implement the controller in Comsol using added ODE physics.

(Easy enough for a simple PID controller with constant coefficients).

An alternate approach would be to implement the controller in Comsol using added ODE physics. (Easy enough for a simple PID controller with constant coefficients).

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago Apr 19, 2022, 10:54 a.m. EDT

Yes, or use the PID Controller add-in, available from Add-in Libraries on the Developer ribbon toolbar in the COMSOL Desktop.

Yes, or use the PID Controller add-in, available from Add-in Libraries on the Developer ribbon toolbar in the COMSOL Desktop.

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.