[Gmsh] How do I set the random number seed with a "Mesh.Seed" option for deterministic mesh generation?

Christophe Geuzaine cgeuzaine at uliege.be
Sat Oct 27 09:56:47 CEST 2018



> On 27 Oct 2018, at 00:16, Max Orok <morok at mevex.com> wrote:
> 
> Hi Thomas, 
> 
> I first tried to set the random factors using: 
> Mesh.RandomFactor = 1e-9;
> Mesh.RandomFactor3D = 1e-9;
> 
> I think the bug is elsewhere however...
> With your file, I get a warning the first time and none the subsequent times.
> I think it is due to internal state with the mesher remembering the choice of MeshAdapt?

Yes : when meshing fails with Delaunay or Frontal we currently force MeshAdapt on that surface. Currently this choice is persistent (in a Gmsh run) - I will change this so that the initial state is restored.


> Switching from Delauney to MeshAdapt halfway might cause different point spacing etc. 
> 
> Here are some pictures showing the two consecutive mesh logs 
> 
> 1st time: 
> <image.png>
> 
> 2nd time (same window): 
> <image.png>
> 
> On closing Gmsh and trying again, this repeats.
> 
> Instead, to fix your problem, you can set the meshing algo to MeshAdapt ahead of time by changing the line here: 
> Mesh.Algorithm = 1; // changed to MeshAdapt
> 
> Three repeated trials gave identical output files. 
> 
> p.s. just in case, all of the current / modified options can be looked through and searched using Ctrl-Shift-H or Help -> Current Options and Workspace
> 
> Sincerely, 
> Max
> 
> On Fri, Oct 26, 2018 at 12:44 PM, Thomas Kiel <Thomas.Kiel at physik.hu-berlin.de> wrote:
> Dear Gmshers,
> 
> as I already pointed out in an earlier email (s. http://onelab.info/pipermail/gmsh/2018/012045.html), I had problems with reproducing the exact same mesh twice. Since this email was unfortunately html encoded I think it was overlooked. Yet I like to apologize to ask again, this time in text formatted email, how to set the random number generator seed with an outside option?
> 
> I know, that a grep to "srand" within the gmsh git repository gives several times hard-coded initialized seeds, e.g.
> 
> Geo/SOrientedBoundingBox.cpp:326:  srand((unsigned)time(0));
> Mesh/Levy3D.cpp:624:  srand(time(NULL));
> Mesh/Levy3D.cpp:1359:    srand(time(NULL));
> Mesh/meshGFaceRecombine.cpp:245:  srand(time(NULL));
> Mesh/meshGFaceLloyd.cpp:394:  srand(time(NULL));
> 
> yet I am not sure whether these influence my mesh generation. A minimalistic test file which causes different meshes at consecutive runs in my case, is
> 
> 
> //+
> SetFactory("OpenCASCADE");
> 
> Mesh.CharacteristicLengthMin = 0.001;
> Mesh.CharacteristicLengthMax = 2.0;
> 
> Mesh.CharacteristicLengthExtendFromBoundary = 1;
> 
> Mesh.Algorithm = 5;
> Mesh.Smoothing = 3;
> Mesh.Algorithm3D = 1;
> 
> Box(1) = {0, -0.5, -0.5, 1, 1, 1};
> Box(2) = {-1, -0.5, -0.5, 1, 1, 1};
> Sphere(3) = {0.5, 0.0, 0.0, 0.3, -Pi/2, Pi/2, 2*Pi};
> 
> Coherence;
> 
> surfs_box1() = Unique(Abs(Boundary{ Volume{4}; } ));
> lines_box1() = Unique(Abs(Boundary{ Surface{surfs_box1()}; } ));
> pts_box1() = Unique(Abs(Boundary{ Line{lines_box1()}; } ));
> 
> surfs_sphere() = Unique(Abs(Boundary{ Volume{3}; } ));
> lines_sphere() = Unique(Abs(Boundary{ Surface{surfs_sphere()}; } ));
> pts_sphere() = Unique(Abs(Boundary{ Line{lines_sphere()}; } ));
> 
> surfs_box2() = Unique(Abs(Boundary{ Volume{2}; } ));
> lines_box2() = Unique(Abs(Boundary{ Surface{surfs_box2()}; } ));
> pts_box2() = Unique(Abs(Boundary{ Line{lines_box2()}; } ));
> 
> // sorted from largest to smallest:
> Characteristic Length{pts_box2()} = 0.5;
> Characteristic Length{pts_sphere()} = 0.2;
> Characteristic Length{pts_box1()} = 0.1;
> 
> 
> 
> I tested this on a machine running Ubuntu 16.04 and installed the out-of-the-box gmsh 4.0.4 version from the webpage. If any further detail on the running machine is required please tell me.
> I hope you can help me out.
> 
> Thanks a lot in advance and best regards,
> 
> Thomas Kiel
> 
> -- 
> Thomas Kiel
> Theoretische Optik und Photonik
> 
> Humboldt-Universität zu Berlin, Institut für Physik
> Newtonstraße 15, 12489 Berlin
> 
> Tel.:   +49 30 2093 7999
> E-Mail: thomas.kiel at physik.hu-berlin.de
> Web:    https://top.physik.hu-berlin.de/people/thomas-kiel
> 
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh
> 
> 
> 
> -- 
> Max Orok
> Contractor
> www.mevex.com
> 
> 
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

— 
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science 
http://www.montefiore.ulg.ac.be/~geuzaine

Free software: http://gmsh.info | http://getdp.info | http://onelab.info




More information about the gmsh mailing list