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.

Single Shot

Please login with a confirmed email address before reporting spam

Hi, I want to use a Comsol model in Matlab where I want to update a parameter after each iteration. Is there any way to use a study that calculates only a single time element and then updates the parameter in Matlab and then calculates the next single time element.

Thanks in advance


6 Replies Last Post 6 ott 2022, 08:59 GMT-4
Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 5 ott 2022, 10:11 GMT-4

Johannes,

parameters cannot be updated during a solution process, but you can define a variable according to your needs. The variable will then be calculated in each time step and you can refer to it in the model, e.g. in boundary conditions. Depending on your requirements you may not need Matlab for that.

Cheers Edgar

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Johannes, parameters cannot be updated during a solution process, but you can define a variable according to your needs. The variable will then be calculated in each time step and you can refer to it in the model, e.g. in boundary conditions. Depending on your requirements you may not need Matlab for that. Cheers Edgar

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 6 ott 2022, 01:54 GMT-4

Edgar,

is there any way to calculate the solution in Matlab using state space extraction, as I am currently designing a controller for the model and my company has only given the "LiveLink for Simulink" license to the license bool for the coming quarter, so this will not be available until November.

Johannes

Edgar, is there any way to calculate the solution in Matlab using state space extraction, as I am currently designing a controller for the model and my company has only given the "LiveLink for Simulink" license to the license bool for the coming quarter, so this will not be available until November. Johannes


Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 6 ott 2022, 04:10 GMT-4

Dear Johannes,

To implement such a control system the easiest is to use LiveLink for Simulink, which enables cosimulation between COMSOL Multiphysics and Simulink. You can benefit the Simulink interface to implement the control system and solve the physical problem in COMSOL.

Alternatively you can implement the control system entirely in COMSOL as it is described in the Application Library model: https://www.comsol.com/model/process-control-using-a-pid-controller-866

Dear Johannes, To implement such a control system the easiest is to use LiveLink for Simulink, which enables cosimulation between COMSOL Multiphysics and Simulink. You can benefit the Simulink interface to implement the control system and solve the physical problem in COMSOL. Alternatively you can implement the control system entirely in COMSOL as it is described in the Application Library model: https://www.comsol.com/model/process-control-using-a-pid-controller-866

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 6 ott 2022, 06:02 GMT-4
Updated: 2 years ago 6 ott 2022, 06:06 GMT-4

Thank you for your expertise

The problem with this controller lib is that I am not using a PID controller. In my case I would use a state space controller and so I want to extract the states or use this single shot. As I said, the license is requested but not solved yet. Maybe you have an idea how to extract the SS model, because when I extract that the first time it works, but on the second run the Matlab console gives the following error message and I don't always want to remove that manually.

Error using mphstate
Solution already contains an active StateSpace node.

Error in State_Space_MJ1 (line 25)
M = mphstate(model2,'sol1','out', {'MA' 'MB' 'Mc' 'C' 'D' 'x0', 'Null', 'ud'},...`
Thank you for your expertise The problem with this controller lib is that I am not using a PID controller. In my case I would use a state space controller and so I want to extract the states or use this single shot. As I said, the license is requested but not solved yet. Maybe you have an idea how to extract the SS model, because when I extract that the first time it works, but on the second run the Matlab console gives the following error message and I don't always want to remove that manually. Error using mphstate Solution already contains an active StateSpace node. Error in State_Space_MJ1 (line 25) M = mphstate(model2,'sol1','out', {'MA' 'MB' 'Mc' 'C' 'D' 'x0', 'Null', 'ud'},...`

Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 6 ott 2022, 08:52 GMT-4

Dear Johannes,

the error message indicates that between the two runs the state-space node remain active in the COMSOL model. When calling MPHSTATE. make sure you set the property 'keepfeature' to 'off' to avoid this issue. I would rather recommend you to use a reduced order model (ROM) from which you can also extract state-space matrices (with the function MPHREDUCTION), as this approach provides more efficient matrices to work with.

If you still have issue the best is to continue the discussion via the COMSOL support, feel free to address the question to me.

Best regards,

Dear Johannes, the error message indicates that between the two runs the state-space node remain active in the COMSOL model. When calling MPHSTATE. make sure you set the property 'keepfeature' to 'off' to avoid this issue. I would rather recommend you to use a reduced order model (ROM) from which you can also extract state-space matrices (with the function MPHREDUCTION), as this approach provides more efficient matrices to work with. If you still have issue the best is to continue the discussion via the COMSOL support, feel free to address the question to me. Best regards,

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 6 ott 2022, 08:59 GMT-4

It works for me now, thank you very much.

It works for me now, thank you very much.

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.