% extrusion_grid.m - FEATool Multiphysics Grid Extrusion Example.

% Copyright 2013-2019 Precise Simulation, Ltd.


ro = 0.003;   % Outer circle diameter.
ri = ro/2;    % Inner circle diameter.

% Circle 1.
co1 = gobj_circle( [0.01,0.01], ro, 'CO1' );
ci1 = gobj_circle( [0.01,0.01], ri, 'CI1' );

% Circle 2.
co2 = gobj_circle( [0.05,0.02], ro, 'CO2' );
ci2 = gobj_circle( [0.05,0.02], ri, 'CI2' );

% Remove inner holes from circles.
geom.objects = { co1 ci1 co2 ci2 };
geom = geom_apply_formula( geom, 'CO1-CI1' );
geom = geom_apply_formula( geom, 'CO2-CI2' );


% Base rectangle.
r1 = gobj_rectangle( 0, 0.06, 0, 0.03, 'R1' );

% Remove (outer) circles from base rectangle.
geom.objects = [ geom.objects { r1 co1 co2 } ];
geom = geom_apply_formula( geom, 'R1-CO1-CO2' );


% Polygon for connecting conductive track.
w = 0.002/2;
p = [ 0.01   0.02-w/2 0.03-w/2 0.05   0.05   0.03+w/2 0.02+w/2 0.01   ;
      0.01+w 0.01+w   0.02+w   0.02+w 0.02-w 0.02-w   0.01-w   0.01-w ];
p1 = gobj_polygon( p', 'P1' );

% Remove outer circles from conductive rtack.
geom.objects = [ geom.objects { p1 co1 co2 } ];
geom = geom_apply_formula( geom, 'P1-CO1-CO2' );

% Join circles and conductive track.
geom = geom_apply_formula( geom, 'CS6+CS1+CS2' );


% 2D grid generation.
hmax = (ro-ri)/2;
if( exist('gridgen_triangle') )
  grid = gridgen_triangle( geom, 'hmax', [10*hmax hmax] );
else
  warning( 'Install gridgen_triangle for improved grid generation.' )
  grid = gridgen( geom, 'hmax', hmax );
end


% Extrude grid.
grid2 = gridextrude( grid, 2, 0.002 );


% Plot grid.
cols = repmat( {[0 0 0.5]}, max(grid2.b(3,:)) );
[cols{[19 20]}] = deal([0.9 0.9 0.9]);
[cols{[1:10 11:16]}] = deal([0.7 0.7 1]);
plotgrid( grid2, 'edgecolor', [0.3 0.3 0.3] )
plotbdr(  grid2, 'labels', 'off', 'colors', cols  )
view(3)
