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 Optimization get volume of each element

Hendrik Mechanical Engineering

Please login with a confirmed email address before reporting spam

Hello all,

I want to run a Density Model Topology Optimization using LiveLink MATLAB.

My question is regarding the extraction of the surface area / volume of each element in the mesh - how does one do this efficiently?

I have tried using "export / meshvol" , but it seems that the ordering of the elements is different from the ordering of the design variables (I could be mistaken though, or have an incorrect implementation).

Is this the way to do it ? or does a more elegant way exist?

Kind regards,


7 Replies Last Post 12 juil. 2023, 09:04 UTC−4
Kristian Ejlebjærg Jensen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 11 juil. 2023, 06:54 UTC−4

Hi

You can combine the getVertex and getElem for accessing mesh data (https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/comsol_api_mesh.48.33.html?highlight=getelem) with the setInterpolationCoordinates of the interpolation feature (https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/comsol_api_results.51.069.html?highlight=setinterpolationcoordinates)

To verify correctness, you can combine the getU(), setU() and createSolution() methods. For academic problems, you might be able to just use a mapped mesh so that all elements have the same size. Plotting surface data manually might also be of use. This ought to be easy in MATLAB. Alternatively, you can use the COMSOL API functionality:

https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/comsol_api_results.51.147.html?highlight=surfacedata

Best regards,

Kristian E. Jensen

Technical Product Manager, Optimization

Hi You can combine the getVertex and getElem for accessing mesh data (https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/comsol_api_mesh.48.33.html?highlight=getelem) with the setInterpolationCoordinates of the interpolation feature (https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/comsol_api_results.51.069.html?highlight=setinterpolationcoordinates) To verify correctness, you can combine the getU(), setU() and createSolution() methods. For academic problems, you might be able to just use a mapped mesh so that all elements have the same size. Plotting surface data manually might also be of use. This ought to be easy in MATLAB. Alternatively, you can use the COMSOL API functionality: https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/comsol_api_results.51.147.html?highlight=surfacedata Best regards, Kristian E. Jensen Technical Product Manager, Optimization

Kristian Ejlebjærg Jensen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 11 juil. 2023, 07:48 UTC−4

Hi

Alternatively, you could just set the volume as objective and use the sensitivity functionality to get the element sizes. That approach ought to be compatible with different discretizations.

Best regards,

Kristian E. Jensen

Technical Product Manager, Optimization

Hi Alternatively, you could just set the volume as objective and use the sensitivity functionality to get the element sizes. That approach ought to be compatible with different discretizations. Best regards, Kristian E. Jensen Technical Product Manager, Optimization

Hendrik Mechanical Engineering

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 11 juil. 2023, 09:05 UTC−4

Hi Kristian ,

Thank you very much for your replies. I have looked into both approaches and would like to ask a short question about both of them

approach 1 : am I correct in understanding that one should give the getVertex result to the setInterpolationCoordinates , and that the latter then interpolates a function in the region defined by the vertices? In this case, I was unable to figure out to set a function (constant)

My approach 1 implementation (currently) is below:

model.result().numerical().create('interp1',"Interp") <--- create interpolation

vertices = model.component('comp1').mesh('mesh1').getVertex(); <--- get vertices

model.result().numerical('interp1').setInterpolationCoordinates(vertices); <--- assign vertices to interpolation points

<--- here should be the definition of the function to be interpolated (but I could be mistaken)

model.result().numerical('interp1').run(); <--- run interpolation result = model.result().numerical('interp1').getData(); <--- get result

approach 2 : sensitivity functionality

I have added a Sensitivity node , with an Integral Objective (function = 1) to the component in my model. Furthermore, a Sensitivity step is present in my Study.

Computing the overall area works perfectly with this node. However, I do not know how to compute the sensitivity of the overall area with respect to the individual element sizes as you mentioned.

I thought to the size of the individual elements might have to be set up as an independent Control Variable (which can vary per element). However, I don't see how to enforce this.

