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