[Gmsh] Variable Not Updating In For Loop
Jeremias Gonzalez
jgonzalez49 at ucmerced.edu
Sat Jul 8 03:26:15 CEST 2017
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? 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
-------------- next part --------------
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
More information about the gmsh
mailing list