Mesh generation with specific mesh size

Asked by corrado maurini on 2013-01-30

I try to generate a mesh with a specific mesh size using the new CSG features.

I followed the indication given on the doc page

http://fenicsproject.org/documentation/dolfin/dev/python/programmers-reference/cpp/mesh/Mesh.html#dolfin.cpp.mesh.Mesh

but I get the following error:

TypeError: __init__() got an unexpected keyword argument 'meshsize'

Below the code to reproduce the issue

## BEGIN ###
from dolfin import *
geom=Rectangle(0,0,1,2)
mesh = Mesh(geometry, meshsize="fine")
## END ###

If I use a integer as a parameter (as one should do looking at Mesh.ccp), Mesh accepts it, but it seems to do not affect the mesh resolution. For example

mesh = Mesh(geometry, 10)

gives the same result as

mesh = Mesh(geometry, 1)

How the integer parameter is expected to control the resolution?

Is there a way to generate a unstructured mesh with given mesh size within dolfin?

I use the development version of FEniCS

P.S.: I currently use an external mesh generator, but the feature may be useful for test problems

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
corrado maurini
Solved:
2013-01-31
Last query:
2013-01-31
Last reply:
2013-01-30
Anders Logg (logg) said : #1

On Wed, Jan 30, 2013 at 10:25:54AM -0000, corrado maurini wrote:
> New question #220533 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/220533
>
> I try to generate a mesh with a specific mesh size using the new CSG features.
>
> I followed the indication given on the doc page
>
> http://fenicsproject.org/documentation/dolfin/dev/python/programmers-reference/cpp/mesh/Mesh.html#dolfin.cpp.mesh.Mesh
>
> but I get the following error:
>
> TypeError: __init__() got an unexpected keyword argument 'meshsize'
>
> Below the code to reproduce the issue
>
> ## BEGIN ###
> from dolfin import *
> geom=Rectangle(0,0,1,2)
> mesh = Mesh(geometry, meshsize="fine")
> ## END ###
>
> If I use a integer as a parameter (as one should do looking at Mesh.ccp), Mesh accepts it, but it seems to do not affect the mesh resolution. For example
>
> mesh = Mesh(geometry, 10)
>
> gives the same result as
>
> mesh = Mesh(geometry, 1)
>
> How the integer parameter is expected to control the resolution?
>
> Is there a way to generate a unstructured mesh with given mesh size within dolfin?
>
> I use the development version of FEniCS
>
> P.S.: I currently use an external mesh generator, but the feature may be useful for test problems

Last I heard the resolution option was not implemented in 2D, only 3D.

Perhaps Benjamin or Johannes could give an updated on this?

--
Anders

Johannes Ring (johannr) said : #2

Yes, the int parameter is not implemented in 2D and the keyword argument 'meshsize' does not work in either 2D or 3D.

Thanks for the information!

Johannes Ring (johannr) said : #4

Note that you can use the 'cell_size' parameter in CSGCGALMeshGenerator2D to change the resolution of the mesh in 2D. I'm not sure if this is documented anywhere, but something like this should work:

from dolfin import *
geom = Rectangle(0,0,1,2)
mesh = Mesh(geom, 1)
gen = CSGCGALMeshGenerator2D(geom)
gen.parameters["cell_size"] = 0.05
gen.generate(mesh)

very nice, it works, thanks!

 11:41, Johannes Ring a √©crit :

> from dolfin import *
> geom = Rectangle(0,0,1,2)
> mesh = Mesh(geom, 1)
> gen = CSGCGALMeshGenerator2D(geom)
> gen.parameters["cell_size"] = 0.05
> gen.generate(mesh)