#!/bin/sh
#
# This file is part of Rheolef.
#
# Copyright (C) 2000-2018 Pierre Saramito 
#
# Rheolef is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Rheolef is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rheolef; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# -------------------------------------------------------------------------

if test $# -eq 0; then
  echo "usage: mkgeo_circle <n>" >&2
  exit 1
fi
n=$1
basename="circle"
name=${basename}-${n}
bamgcad=${name}.bamgcad
echo "! file \"$bamgcad\" created." >&2

cat > $bamgcad << EOF1
MeshVersionFormatted
0

Dimension
2

Vertices
$n
EOF1


echo | awk -v n=$n 'BEGIN {
  pi = 3.14159265358979323846
  for (i = 0; i < n; i++)
    printf ("%25.16g %25.16g     1\n", cos(2*i*pi/n), sin(2*i*pi/n))
}' >> $bamgcad

cat >> $bamgcad << EOF2
Edges
$n
EOF2

echo | awk -v n=$n 'BEGIN {
  for (i = 0; i < n; i++)
    printf ("%5d %5d     1\n", i+1, ((i+1)%n) + 1)
}' >> $bamgcad

bamg=$name.bamg
command="bamg -g $bamgcad -o $bamg"
echo "! $command"
eval $command

dmn=$basename.dmn
echo "! file \"$dmn\" created." >&2
cat > $dmn << EOF3
EdgeDomainNames
1
boundary
EOF3

geo=$name.geo
command="bamg2geo $bamg $dmn > $geo"
echo "! $command"
eval $command

