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.

Mesh element volume

Please login with a confirmed email address before reporting spam

Dear all,

I have a material property having a different value in a domain and
it is function of individual volume of deformed mesh element and undeformed mesh
element.
Could you tell me how to get the volume of the mesh element?
In 2D, this may be the area of the each element. (Am I right?)

I appreciate your reply.

Thank you.

Yoon

22 Replies Last Post Feb 9, 2016, 11:57 AM EST

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 4, 2009, 6:12 AM EDT
hello
I'm not sure I really catch fully your request, but to calculate the volume, surface, length you simply apply a "Integration Coupling Variable" on a Subdomain, Boundary, respectively Edge, you define the geometrical object onto where to integrate, and you integrate with the value "1".
It's not writen fully out but these GUI's are there to calculate th integration over dV=dx,dy,dz, dA=dx,dy, respectiely ds (or whatever Geometry Reference Coordinate you are using, length is slightly particular as it differs slightly depending on the number of DoFs seleted, have a read through the manuals).
Such an integratin can only be calulated once the volume is meshed and the solver initialised (use Solve Get Inital Value).

Now if you want to get the mesh difference before and after "deformation" you have either the "u,v,w" values to play with or you could perhaps turn on the "frame" (Physics Properties Crate Frame On) and then integrate on the different frames you define.

I would suggest that you write out the equations of what you want to do and then read through the manuals, start to test with a simple case.

Comsol, in opposition to most other FEM programmes is really a global physics PDE solver, so you should really switch to thinking physics from the PDE world side, not the first though fr those of us trained to use more traditional FEM programmes

Good luck
hello I'm not sure I really catch fully your request, but to calculate the volume, surface, length you simply apply a "Integration Coupling Variable" on a Subdomain, Boundary, respectively Edge, you define the geometrical object onto where to integrate, and you integrate with the value "1". It's not writen fully out but these GUI's are there to calculate th integration over dV=dx,dy,dz, dA=dx,dy, respectiely ds (or whatever Geometry Reference Coordinate you are using, length is slightly particular as it differs slightly depending on the number of DoFs seleted, have a read through the manuals). Such an integratin can only be calulated once the volume is meshed and the solver initialised (use Solve Get Inital Value). Now if you want to get the mesh difference before and after "deformation" you have either the "u,v,w" values to play with or you could perhaps turn on the "frame" (Physics Properties Crate Frame On) and then integrate on the different frames you define. I would suggest that you write out the equations of what you want to do and then read through the manuals, start to test with a simple case. Comsol, in opposition to most other FEM programmes is really a global physics PDE solver, so you should really switch to thinking physics from the PDE world side, not the first though fr those of us trained to use more traditional FEM programmes Good luck

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 4, 2009, 8:38 PM EDT
I appreciate your reply.

I noticed that ALE module can allow us to calculate the volume ratio of deformed and undeformed
mesh. The variable (dvol_ale/dvol) seems to give me the ratio for individual mesh element.
Please correct me if I'm wrong.

Thank you very much for your comments.

Yoon
I appreciate your reply. I noticed that ALE module can allow us to calculate the volume ratio of deformed and undeformed mesh. The variable (dvol_ale/dvol) seems to give me the ratio for individual mesh element. Please correct me if I'm wrong. Thank you very much for your comments. Yoon

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 13, 2009, 1:37 AM EDT
Hello

ALE is certainly a good approach, particularly if you have larger deformations. I cannot confirm your formula, bacause I havent to now used it myself, but from the help I beleive you are right.
I have learned to carefully check every variable, as there is not always the full physical formula written out in the doc (COMSOL would need to rewrite a full physics book, but I still beleive they should).
This is my only concern with COMSOL, I'm still not 100% used to COMSOl's way to not write indexes, nor even integrals , in their formulas, and GUI's.
Good luck
Hello ALE is certainly a good approach, particularly if you have larger deformations. I cannot confirm your formula, bacause I havent to now used it myself, but from the help I beleive you are right. I have learned to carefully check every variable, as there is not always the full physical formula written out in the doc (COMSOL would need to rewrite a full physics book, but I still beleive they should). This is my only concern with COMSOL, I'm still not 100% used to COMSOl's way to not write indexes, nor even integrals , in their formulas, and GUI's. Good luck

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Jul 22, 2011, 10:55 AM EDT
Hi,

