[Gmsh] Setting random seed in geo file

Serban Georgescu Serban.Georgescu at uk.fujitsu.com
Fri Dec 5 13:39:40 CET 2014


Actually I had the same problem and in the last few days I put some time into finding the reason why this happens.
The random seeds are actually hard-coded, the reason for the lack of reproducibility comes from a few STL containers that store pointers and were left with the default ordering - which means that the order will be dependent on the pointer addresses - hence the lack of reproducibility.

Here are the modifications that you need to make in order to have full reproducibility:
Note that these are made with respect to the source code of Gmsh 2.8.5.

Mesh/meshGFace.cpp --> added ordering to the set

<   std::set<MVertex*, MVertexLessThanLexicographic> all_vertices, boundary;
>   std::set<MVertex*> all_vertices, boundary;

<     for(std::set<MVertex*, MVertexLessThanLexicographic>::iterator it = all_vertices.begin();
>     for(std::set<MVertex*>::iterator it = all_vertices.begin();

<   for(std::set<MVertex*, MVertexLessThanLexicographic>::iterator it = all_vertices.begin();
>   for(std::set<MVertex*>::iterator it = all_vertices.begin();

Mesh/meshGFaceBDS.cpp --> defined what happens when we have two identical values in the sort

< bool edges_sort (std::pair<double, BDS_Edge*> a , std::pair<double, BDS_Edge*> b)
< {
<             if (a.first == b.first)
<                             return ((*a.second) < (*b.second));
<             else
<                             return (a.first < b.first);
< }
<   std::sort(edges.begin(), edges.end(), edges_sort);
>   std::sort(edges.begin(), edges.end());
<   std::sort(edges.begin(), edges.end(), edges_sort);
>   std::sort(edges.begin(), edges.end());

Mesh/meshGRegion.cpp --> added ordering to the set
< static void getAllBoundingVertices(GRegion *gr, std::set<MVertex*, MVertexLessThanLexicographic> &allBoundingVertices)
> static void getAllBoundingVertices(GRegion *gr, std::set<MVertex*> &allBoundingVertices)
<   std::set<MVertex*, MVertexLessThanLexicographic> allBoundingVertices;
>   std::set<MVertex*> allBoundingVertices;
<   std::set<MVertex*, MVertexLessThanLexicographic>::iterator itv = allBoundingVertices.begin();
>   std::set<MVertex*>::iterator itv = allBoundingVertices.begin();
< struct GFaceOrderedByTag
< {
<             bool operator() (const GFace* first, const GFace* second) const
<             {
<                             return (first->tag() < second->tag());
<             }
< };
<     std::set<GFace*, GFaceOrderedByTag> mySet;
>     std::set<GFace*> mySet;


That's about it.
It would be nice if these modifications could be added to the SVN version.


From: gmsh [mailto:gmsh-bounces at ace20.montefiore.ulg.ac.be] On Behalf Of David Bernstein
Sent: 02 November 2014 00:45
To: gmsh at geuz.org Geuzaine
Subject: [Gmsh] Setting random seed in geo file

Sorry, I missed this post back in May.  What is the geo file command to set the global random number seed?



This issue has been fixed in the last versions. What is the version you are using ?


Le 22 mai 2014 à 23:29, David Bernstein <david at terafrac.org<http://www.geuz.org/mailman/listinfo/gmsh>> a écrit :

> Hi Everyone, I'm using Gmsh as a backend mesh generator in a project and it's been working very well so far.  One issue that we've encountered is reproducing a problem from a given set of simulation input parameters because Gmsh produces a different mesh every time it's run with the same input.


> I've looked through the documentation and have not been able to find a way to set a random number seed so that the same mesh is produced every time for a given input .geo file.  If anyone knows a way to do this please let me know.


> Thanks,

> Dave

This e-mail is covered by the Electronic Communication Privacy Act, 18 U.S.C. Section 2510-2521 and may be legally privileged. If you have received this transmission in error, please notify the original sender immediately by return e-mail or by telephone at the telephone number provided above and delete/trash the original message from your system. Thank you for your assistance. The information contained herein is confidential information provided only for the use of the individual or entity for whom it was intended. If the reader of this message received it in error, is not the intended recipient, or if an attachment is made in error, the reader is hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.

 Fujitsu Laboratories of Europe Limited
 Hayes Park Central, Hayes End Road, Hayes, Middlesex, UB4 8FE
 Registered No. 4153469
 This e-mail and any attachments are for the sole use of addressee(s) and
 may contain information which is privileged and confidential. Unauthorised
 use or copying for disclosure is strictly prohibited. The fact that this
 e-mail has been scanned by Trendmicro Interscan does not guarantee that 
 it has not been intercepted or amended nor that it is virus-free.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20141205/7d48b23f/attachment.html>