| 1 |
#!/usr/local/bin/perl |
| 2 |
# ----- clean --- |
| 3 |
unlink <*.mesh>; |
| 4 |
unlink <*.am_fmt>; |
| 5 |
unlink <*.mtr>; |
| 6 |
unlink <*.bb>; |
| 7 |
unlink <*.BB>; |
| 8 |
unlink <YG_trace*>; |
| 9 |
unlink 'PLOT'; |
| 10 |
|
| 11 |
##$f="10 + 1/(1+ 100**(sin(x*3)-y)) "; |
| 12 |
#$f1 = "(10*x*x*x+y*y*y) + 10/(1+10**(10*((sin(5*x)-2*y)))) "; |
| 13 |
$f1=" sin(3*x)*cos(5*y)+ atan2(0.001,x**2 + y**2 - 0.5 )"; |
| 14 |
#$f1=" 8*(x-y)**2 + (x+y)**2"; |
| 15 |
|
| 16 |
$err=0.1; |
| 17 |
$errg=0.01; |
| 18 |
$nbiteration=10; |
| 19 |
$bamg=$ENV{'bamg'}; |
| 20 |
$quadoption=""; |
| 21 |
$bamgoption=" -AbsError -NbJacobi 2 -NbSmooth 5 -anisomax 5 -hmax 0.5 -ratio 2 -nbv 100000 "; |
| 22 |
#$bamgoption=" -AbsError -NbJacobi 3 -ratio 2 -anisomax 30"; |
| 23 |
#$quadoption=" -2q -thetaquad 30 -coef 2"; |
| 24 |
|
| 25 |
# --- change x in $x and y in $y |
| 26 |
$_=$f1; |
| 27 |
s/x/\$x/g; |
| 28 |
s/y/\$y/g; |
| 29 |
$f1="$_;"; |
| 30 |
|
| 31 |
print "The function = f1(x,y) = $f1 \n"; |
| 32 |
|
| 33 |
#-------------------------- |
| 34 |
$suffixe=".mesh"; |
| 35 |
$iteration=0; |
| 36 |
$GH="Gh$suffixe"; |
| 37 |
$TH="Th$iteration$suffixe"; |
| 38 |
$, = ' '; # set output field separator |
| 39 |
$\ = "\n"; # set output record separator |
| 40 |
## ------------------------------------------------------------- |
| 41 |
## --- construction the Geometry file Gh.mesh |
| 42 |
|
| 43 |
## 8 points on circle of radius r |
| 44 |
open(GH,">$GH") || die "Can't redirect stdout"; |
| 45 |
$Pi = 3.14159265358979; |
| 46 |
|
| 47 |
$i8 = 8; |
| 48 |
$r = 1; |
| 49 |
$c0x = 0; |
| 50 |
$c0y = 0; |
| 51 |
print GH 'Dimension', 2; |
| 52 |
print GH 'MaximalAngleOfCorner 46'; |
| 53 |
|
| 54 |
print GH 'Vertices'; |
| 55 |
print GH $i8; |
| 56 |
|
| 57 |
# vertex on circle (counter clock wise) |
| 58 |
for ($i = 0; $i < $i8; $i++) { |
| 59 |
$t = $i * $Pi * 2 / $i8; |
| 60 |
print GH $c0x + $r * (cos($t)), $c0y + $r * sin($t), 5; |
| 61 |
} |
| 62 |
|
| 63 |
print GH 'Edges', $i8+1; |
| 64 |
|
| 65 |
print GH 1,5,10; |
| 66 |
# edge on circle |
| 67 |
$k = 1; |
| 68 |
$j = $i8 - 1; |
| 69 |
# previous points |
| 70 |
for ($i = 0; $i < $i8; $j = $i++) { |
| 71 |
print GH $k + $j, $k + $i, 5; |
| 72 |
} |
| 73 |
# previous, current vertex |
| 74 |
|
| 75 |
# one subdomain, region on left side of the wing |
| 76 |
# because clock wise sens. |
| 77 |
print GH 'SubDomain', 2; |
| 78 |
print GH 2, 1, 1, 0; |
| 79 |
print GH 2, 1, -1, 1; |
| 80 |
close GH; |
| 81 |
## -------------- END construct of the geom |
| 82 |
## |
| 83 |
|
| 84 |
# -- make the DATA file for the mesh to also save the arguments |
| 85 |
open(BAMG,">DATA_bamg") || die "Can't open DATA_bamg"; |
| 86 |
print BAMG "$quadoption $bamgoption -g $GH -o $TH -v 9 -oam_fmt $TH.am_fmt"; |
| 87 |
close(BAMG); |
| 88 |
|
| 89 |
## constructio the inital mesh |
| 90 |
!system($bamg) || die "Error in bamg construction of initial mesh $Th"; |
| 91 |
|
| 92 |
## the adpatation loop |
| 93 |
while ($iteration<$nbiteration) { |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
$BB="$iteration.BB"; |
| 98 |
$ERRBB="err$iteration.bb"; |
| 99 |
|
| 100 |
|
| 101 |
## construction of the solution |
| 102 |
$errsol=0; |
| 103 |
open (TH,"<$TH") || die "Can't open $TH"; |
| 104 |
open (BB,">$BB") || die "Can't open $BB"; |
| 105 |
open (ERRBB,">$ERRBB") || die "Can't open $ERRBB"; |
| 106 |
|
| 107 |
|
| 108 |
while (<TH>) { |
| 109 |
if(/^Vertices$/) { |
| 110 |
$nbv=<TH>; |
| 111 |
chop($nbv); |
| 112 |
print BB "2 1 1 $nbv 2"; |
| 113 |
|
| 114 |
for ($i=1;$i<=$nbv;$i++) { |
| 115 |
($x,$y,$ref)=split(/[\ \t\n]+/, <TH>); |
| 116 |
$f1xy=eval $f1; |
| 117 |
|
| 118 |
$xx[$i]=$x; |
| 119 |
$yy[$i]=$y; |
| 120 |
$ff[$i]=$f1xy; |
| 121 |
|
| 122 |
|
| 123 |
print BB $f1xy ; |
| 124 |
|
| 125 |
}; |
| 126 |
}; |
| 127 |
if(/^Triangles$/) { |
| 128 |
$nbt=<TH>; |
| 129 |
chop($nbt); |
| 130 |
print " Nb of Triangles = $nbt \n"; |
| 131 |
print ERRBB "2 1 $nbt 1"; |
| 132 |
for ($i=1;$i<=$nbt;$i++) { |
| 133 |
($i0,$i1,$i2,$ref)=split(/[\ \t\n]+/, <TH>); |
| 134 |
|
| 135 |
$x = ($xx[$i0]+$xx[$i1]+$xx[$i2])/3; |
| 136 |
$y = ($yy[$i0]+$yy[$i1]+$yy[$i2])/3; |
| 137 |
$fm = ($ff[$i0]+$ff[$i1]+$ff[$i2])/3; |
| 138 |
$fxy = eval $f1; |
| 139 |
$vv=($fm-$fxy); |
| 140 |
$vv= ($vv<0)?-$vv:$vv; |
| 141 |
print ERRBB $vv; |
| 142 |
$errsol = ($errsol>$vv) ? $errsol : $vv; |
| 143 |
}; |
| 144 |
}; |
| 145 |
|
| 146 |
}; |
| 147 |
close TH; |
| 148 |
close BB; |
| 149 |
close ERRBB; |
| 150 |
print " ---------------------------------------------\n"; |
| 151 |
print "\n\n Iteration $iteration\n Erreur L_infini = $errsol \n\n"; |
| 152 |
print " ---------------------------------------------\n"; |
| 153 |
|
| 154 |
## ----------------------- |
| 155 |
|
| 156 |
$MTR="M$iteration.mtr"; |
| 157 |
|
| 158 |
$iteration++; |
| 159 |
$BTH=$TH; |
| 160 |
$TH="Th$iteration$suffixe"; |
| 161 |
|
| 162 |
open(BAMG,">DATA_bamg") || die "Can't open DATA_bamg"; |
| 163 |
print BAMG "$quadoption $bamgoption -MBB $BB -errg $errg -err $err -b $BTH -o $TH -v 9 -oM $MTR -oam_fmt $TH.am_fmt -wBB /tmp/tyty "; |
| 164 |
close(BAMG); |
| 165 |
!system($bamg) || die "Error in bamg construction of adapted $iteration mesh $Th"; |
| 166 |
} |
| 167 |
|
| 168 |
print "Normal End\n"; |