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.

LiveLink with Matlab - Updating input force

Please login with a confirmed email address before reporting spam

Hi everyone, I'm working on an active vibration control of a structure modeled in Comsol with a control algorithm written in Matlab. What I'm trying to do is linking the model to the algorithm using LiveLink for Matlab. In particular I need to perform a step of the simulation (in time domain), export a quantity from Comsol (which we can call "error"), feed it to Matlab control algorithm which basing on that will update the input force (the control force) and apply that force to the Comsol model at the next step. This process will continue untill the "error" is minimized. My question is how can I do this? In particular how can I update the force in the simulation at each step? Do I have to compute n simulations each of the duration of a step (each considering as initial condition the previous step) or it is possible to compute a unique simulation and update the input force at each step? I hope that I've explained the problem clearly, in any case thank you in advance.

Tommaso


6 Replies Last Post Nov 16, 2021, 5:57 a.m. EST
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Nov 8, 2021, 10:02 a.m. EST
Updated: 3 years ago Nov 8, 2021, 10:03 a.m. EST

Hi Tommaso

Allow me to advertise our LiveLink for Simulink that is made for exactly the scenario you describe: www.comsol.com/livelink-simulink

You can of course use LiveLink for Matlab to do the same thing, but you have to implement all the steps yourself. You need to update your model based on the input values you need, simulate in Comsol for a small period of time and extract the results afterwards.

-------------------
Lars Gregersen
Comsol Denmark
Hi Tommaso Allow me to advertise our LiveLink for Simulink that is made for exactly the scenario you describe: [www.comsol.com/livelink-simulink](https://www.comsol.com/livelink-simulink) You can of course use LiveLink for Matlab to do the same thing, but you have to implement all the steps yourself. You need to update your model based on the input values you need, simulate in Comsol for a small period of time and extract the results afterwards.

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Nov 8, 2021, 11:50 a.m. EST

First of all thank you for your reply. I was trying with LiveLink for Matlab because I have the student license and I don't have LiveLink for Simulink (can I add it maybe?). Anyway, can you elaborate a bit on what you've said about the updating of the model? Because I've understood the reasoning but practically I don't know how to tell to Comsol to update the input at each step from Matlab code. Thank you again,

Tommaso

First of all thank you for your reply. I was trying with LiveLink for Matlab because I have the student license and I don't have LiveLink for Simulink (can I add it maybe?). Anyway, can you elaborate a bit on what you've said about the updating of the model? Because I've understood the reasoning but practically I don't know how to tell to Comsol to update the input at each step from Matlab code. Thank you again, Tommaso

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Nov 9, 2021, 2:28 a.m. EST

Hi Tommaso

Sure you can add LiveLink for Simulink to your set of modules. Just ask your local sales representative.

I suggest you go through the material in the Introductiuon to LiveLink for Matlab manual and after that you look at the homogenization_llmatlab model in the Model Library.

-------------------
Lars Gregersen
Comsol Denmark
Hi Tommaso Sure you can add LiveLink for Simulink to your set of modules. Just ask your local sales representative. I suggest you go through the material in the Introductiuon to LiveLink for Matlab manual and after that you look at the homogenization_llmatlab model in the Model Library.

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Nov 9, 2021, 7:47 a.m. EST

Thank you again Lars, I'm looking for the installation of LiveLink for Simulink, but in the meantime I'm looking at the model that you suggested me, in order to try with Matlab. I understood the procedure but I'm left with a last doubt. In particular, in the example the "concentration" is the parameter to update at each iteration to start from the previous condition. In fact, it is the only parameter to set in the "initial values" node under the physics that it is used in the example. The problem is that my model is much more complex and I have many parameters to update at each iteration. I explain it better, I have a multiphysics problem with Shell and Pressure Acoustics Transient physics and a multiphysics coupling between them and I am looking to control the pressure in a point. More in detail, for Pressure Acoustics Transient under "initial values" I have the pressure and its first time derivative, while for Shell I have the displacement field, the structural velocity field, the displacement of shell normals and the first time derivative of the displacement of shell normals. Do I have to update all this parameters of both the physics, at each iteration, to have a study that starts from the result of the previous? Or is there a quicker way to do that (maybe in the study settings)?

Thank you so much again, Tommaso

Thank you again Lars, I'm looking for the installation of LiveLink for Simulink, but in the meantime I'm looking at the model that you suggested me, in order to try with Matlab. I understood the procedure but I'm left with a last doubt. In particular, in the example the "concentration" is the parameter to update at each iteration to start from the previous condition. In fact, it is the only parameter to set in the "initial values" node under the physics that it is used in the example. The problem is that my model is much more complex and I have many parameters to update at each iteration. I explain it better, I have a multiphysics problem with Shell and Pressure Acoustics Transient physics and a multiphysics coupling between them and I am looking to control the pressure in a point. More in detail, for Pressure Acoustics Transient under "initial values" I have the pressure and its first time derivative, while for Shell I have the displacement field, the structural velocity field, the displacement of shell normals and the first time derivative of the displacement of shell normals. Do I have to update all this parameters of both the physics, at each iteration, to have a study that starts from the result of the previous? Or is there a quicker way to do that (maybe in the study settings)? Thank you so much again, Tommaso

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Nov 11, 2021, 3:46 a.m. EST

I suggest you specify all your inputs to your model as parameters. This way you only need to worry about setting parameter values when updating your model - and the values will then propagate to whereever you use these parameter values automatically.

I suggest you start with a simple model having only one input and one output to learn how the workflow goes.

-------------------
Lars Gregersen
Comsol Denmark
I suggest you specify all your inputs to your model as parameters. This way you only need to worry about setting parameter values when updating your model - and the values will then propagate to whereever you use these parameter values automatically. I suggest you start with a simple model having only one input and one output to learn how the workflow goes.

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Nov 16, 2021, 5:57 a.m. EST

Hi Lars, I'm trying to do what you suggested me, but the problem is that the "initial values" node in the physics takes only a single value. In fact, in the example you suggested me (homogenization_llmatlab), there was a single value to be updated (the concentration average). However in my case I need to give the entire fields (vibration, velocity and so on) as initial values for the next study, so I need to put the values for each node of the mesh and not just a single number. Do you know what should be a possible solution? Thank you again,

Tommaso

Hi Lars, I'm trying to do what you suggested me, but the problem is that the "initial values" node in the physics takes only a single value. In fact, in the example you suggested me (homogenization_llmatlab), there was a single value to be updated (the concentration average). However in my case I need to give the entire fields (vibration, velocity and so on) as initial values for the next study, so I need to put the values for each node of the mesh and not just a single number. Do you know what should be a possible solution? Thank you again, Tommaso

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.