#include <cstdlib>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
fstream out;
if (argc==1)
{
printf("Parameter missing!\n");
return EXIT_FAILURE;
}
int u=atoi(argv[1]);
int m=u+1;
int n=2*u;
out.open ("bubbles.fe", std::fstream::in | std::fstream::out | std::fstream::app);
int nv=1;
out<<"string\nspace_dimension 2\n\n";
out<<"parameter rad = 1.0\n\n";
out<<"Vertices\n\n";
int s=0;
for (int i=0;i<m+1;i++,s+=(1+i%2))
{
for (int j=0;j<n+1;j++,nv++)
{
out<<nv<<" "<<j<<"*rad*cos(pi/6) ";
double y=s;
if (!(j%2))
{
if (i%2)
y-=0.5;
else
y+=0.5;
}
out<<y<<"*rad\n";
}
}
out<<"\nEdges\n\n";
int ne=1;
nv=1;
for (int i=0;i<m+1;i++)
{
for (int j=0;j<n;j++,nv++,ne++)
out<<ne<<" "<<nv<<" "<<nv+1<<"\n";
nv-=n;
for (int j=0;j<n+1;j++,nv++)
{
if ((i<m)&&((j%2)^(i%2)^1))
{
out<<ne<<" "<<nv<<" "<<nv+n+1<<"\n";
ne++;
}
}
}
out<<"\nFaces\n\n";
int nf=1;
ne=1;
int r=n/2;
for (int i=0;i<m;i++)
{
if (!(i%2))
for (int j=0;j<n;j+=2,nf++,ne+=2)
{
out<<nf<<" "<<ne<<" "<<ne+1<<" "<<ne+(n-j/2+1)<<" "<<-(ne+(n+r+2))<<" "<<-(ne+n+r+1)<<" "<<-(ne+(n-j/2))<<"\n";
}
else
for (int j=0;j<r-1;j++,nf++,ne+=2)
{
out<<nf<<" "<<ne<<" "<<ne+1<<" "<<ne+(n-j)<<" "<<-(ne+(n+r+1))<<" "<<-(ne+n+r)<<" "<<-(ne+n-j-1)<<"\n";
}
ne+=r+2-(i%2);
}
out<<"\nBodies\n\n";
for (int i=1;i<=nf-1;i++)
{
out<<i<<" "<<i<<" volume 3*sqrt(3)/2\n";
}
out.close();
return EXIT_SUCCESS;
}