title anode

c The anode is constructed by starting with a prism shaped logical
c mesh which is hollowed out for the cavity. Then both the exterior
c and interior are projected to the appropriate cylinders. The
c top of the anode is projected to the desired plane surface.

parameter c to be chosen from the design
md 20     c mesh density
rho1 .1   c radius of inner cavity
rho2 .125 c outer radius of anode
rho3 .15  c outer radius of ring
xc 1      c x-component of normal to top plane of anode
zc 1      c z-component of normal to top plane of anode
z1 0      c height of base
z2 .25    c height of bottom of ring
z3 .375   c height of top of ring
z4 .75    c height of top of cavity at the cylinder wall
z5 .855   c height of top of cavity at the center
z7 1.125; c height of peak of anode

parameter c dependent on the design parameters
pi 3.14159
z6 [%z7-2*%rho2*%xc/%zc] c lowest point of top of anode
c number of elements in the thickness of the wall 
ij1 [max(2,nint((%rho2-%rho1)*%md))]
c 1/8th the number of elements in the circumference 
ij2 [max(1,nint(.25*%pi*%rho2*%md))]
c number of elements in the thickness of the ring
ij3 [max(2,nint((%rho3-%rho2)*%md))]
c number of elements from bottom of anode to ring
k1 [max(1,nint((%z2-%z1)*%md))]
c number of elements in height of ring
k2 [max(1,nint((%z3-%z2)*%md))]
c number of elements from ring to top of cavity
k3 [max(1,nint((%z4-%z3)*%md))]
c number of elements from top of cavity to top of anode
k4 [max(1,nint((.5*(%z6+%z7)-%z4)*%md))]
epsin  [%rho1/sqrt(2)]
delin  [(%rho2-%epsin)*%xc/%zc]
epsout [%rho2/sqrt(2)]
delout [(%rho2-%epsout)*%xc/%zc];

c define surfaces for projections
sd 1 cy   0 0 0 0 0 1 %rho1        c cavity cylinder
sd 2 cy   0 0 0 0 0 1 %rho2        c outer wall cylinder of anode
sd 3 cy   0 0 0 0 0 1 %rho3        c outer wall cylinder of ring
sd 4 plan %rho2 0 %z7 [-%xc] 0 %zc c top plane of anode

block c beginning of part

1 [1+%ij3] [1+%ij3+%ij1] [1+%ij3+%ij1+%ij2] [1+%ij3+%ij1+2*%ij2] 
[1+%ij3+2*%ij1+2*%ij2] [1+2*%ij3+2*%ij1+2*%ij2];
1 [1+%ij3] [1+%ij3+%ij1] [1+%ij3+%ij1+%ij2] [1+%ij3+%ij1+2*%ij2] 
[1+%ij3+2*%ij1+2*%ij2] [1+2*%ij3+2*%ij1+2*%ij2];
1 [1+%k1] [1+%k1+%k2] [1+%k1+%k2+%k3] [1+%k1+%k2+%k3+%k4];

c initialize prism mesh to circumscribe inner and outer cylinders of anode
[-2*%rho2] [-2*%rho2] [-2*%rho1] 0 [2*%rho1] [2*%rho2] [2*%rho2]
[-2*%rho2] [-2*%rho2] [-2*%rho1] 0 [2*%rho1] [2*%rho2] [2*%rho2]
%z1 %z2 %z3 %z4 %z7 

dei 1 2 0 6 7;;1 2 0 3 5; c delete regions above and below ring
dei ;1 2 0 6 7;1 2 0 3 5; c

dei 1 3 0 5 7;1 3 0 5 7;; c remove the corner columns of the mesh

pb 2 3 0 2 3 0 xy [-%epsout] [-%epsout] c position the exposed surfaces
pb 3 2 0 3 2 0 xy [-%epsout] [-%epsout] c due to column deletions so
pb 6 3 0 6 3 0 xy   %epsout  [-%epsout] c that edges project to the same
pb 5 2 0 5 2 0 xy   %epsout  [-%epsout] c point to be merged together
pb 2 5 0 2 5 0 xy [-%epsout]   %epsout  c
pb 3 6 0 3 6 0 xy [-%epsout]   %epsout  c
pb 6 5 0 6 5 0 xy   %epsout    %epsout  c
pb 5 6 0 5 6 0 xy   %epsout    %epsout  c

pb 1 3 2 1 3 3 xy [-%epsout] [-%epsout] c position the exposed surfaces
pb 3 1 2 3 1 3 xy [-%epsout] [-%epsout] c due to column deletions in the
pb 1 5 2 1 5 3 xy [-%epsout]   %epsout  c ring so that edges project to the
pb 3 7 2 3 7 3 xy [-%epsout]   %epsout  c same point to be merged
pb 7 3 2 7 3 3 xy   %epsout  [-%epsout] c
pb 5 1 2 5 1 3 xy   %epsout  [-%epsout] c
pb 7 5 2 7 5 3 xy   %epsout    %epsout  c
pb 5 7 2 5 7 3 xy   %epsout    %epsout  c

de 3 3 1 5 5 4                          c hollow out the cavity

pb 3 3 0 3 3 0 xy [-%epsin ] [-%epsin] c position the edges of
pb 5 3 0 5 3 0 xy   %epsin   [-%epsin] c the cavity prior to
pb 3 5 0 3 5 0 xy [-%epsin]    %epsin  c projections so that the mesh
pb 5 5 0 5 5 0 xy   %epsin     %epsin  c through the wall is consistent

pa 2 3 5 z [%z6+%delout]  c adjust the z coordinates for the top
pa 3 2 5 z [%z6+%delout]  c surface of the anode to avoid distortions
pa 5 2 5 z [%z7-%delout]  c in the mesh due to the projection 
pa 6 3 5 z [%z7-%delout]  c method
pa 3 6 5 z [%z6+%delout]  c 
pa 2 5 5 z [%z6+%delout]  c 
pa 6 5 5 z [%z7-%delout]  c 
pa 5 6 5 z [%z7-%delout]  c 
pa 3 3 5 z [%z6+%delin]   c 
pa 5 3 5 z [%z7-%delin]   c 
pa 3 5 5 z [%z6+%delin]   c 
pa 5 5 5 z [%z7-%delin]   c 
pb 4 0 5 4 0 5 z [.5*(%z6+%z7)]

pa 4 4 4 z %z5 c adjust height of peak of cavity

sf  0 0 5 0 0 5  sd 4 c project the top to plane
sfi -3 -5;-3 -5;;sd 1 c project the cavity to cylinder
sfi -2 -6;-2 -6;;sd 2 c project the outer wall to cylinder
sfi -1 -7;-1 -7;;sd 3 c project the outer wall to cylinder

endpart c end of part

stp .001 c merge the anode and the ring

merge
rx 20 ry 30 zf 2 tvv
