CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Unequal Mesh Volumes in Cells of the Same Size? (mesh.V())

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By adhiraj
  • 1 Post By Santiago

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 8, 2020, 15:50
Default Unequal Mesh Volumes in Cells of the Same Size? (mesh.V())
  #1
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 19
Rep Power: 5
MCrossover97 is on a distinguished road
Hey everybody, I came across a strange case.

I generated a mesh with blockMesh in which all cells are the same size:
Code:
convertToMeters 0.000508;

vertices
(
    (0 0 0)
    (100 0 0)
    (100 40 0)
    (0 40 0)
    (0 0 40)
    (100 0 40)
    (100 40 40)
    (0 40 40)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (100 1 1) simpleGrading (1 1 1)
);
Then I compared the volumes of two random cells:
Code:
	if (mesh.V()[0] == mesh.V()[2]){
		std :: cout <<"Yes"<< std::endl;
	}else{
		std :: cout <<"No"<< std::endl;
	}
	
	std :: cout <<mesh.V()[0] - mesh.V()[2]<< std::endl;
And this is the result:
Code:
No
2.64698e-23
But when I compare the volumes of mesh(0) and mesh(1), I get a different answer:
Code:
Yes
0
How is this possible?
MCrossover97 is offline   Reply With Quote

Old   November 8, 2020, 21:28
Default
  #2
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
The difference is 2.64698 \times 10^{-23}, which is very small.

I think you should not be comparing floating point umbers directly, as you have here:
Code:
if (mesh.V()[0] == mesh.V()[2])
{
    std :: cout <<"Yes"<< std::endl;
}
You are better off trying to see if the absolute difference between them is smaller than some \epsilon, such as 1 \times 10^{-15}.
MCrossover97 likes this.
adhiraj is offline   Reply With Quote

Old   November 9, 2020, 13:38
Default
  #3
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 19
Rep Power: 5
MCrossover97 is on a distinguished road
Thank you for your answer! Do you know why some are exactly equal, but some are slightly different?
MCrossover97 is offline   Reply With Quote

Old   November 9, 2020, 16:45
Default
  #4
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 15
Santiago is on a distinguished road
Quote:
Originally Posted by MCrossover97 View Post
Thank you for your answer! Do you know why some are exactly equal, but some are slightly different?
Because you are working with discrete mathematics here: 1 + 1 = 2 is a mathematical abstraction, for a computer 1 + 1 ~ 2, which implies moving bytes around
MCrossover97 likes this.
Santiago is offline   Reply With Quote

Reply

Tags
blockmesh


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[mesh manipulation] How to write cellSet for different regions in constant/polyMesh/sets Struggle_Achieve OpenFOAM Meshing & Mesh Conversion 3 June 17, 2019 09:29
[snappyHexMesh] Number of cells in mesh don't match with size of cellLevel colinB OpenFOAM Meshing & Mesh Conversion 14 December 12, 2018 08:07
[snappyHexMesh] sHM layer process keeps getting killed MBttR OpenFOAM Meshing & Mesh Conversion 4 August 15, 2016 03:21
OF 1.6 | Ubuntu 9.10 (64bit) | GLIBCXX_3.4.11 not found piprus OpenFOAM Installation 22 February 25, 2010 13:43
Problems in compiling paraview in Suse 10.3 platform chiven OpenFOAM Installation 3 December 1, 2009 07:21


All times are GMT -4. The time now is 19:29.