In Comsol 4.1, is there a way to display or export the volume of each single mesh element (I am not speaking about the volume of a domain). I can display the size, h, but what about the volume of each mesh element? I could of course display h^3, which would assume that each element is a cube with edge length h. But I guess this is not really accurate.

Thanks for any help.

Alois
Hi, In Comsol 4.1, is there a way to display or export the volume of each single mesh element (I am not speaking about the volume of a domain). I can display the size, h, but what about the volume of each mesh element? I could of course display h^3, which would assume that each element is a cube with edge length h. But I guess this is not really accurate. Thanks for any help. Alois

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Jul 22, 2011, 2:33 PM EDT
Hi, Alois

You can probably utilize the deformation gradient tensor to calculate the volume of each mesh element.
For the large deformation, the determinant of the tensor give you the ratio of deformed and undeformed volume.
For the small deformation, you can use strain to get the approximate value for that.

Wonseok
Hi, Alois You can probably utilize the deformation gradient tensor to calculate the volume of each mesh element. For the large deformation, the determinant of the tensor give you the ratio of deformed and undeformed volume. For the small deformation, you can use strain to get the approximate value for that. Wonseok

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Jul 22, 2011, 3:19 PM EDT
Hi Wonsoek,

thanks for your suggestion. I do not have any mechanical deformation, since my problem uses the "Electric Currents" physics. I am just interested in the volume represented by each single mesh element.

I export the data to Matlab, where I need to compute an integral over a domain (Biot-Savart). This integral requires knowledge of a physical quantity at each mesh element (the current density) and the volume of each mesh element.

Exporting the current density is ok. But how do I export the volume of each mesh element?

Thanks. Alois
Hi Wonsoek, thanks for your suggestion. I do not have any mechanical deformation, since my problem uses the "Electric Currents" physics. I am just interested in the volume represented by each single mesh element. I export the data to Matlab, where I need to compute an integral over a domain (Biot-Savart). This integral requires knowledge of a physical quantity at each mesh element (the current density) and the volume of each mesh element. Exporting the current density is ok. But how do I export the volume of each mesh element? Thanks. Alois

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Dec 1, 2011, 2:08 PM EST
I am also interested in this problem. Did you find a solution?
I am also interested in this problem. Did you find a solution?

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Dec 1, 2011, 4:26 PM EST
Hi,
Yes I got the solution from Comsol support. Here is a summary of this support case:

My email #1:

I would like to ask you if there is a way to obtain the volume of a mesh element in Comsol 4.1. I know that there is a variable called "mesh element size", "h". According to the documentation of Comsol 3.5a:
"The variable h, available only in subdomains, represents the mesh element size (of the undeformed mesh), that is, the length of the longest edge of the element."
So in a first guess, I could assume that the mesh element is a cube of length h, and its volume is h^3. But this is of course not accurate. Is there a way to obtain the exact mesh element volume?
For example, let's assume that we have a domain with constant density. I would like to know the mass of each single mesh element. For this I need to know the volume of each single mesh element, such that I can multiply it with the density.

Comsol support answer #1:

You can use the variable "dvol" to determine the volume of the mesh elements. However, for non-block elements you need to multiply dvol with the following factors to get the correct volume.
Triangle : 1/2
Tetrahedron : 1/6
Prism : 1/2
Pyramid : 1/3

My email #2:

Thanks a lot for your help. Just to be sure that I understand you well:
by block elements, you mean quad and hex?

Is there a variable that describes the element type, e.g. var=1 for prism, var=2 for tetrahedron, var=3 for pyramid, etc?

Comsol support answer #2:

Yes.

Yes, you can use the variable "meshtype", which is equal to the number of element edges for each mesh element type, for example, 9 for prism and 6 for tetrahedron.

My email #3:

What I want to do does not work unfortunately. I drew a cylinder (radius r and height h) in Comsol, generated a mesh, and solved for a simple laminar flow through the cylinder. I then extracted the information for dvol and meshtype to two different text files. I then loaded the two files in Matlab, and ran a for loop over all the elements, checking which type
they are, and correcting the volume accordingly (Tetrahedron : 1/6, Prism : 1/2, etc.). Finally I sumed up all the single corrected volumes to obtain the total volume of the mesh. I ended up with a value which is completely wrong compared to the theoretical volume of the cylinder obtained by pi*r^2*h.
What is strange is that dvol and meshtype are given for each mesh point. How can a mesh point give any information about volume and element type?
There are points which belong to tetrahedrons and prisms at the same time. Nevertheless, they will either indicate tetrahedron or prism. Furthermore, what is the meaning of dvol for a mesh element? The volume of a point???
Thanks for clarifying this issue.

