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.

How to input a field variable from matlab to comsol

Please login with a confirmed email address before reporting spam

I am doing a structual optimization, and I can not find a way to transfer the design variable (a field variable) to the comsol from matlab. Can someone shed a light on it, please!!!


5 Replies Last Post 19 nov. 2019, 10:01 UTC−5
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 14 nov. 2019, 06:39 UTC−5

Hi Lin

You can retrieve numerical values from Comsol to Matlab in a number of ways.

mphinterp gives you values at arbitrary coordinates.

mpheval gives you values at node points.

mphgetu gives you the raw solution vector. You use the information returned from mphxmeshinfo to identify which field variables are stored where in this vector.

Comsol has support for returning sensitivities that may be useful when doing optimisation. See the chapter on "Sensitivity Analysis" in the Reference Manual for more information.

-------------------
Lars Gregersen
Comsol Denmark
Hi Lin You can retrieve numerical values from Comsol to Matlab in a number of ways. mphinterp gives you values at arbitrary coordinates. mpheval gives you values at node points. mphgetu gives you the raw solution vector. You use the information returned from mphxmeshinfo to identify which field variables are stored where in this vector. Comsol has support for returning sensitivities that may be useful when doing optimisation. See the chapter on "Sensitivity Analysis" in the Reference Manual for more information.

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 14 nov. 2019, 07:00 UTC−5

I think he or she's asking about how to transfer the variable the other way around.

-------------------
ZHANG, Pu
School of Physics,
Huazhong University of Science and Technology
I think he or she's asking about how to transfer the variable the other way around.

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 15 nov. 2019, 04:49 UTC−5

Hi Pu

You could be right ;-)

You can "transfer" a field variable back to a Comsol model by

  1. Saving the data as a file and set up an interpolation function.
  2. Use the COMSOL API to set a solution vector in the Comsol model. There is no easy to use function for this. See the section "Solution Creation" in the Programming Reference Manual for more info
-------------------
Lars Gregersen
Comsol Denmark
Hi Pu You could be right ;-) You can "transfer" a field variable back to a Comsol model by 1. Saving the data as a file and set up an interpolation function. 2. Use the COMSOL API to set a solution vector in the Comsol model. There is no easy to use function for this. See the section "Solution Creation" in the Programming Reference Manual for more info

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 15 nov. 2019, 07:40 UTC−5

Good to know.

It sounds there's no very direct way to do the variable assignment via Matlab Livelink.

-------------------
ZHANG, Pu
School of Physics,
Huazhong University of Science and Technology
Good to know. It sounds there's no very direct way to do the variable assignment via Matlab Livelink.

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 19 nov. 2019, 10:01 UTC−5

Hi Pu

You could be right ;-)

You can "transfer" a field variable back to a Comsol model by

  1. Saving the data as a file and set up an interpolation function.
  2. Use the COMSOL API to set a solution vector in the Comsol model. There is no easy to use function for this. See the section "Solution Creation" in the Programming Reference Manual for more info

Thanks for your reply! The second methods you suggested actually works and I am grateful for your help!! But I encounter another problem now , I want to caculate the integration of the shape functions( and other function as well) on each node. At first, I try to set up a PDE fields and extract the residual Vector from it, but I find out that I need to solve the PDE fields first then I can get the residual Vector. Is there any other way to acquire the integration of the shape functions on every node?

>Hi Pu > >You could be right ;-) > >You can "transfer" a field variable back to a Comsol model by > >1. Saving the data as a file and set up an interpolation function. >2. Use the COMSOL API to set a solution vector in the Comsol model. There is no easy to use function for this. See the section "Solution Creation" in the Programming Reference Manual for more info Thanks for your reply! The second methods you suggested actually works and I am grateful for your help!! But I encounter another problem now , I want to caculate the integration of the shape functions( and other function as well) on each node. At first, I try to set up a PDE fields and extract the residual Vector from it, but I find out that I need to solve the PDE fields first then I can get the residual Vector. Is there any other way to acquire the integration of the shape functions on every node?

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.