[Gmsh] Question

Bernhard Kubicek bernhard.kubicek at arsenal.ac.at
Thu Aug 9 10:12:01 CEST 2007


Hi!
If you are running linux or don't fear to use cygwin in windows, you can
do a lot of magic in the command line. As a demo the magic trick is to
do a 2d parameter variation complete with some info messages. 

You could create several files:
A parameter file where LARGE characters are to be replaced by variated
values:
--"parameters.ori"--
length=LENGTH;
width=WIDTH;
msh=length/10.;
-------------------

a simple geo file, in this case a 2d rectangle, that includes a file
that with the filled parameters
--your.geo--
Include "current.par";

Point(0)={0,0,0,msh};
Point(1)={length,0,0,msh};
Point(2)={length,width,0,msh};
Point(3)={0,width,0,msh};

Line(1)={0,1};
Line(2)={1,2};
Line(3)={2,3};
Line(4)={3,0};

Line Loop(5) = {2,3,4,1};
Plane Surface(6) = {5};
Physical Surface(7) = {6};
-------------

and a script file:
---variate.bash---
#!/bin/bash

function test {
	echo "Preparing"
	#print parameters ori, and replace the string LENGTH by first fuction
parameter, 
	#WITH by the second,... and finally write the result to the file
"current.par"
	cat "parameters.ori" |sed s/LENGTH/$1/g |sed s/WIDTH/$2/g |sed
s/WHATEVER/$3/> current.par
	echo "Meshing"
	# &> throws all output into log.txt, e.g. error messages
	gmsh2 -2 your.geo &> log.txt

	Nodes=`head -n 5 your.msh |tail -n 1 `
	
	#output possible errors
	cat log.txt |grep Error
	
	echo "Calculating with Mesh having $Nodes Nodes."
	#execute your calculation between here:
	#touch just creates an empty file for demo purposes
	touch result.pos
	#and here
	
	#now save postprocessing data so its not overwritten
	mv result.pos resultA${i1}B${i2}.pos
}


#echo "This is an sample output to the shell that is not printed because
its commented out"
echo "I variate parameters.."
#seq -f miminum increment maximum
LISTA=`seq -f %f 0.1 0.1 1`
LISTB=`seq -f %f 0.1 0.5 1`
echo "Parameters are evaluated at:"
echo "1: " $LISTA
echo "2: " $LISTB

for i1 in $LISTB ;
do
	for i2 in $LISTA ;
	do
		echo "Current: $i1 $i2 "
		test $i1 $i2
	done
done
----------------


In this script, two lsts of parameters are created that are than used in
for loops. For each pair, a mesh is created and so on...
To make this script executeable, you have to "chmod a+x variate.bash"
it, and then call it via "./variate.bash". 
This should equally work in Windows in the Cygwin shell.
The result files need to be renamed of course, as they would be
overwritten otherwise.

If this is not difficult, you could e.g. create the filled parameter
file using matlab, Mathematica or Visual Basic ( please don't do that ).
But Bash is very nice and modular, and it's addictive. Especially, if
you like little brain teasers in the mornings, before heaving the first
coffee.

Very nice greetings,
 Bernhard, needing coffee :)


PS: If you want to take a further step, you can easily adopt the
bash-function "test" to be used with DAKOTA (sandia national labs),
which is able to perform random parameter evaluation, and as it's core
element, offers parallelized numerical optimization.


On Thu, 2007-08-09 at 08:37 +0200, David Colignon wrote:
> Hi Cynthia,
> 
> your script should first generate a simple text file ( test.par for example ) with the geometrical parameters, like
> 
> h1 = 1. ;
> w1 = 5. ;
> ...
> 
> then you include this parameters file at the beginning of your main test.geo file:
> 
> Include "test.par";
> Point(1) = {0, 0, 0, lc};
> Point(2) = {0, h1, 0, lc};
> Point(3) = {w1, 0, 0, lc};
> 
> and finally your script issue the meshing command:
> 
> gmsh test.geo -2
> 
> Cheers,
> 
> Dave
>