Comsol support answer #3:

When you export solution data to file you can specify the evaluation points for the export in the Advanced section. If you use the default settings you typically get several evaluation points for each element. This might be the reason for the incorrect value of the total volume resulting from your MATLAB script.
In this case you only want one evaluation point per element. To achieve this choose Gauss points in the Evaluate in list (and use Gauss point order 1).
Hi, Yes I got the solution from Comsol support. Here is a summary of this support case: My email #1: I would like to ask you if there is a way to obtain the volume of a mesh element in Comsol 4.1. I know that there is a variable called "mesh element size", "h". According to the documentation of Comsol 3.5a: "The variable h, available only in subdomains, represents the mesh element size (of the undeformed mesh), that is, the length of the longest edge of the element." So in a first guess, I could assume that the mesh element is a cube of length h, and its volume is h^3. But this is of course not accurate. Is there a way to obtain the exact mesh element volume? For example, let's assume that we have a domain with constant density. I would like to know the mass of each single mesh element. For this I need to know the volume of each single mesh element, such that I can multiply it with the density. Comsol support answer #1: You can use the variable "dvol" to determine the volume of the mesh elements. However, for non-block elements you need to multiply dvol with the following factors to get the correct volume. Triangle : 1/2 Tetrahedron : 1/6 Prism : 1/2 Pyramid : 1/3 My email #2: Thanks a lot for your help. Just to be sure that I understand you well: by block elements, you mean quad and hex? Is there a variable that describes the element type, e.g. var=1 for prism, var=2 for tetrahedron, var=3 for pyramid, etc? Comsol support answer #2: Yes. Yes, you can use the variable "meshtype", which is equal to the number of element edges for each mesh element type, for example, 9 for prism and 6 for tetrahedron. My email #3: What I want to do does not work unfortunately. I drew a cylinder (radius r and height h) in Comsol, generated a mesh, and solved for a simple laminar flow through the cylinder. I then extracted the information for dvol and meshtype to two different text files. I then loaded the two files in Matlab, and ran a for loop over all the elements, checking which type they are, and correcting the volume accordingly (Tetrahedron : 1/6, Prism : 1/2, etc.). Finally I sumed up all the single corrected volumes to obtain the total volume of the mesh. I ended up with a value which is completely wrong compared to the theoretical volume of the cylinder obtained by pi*r^2*h. What is strange is that dvol and meshtype are given for each mesh point. How can a mesh point give any information about volume and element type? There are points which belong to tetrahedrons and prisms at the same time. Nevertheless, they will either indicate tetrahedron or prism. Furthermore, what is the meaning of dvol for a mesh element? The volume of a point??? Thanks for clarifying this issue. Comsol support answer #3: When you export solution data to file you can specify the evaluation points for the export in the Advanced section. If you use the default settings you typically get several evaluation points for each element. This might be the reason for the incorrect value of the total volume resulting from your MATLAB script. In this case you only want one evaluation point per element. To achieve this choose Gauss points in the Evaluate in list (and use Gauss point order 1).

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Dec 2, 2011, 5:57 AM EST
Hi

from my understanding "dvol" is a mesh element scale factor (without units), not truly the volume of the element.

-----------
Good luck
Ivar
Hi from my understanding "dvol" is a mesh element scale factor (without units), not truly the volume of the element. ----------- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Dec 2, 2011, 9:44 AM EST
Hi,

when multypling dvol with the corresponding correction factor (Triangle : 1/2; Tetrahedron : 1/6; Prism : 1/2; Pyramid : 1/3) and summing up the result over an entire domain (using the evaluation with Gauss points as described just above), you end up with the correct volume of this domain. So this variable represents a physical quantity, even if it is not obvious.

