Local mesh diameter

More
6 years 5 months ago #535 by hvwahl
Local mesh diameter was created by hvwahl
Hi,

I want to compute the actual maxh of a given mesh after it is built. My idea was to iterate through the mesh and call specialcf.mesh_size.Norm(). Something along these lines:
Code:
from netgen.geom2d import unit_square mesh = unit_square.GenerateMesh(maxh=h_max) from ngsolve import * for e in mesh.Elements2D(): print(specialcf.mesh_size)

This does not give me the desired result. I'd appreciate any help :)

Best wishes,
Henry
More
6 years 5 months ago #536 by cwinters
Replied by cwinters on topic Local mesh diameter
Hi,

the function "specialcf.mesh_size" is a CoefficientFunction. Therefore it needs an integration point to evaluate the mesh size. If you have an NGSolve mesh can call "mesh(x,y)" to get an integration point with the coordinates x,y.

But I would suggest an easier solution:
Code:
from netgen.geom2d import unit_square h_max = 0.2 ngmesh = unit_square.GenerateMesh(maxh=h_max) from ngsolve import * mesh = Mesh(ngmesh) elvol = Integrate(CoefficientFunction(1),mesh,element_wise=True) h = [(2*vol)**(1/2) for vol in elvol] print(min(h),max(h))
In the first step you calculate the volume of each element. Knowing that the volume of a simplex is connected to the Jacobian determinant (which scales h^dim) you get an estimate for the mesh size.

Best,
Christoph
The following user(s) said Thank You: hvwahl
More
6 years 5 months ago #537 by hvwahl
Replied by hvwahl on topic Local mesh diameter
Hi Christoph,

tank you for your help! Your easier solution, has worked well. For 3d I can similarly use
Code:
h = [(3*vol)**(1/3) for vol in elvol]
or have I messed something up in the constant?

Best wishes,
henry
More
6 years 5 months ago #538 by cwinters
Replied by cwinters on topic Local mesh diameter
Hi,

for 3d it should be
Code:
h = [(6*vol)**(1/3) for vol in elvol]

Here you can find the volume of a simplex . The constant is actually the factorial of the spatial dimension.

Best
Christoph
More
6 years 5 months ago #539 by hvwahl
Replied by hvwahl on topic Local mesh diameter
Hi Christoph,

thanks! Strangely however, using the constant = 6, consistently gives me a max(h) which is larger than the h_max I used to mesh a cube (of side length 2) by a factor of 21/3 (i.e., constant =3). Do you have any idea why this would be the case?

Best wishes,
Henry
More
6 years 5 months ago #540 by cwinters
Replied by cwinters on topic Local mesh diameter
Hi Henry,

the maxh argument in GenerateMesh is not a strict upper bound.
Therefore the elements might be slightly larger than the defined maxh.

Best,
Christoph
Time to create page: 0.107 seconds