[Gmsh] Variable Not Updating In For Loop

Christophe Geuzaine cgeuzaine at ulg.ac.be
Sat Jul 8 13:20:32 CEST 2017

> On 8 Jul 2017, at 03:26, Jeremias Gonzalez <jgonzalez49 at ucmerced.edu> wrote:
> Hi, below (and attached) is a simple script where, in a for loop, I make a mesh for a cube, output the mesh, then start over and make the mesh again with a changed number. For some reason, as can be seen from the printed line in each iteration of the loop, the variable instantiated by the for loop is changing as expected, but the parameter I made that sets the variable as its own value is stuck at the original value. Even stranger, just to be sure that the parameter is getting refreshed each time since it wasn't overwriting like I expected, at the beginning of the for loop I tried deleting the parameter, then allow it to be declared anew with the current for loop variable, but it remains stuck with the value it received from the first value from the for loop. Can anyone explain where things are going wrong?

cubelength = DefineNumber[ newcubelength, Name "Parameters/cubelength" ];

will assign the default value newcubelength to cubelength if the ONELAB parameter "Parameters/cubelength" does not exist. If "Parameters/cubelength" exists in the ONELAB database, it will use that value.

This is the mechanism that allows you to modifiy the value associated to "Parameters/cubelength" externally (in the GUI, in other ONELAB clients), and have Gmsh use the updated value later.

If the script must have precedence over other clients, i.e. if the script should always assign the value of the ONELAB parameter, you can mark the parameter as "ReadOnly" :

cubelength = DefineNumber[ newcubelength, Name "Parameters/cubelength", ReadOnly];

> Is there a better way to do a parametric sweep and output of meshes?
> SetFactory("OpenCASCADE");
> For newcubelength In {0.1:0.25:0.05}
> Delete cubelength;
> cubelength = DefineNumber[ newcubelength, Name "Parameters/cubelength" ];
> Block(1) = {0, 0, 0, cubelength, cubelength, cubelength};
> Physical Volume("cubebody", 1) = {1};
> Mesh.SaveElementTagType=2;
> Mesh.Format=30;
> Mesh 3;
> Save Sprintf("cube%g.mesh",cubelength);
> Printf("%g,%g",cubelength,newcubelength);
> Delete Model;
> Delete Physicals;
> EndFor
> <cubeparametric.geo>_______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science 

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

More information about the gmsh mailing list