- edited description
deterministic mesh creation
I would expect the meshes, created in the following script, to always be identical and therefore contain the same number of cells
import dolfin
import mshr
resolution = 20
c = mshr.Sphere(dolfin.Point(0, 0, 0), 0.9)
cm1 = mshr.generate_mesh(c, resolution)
cm2 = mshr.generate_mesh(c, resolution)
print('#cells1 %s' % cm1.num_cells())
print('#cells2 %s' % cm2.num_cells())
Is it possible to set the seed used in mshr somehow?
Comments (6)
-
reporter -
The reason that the generated meshes differ is CGAL's mesh generator which uses random rays for generating points on the surface of the domain in the initial phase of the surface remeshing). I agree that the randomness is unfortunate, but I'm a bit reluctant to fixing the seed as the default choice, but I'll see if we can make this option available through the parameter system.
-
reporter I tried to hardcode the seed in
MeshGenerator.cpp
but I still don't get the same number of cells incm1
andcm2
. Here is my patch--- a/src/MeshGenerator.cpp +++ b/src/MeshGenerator.cpp @@ -20,6 +20,8 @@ #include <mshr/CSGCGALMeshGenerator2D.h> #include <mshr/CSGCGALMeshGenerator3D.h> #include <mshr/TetgenMeshGenerator3D.h> +#include <CGAL/Random.h> + #include <dolfin/log/log.h> #include <dolfin/mesh/BoundaryMesh.h> @@ -37,6 +39,7 @@ void generate(dolfin::Mesh& mesh, if (geometry.dim() == 2) { CSGCGALMeshGenerator2D generator; + CGAL::default_random = CGAL::Random(0); generator.parameters["mesh_resolution"] = resolution; generator.generate(geometry, mesh); } @@ -45,6 +48,7 @@ void generate(dolfin::Mesh& mesh, if (backend == "cgal") { CSGCGALMeshGenerator3D generator; + CGAL::default_random = CGAL::Random(0); generator.parameters["mesh_resolution"] = resolution; generator.generate(geometry, mesh); }
-
reporter Yes, it would be nice if the seed could be set through the parameter system.
-
Ok, strange... I'll take a look.
-
reporter Thx
- Log in to comment