Alois
Hi, when multypling dvol with the corresponding correction factor (Triangle : 1/2; Tetrahedron : 1/6; Prism : 1/2; Pyramid : 1/3) and summing up the result over an entire domain (using the evaluation with Gauss points as described just above), you end up with the correct volume of this domain. So this variable represents a physical quantity, even if it is not obvious. Alois

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Dec 2, 2011, 4:09 PM EST
Hi

then I'm not sure how to use it within the GUI as the "summation over a domain" is over the nodes and not the elements from my understanding (integration of 1 = volume, summation is a number > number of elements)

while the GUI summation of dvol/average(meshtype) is far greater and the integration much smaller than the actual volume

--
Good luck
Ivar
Hi then I'm not sure how to use it within the GUI as the "summation over a domain" is over the nodes and not the elements from my understanding (integration of 1 = volume, summation is a number > number of elements) while the GUI summation of dvol/average(meshtype) is far greater and the integration much smaller than the actual volume -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Dec 3, 2011, 2:34 PM EST
Hi,

I did not use it in the GUI, but I extracted the data (using Gauss evaluation of order 1) and then computed the summation in MATLAB. It might not work in the GUI,

Alois
Hi, I did not use it in the GUI, but I extracted the data (using Gauss evaluation of order 1) and then computed the summation in MATLAB. It might not work in the GUI, Alois

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Dec 3, 2011, 3:51 PM EST
Hi

Indeed it needs some further investigations ;)

--
Good luck
Ivar
Hi Indeed it needs some further investigations ;) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Feb 3, 2012, 10:06 AM EST
Please help :

I need to know the mesh element size in the 'extremely coarse' mesh and may also need to know the element sizes in the other mesh types such as 'normal', 'fine' etc. Is there any way I can know this?
Also, if I want to define my mesh element size, then are the numbers input into 'maximum element size' in the free mesh parameters in units of cm/mm?
Please help : I need to know the mesh element size in the 'extremely coarse' mesh and may also need to know the element sizes in the other mesh types such as 'normal', 'fine' etc. Is there any way I can know this? Also, if I want to define my mesh element size, then are the numbers input into 'maximum element size' in the free mesh parameters in units of cm/mm?

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Feb 3, 2012, 11:11 AM EST
Hi

In V4 by default its Si units hence [m], except if you change the base unit system of your model (top node). You can change the default geoemtry units from [m] to [mm] or whatever, this remains limited to the geometry representation, the physics remain in default [m] the mesh normally follos the geoemtryx units, but there you have the m or mm appearing to the right of the max/min sizes

Mostly the units are mentioned in the GUI (still a few exceptions were its missing)

I believe in V3 the default was [m] (or the main pysics based units) for all not sure any longer

--
Good luck
Ivar
Hi In V4 by default its Si units hence [m], except if you change the base unit system of your model (top node). You can change the default geoemtry units from [m] to [mm] or whatever, this remains limited to the geometry representation, the physics remain in default [m] the mesh normally follos the geoemtryx units, but there you have the m or mm appearing to the right of the max/min sizes Mostly the units are mentioned in the GUI (still a few exceptions were its missing) I believe in V3 the default was [m] (or the main pysics based units) for all not sure any longer -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Apr 9, 2013, 2:22 AM EDT
Hi,

I amtrying to find the volume of a geometry, or rather, the part of it where S < 0. So I figured that I could define an integration operator that integrates over the desired domain (this part works as I use it for other purposes), and evaluate something like:

intop1((S<0)*dvol*<some magic based on meshinfo>)

But I cannot find enough info in this thread to solve this puzzle. I'm using the GUI, so java/matlab solutions is not what I want to use.

Anybody?