Thanks in advance for your reply. Your previous replies have been very helpful :-)

Hi Kristian , Thank you very much for your replies. I have looked into both approaches and would like to ask a short question about both of them approach 1 : am I correct in understanding that one should give the getVertex result to the setInterpolationCoordinates , and that the latter then interpolates a function in the region defined by the vertices? In this case, I was unable to figure out to set a function (constant) My approach 1 implementation (currently) is below: model.result().numerical().create('interp1',"Interp")

Kristian Ejlebjærg Jensen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 11 juil. 2023, 09:46 UTC−4

No, my suggestion was to combine getVertex and getElem to compute the element centers and input that with setInterpolationCoordinates. You would need to use the dvol/meshvol as interpolation expression.

I guess the reason you want the element size is to enforce a volume constraint, because the sensitivity of that is equal to the element size (assuming you are using elementwise constant control variables). The sensitivity approach will give you the area associated with each control regardless of the discretization, so it is a more general solution.

No, my suggestion was to combine getVertex and getElem to compute the element centers and input that with setInterpolationCoordinates. You would need to use the dvol/meshvol as interpolation expression. I guess the reason you want the element size is to enforce a volume constraint, because the sensitivity of that is equal to the element size (assuming you are using elementwise constant control variables). The sensitivity approach will give you the area associated with each control regardless of the discretization, so it is a more general solution.

Hendrik Mechanical Engineering

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 11 juil. 2023, 10:15 UTC−4

Hi ,

Yes the volume constraint is indeed what I want to enforce. It is for that reason that I would like to compute the element size for the sensitivity

I think the sensitivity approach works better, but I have problems getting the element volume using it. Should the size of each element be implemented as a Control Variable Field ? How should this variable be implemented (as the size of each element can differ)?

Thanks in advance,

Hi , Yes the volume constraint is indeed what I want to enforce. It is for that reason that I would like to compute the element size for the sensitivity I think the sensitivity approach works better, but I have problems getting the element volume using it. Should the size of each element be implemented as a Control Variable Field ? How should this variable be implemented (as the size of each element can differ)? Thanks in advance,

Kristian Ejlebjærg Jensen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 12 juil. 2023, 06:16 UTC−4

Hi

If you integrate the selection of the Control Variable Field and use that as objective, while setting an element wise constant discretization for the controls, the sensitivity should become the element sizes.

It is easy to test that in the UI by comparing the fsens() operator with the meshvol variable.

Hi If you integrate the selection of the Control Variable Field and use that as objective, while setting an element wise constant discretization for the controls, the sensitivity should become the element sizes. It is easy to test that in the UI by comparing the fsens() operator with the meshvol variable.

Hendrik Mechanical Engineering

Please login with a confirmed email address before reporting spam

Posted: 1 year ago 12 juil. 2023, 09:04 UTC−4

Hi

Thanks for your reply. I got it working , and wanted to note the following important settings for others who might want to replicate my work.

In Sensitivity node, created Integral Objective , with the objective being "meshvol", using integration order 1.

Also add Control variable field : both name and initial value were set to "meshvol" . Used discontinuous Lagrange with constant element order, which is crucial (!) for obtaining the correct results.

Also, in order to ensure that the number of elements is equal to the number of design variables, make sure that the density model Element Order is set to Constant, otherwise the amount of densities is equal to the number of vertices, (different from number of elements).

Thanks again for your help,

Hi Thanks for your reply. I got it working , and wanted to note the following important settings for others who might want to replicate my work. In Sensitivity node, created Integral Objective , with the objective being "meshvol", using integration order 1. Also add Control variable field : both name and initial value were set to "meshvol" . Used discontinuous Lagrange with constant element order, which is crucial (!) for obtaining the correct results. Also, in order to ensure that the number of elements is equal to the number of design variables, make sure that the density model Element Order is set to Constant, otherwise the amount of densities is equal to the number of vertices, (different from number of elements). Thanks again for your help,

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.