// catbody.fe

// Evolver data for catenoid with interior as body.
// Does not use top and bottom facet to completely bound volume.
// Useful for doing unstable catenoid by stabilizing with volume constraint.

PARAMETER  RMAX = 1.0
PARAMETER  ZMAX = 0.4 

boundary 1 parameters 1     //  upper ring
x1:  RMAX * cos(p1)
x2:  RMAX * sin(p1)
x3:  ZMAX


boundary 2 parameters 1    //   lower ring
x1:  RMAX * cos(p1)
x2:  RMAX * sin(p1)
x3:  -ZMAX


vertices   // given in terms of boundary parameter
1    0.00  boundary 1   fixed
2    pi/3  boundary 1   fixed
3  2*pi/3  boundary 1   fixed
4    pi    boundary 1   fixed
5  4*pi/3  boundary 1   fixed
6  5*pi/3  boundary 1   fixed
7    0.00  boundary 2   fixed
8    pi/3  boundary 2   fixed
9  2*pi/3  boundary 2   fixed
10   pi    boundary 2   fixed
11 4*pi/3  boundary 2   fixed
12 5*pi/3  boundary 2   fixed

edges
1    1  2  boundary 1   fixed
2    2  3  boundary 1   fixed
3    3  4  boundary 1   fixed
4    4  5  boundary 1   fixed
5    5  6  boundary 1   fixed
6    6  1  boundary 1   fixed
7    7  8  boundary 2   fixed
8    8  9  boundary 2   fixed
9    9  10 boundary 2   fixed
10   10 11 boundary 2   fixed
11   11 12 boundary 2   fixed
12   12 7  boundary 2   fixed
13   1  7
14   2  8
15   3  9
16   4  10
17   5  11
18   6  12

faces
1   1 14 -7 -13
2   2 15 -8 -14
3   3 16 -9 -15
4   4 17 -10 -16
5   5 18 -11 -17
6   6 13 -12 -18

bodies // Unfortunately, had faces oriented with inward normal.
1  -1 -2 -3 -4 -5 -6

read
hessian_normal

// get better triangulation
edgeswap edge where id >= 13 and id <= 18; 

// A command to find the equation of the unstable catenoid
findun := { aa := 0.001;
            testr := aa*cosh(zmax/aa);
            while ( abs(testr-rmax) > 1e-10 ) do
            { dr := testr - rmax;
              drda := cosh(zmax/aa) - zmax/aa*sinh(zmax/aa);
              aa := aa - dr/drda;
              testr := aa*cosh(zmax/aa);
            };
            printf "aa := %f\n",aa;
          }

// Command to set shape to unstable catenoid.  Moves radially to catenoid.
setshape := { findun;
	      foreach vertex vv where not fixed do
              { rad := aa*cosh(vv.z/aa);
                oldr := sqrt(vv.x^2+vv.y^2);
                vv.x := rad*vv.x/oldr;
                vv.y := rad*vv.y/oldr;
              };
	      recalc;
	      body[1].target := body[1].volume; // set volume constraint
            }
                
            