Thanks,
Fred-Johan
Hi, I amtrying to find the volume of a geometry, or rather, the part of it where S < 0. So I figured that I could define an integration operator that integrates over the desired domain (this part works as I use it for other purposes), and evaluate something like: intop1((S

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Apr 9, 2013, 2:32 PM EDT
Hi

in comsol when you integrate the dx*dy*dz is implicit, and controlled by COMSOL so there is no reason to use twice dvol, its implicit there, if you want the volume of a domain, you integrate over the domain the argument "1", so if you use a boolean operator i.e (S<0) and integrate that over the domain, you will get the total volume where the condition is "1". It's as simple as that ;)

Note COMSOL has many implicit notations, these are quite common to miss, it took me quite some time to really understand the double game of scalar variables, fields, implicit summation and integration over entities ...

--
Good luck
Ivar
Hi in comsol when you integrate the dx*dy*dz is implicit, and controlled by COMSOL so there is no reason to use twice dvol, its implicit there, if you want the volume of a domain, you integrate over the domain the argument "1", so if you use a boolean operator i.e (S

Please login with a confirmed email address before reporting spam

Posted: 6 years ago May 23, 2014, 10:58 AM EDT
what kind of data or information do you extract from comsol and further process in matlab? There are just x- and y-coordinates, element size for the mesh element. How do you figure out the element area? thanks
what kind of data or information do you extract from comsol and further process in matlab? There are just x- and y-coordinates, element size for the mesh element. How do you figure out the element area? thanks

Please login with a confirmed email address before reporting spam

Posted: 6 years ago May 23, 2014, 11:20 AM EDT
I extracted two quantities:
- dvol (for a set of coordinates x,y z)
- meshtype (for a set of coordinates x,y,z)

To obtain the volume of a mesh element (in Matlab), I multiply "dvol" at coordinate (x,y,z) by the appropriate factor depending on the value of "meshtype" at that same coordinate.

"meshtype" is equal to the number of element edges for each mesh element type, for example, 9 for prism and 6 for tetrahedron.

The factors are:
Triangle : 1/2
Tetrahedron : 1/6
Prism: 1/2
Pyramid : 1/3
I extracted two quantities: - dvol (for a set of coordinates x,y z) - meshtype (for a set of coordinates x,y,z) To obtain the volume of a mesh element (in Matlab), I multiply "dvol" at coordinate (x,y,z) by the appropriate factor depending on the value of "meshtype" at that same coordinate. "meshtype" is equal to the number of element edges for each mesh element type, for example, 9 for prism and 6 for tetrahedron. The factors are: Triangle : 1/2 Tetrahedron : 1/6 Prism: 1/2 Pyramid : 1/3

Please login with a confirmed email address before reporting spam

Posted: 6 years ago Jun 26, 2014, 7:41 AM EDT
Just wanted to say Thanks for the solution Alois! Struggled a bit with this, while trying to find the magnetic energy of nonlinear steel by integrating over the saturation in matlab.

My 2 cents: The following lines in matlab computes the volume from two imported arrays meshtype and dvol as discussed above (tested to yield the same value as integrating over 1 in comsol):

meshtype(meshtype==3) = 1/2;
meshtype(meshtype==4) = 1/3;
meshtype(meshtype==6) = 1/6;
meshtype(meshtype==9) = 1/2;
volume = meshtype.*dvol;

BR
Magnus
Just wanted to say Thanks for the solution Alois! Struggled a bit with this, while trying to find the magnetic energy of nonlinear steel by integrating over the saturation in matlab. My 2 cents: The following lines in matlab computes the volume from two imported arrays meshtype and dvol as discussed above (tested to yield the same value as integrating over 1 in comsol): meshtype(meshtype==3) = 1/2; meshtype(meshtype==4) = 1/3; meshtype(meshtype==6) = 1/6; meshtype(meshtype==9) = 1/2; volume = meshtype.*dvol; BR Magnus

Please login with a confirmed email address before reporting spam

Posted: 4 years ago Feb 5, 2016, 6:13 AM EST
thanks. I have the exact same in mind, in python though ;)
For the comsol guys; I do not understand why it is so difficult to combine the current output of some package as an input for the magnetic field package. That's why we have to make this detour ...
thanks. I have the exact same in mind, in python though ;) For the comsol guys; I do not understand why it is so difficult to combine the current output of some package as an input for the magnetic field package. That's why we have to make this detour ...

Please login with a confirmed email address before reporting spam

Posted: 4 years ago Feb 9, 2016, 11:57 AM EST
... for some unknown reason there is no mesh-type node in my export table?!
workaround:
if I do ...
Results>3dplotGroup>mesh
DataSet: Mesh
I can see, with for example Volume, the Element-Type. For all but Tetrahedron the plot is empty : So I know that my factor is always 1/6.
... for some unknown reason there is no mesh-type node in my export table?! workaround: if I do ... Results>3dplotGroup>mesh DataSet: Mesh I can see, with for example Volume, the Element-Type. For all but Tetrahedron the plot is empty : So I know that my factor is always 1/6.

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.