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
Posted 11 juil. 2023, 06:15 UTC−4 LiveLink for MATLAB, Mesh, Optimization Version 6.1 7 Replies
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,
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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 :-)
Please login with a confirmed email address before reporting spam
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.
Please login with a confirmed email address before reporting spam
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,
Please login with a confirmed email address before reporting spam
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.
Please login with a confirmed email address before reporting spam
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.