%% FEATool Multiphysics Version 1.12.5, Build 20.10.289, Model M-Script file.
%% Created on 15-Oct-2020 11:28:49 with MATLAB 9.8.0.1359463 (R2020a) Update 1 PCWIN64.


%% Starting new model.
fea.sdim = { 'x', 'y', 'z' };
fea.geom = struct;
fea = addphys( fea, @conductivemediadc, { 'V' } );

%% Geometry operations.

%% 2D workplane
wpl = struct('p', [0.5,0.5,0.5], 'n', [0,0,1], 't', [1,0,0]);
fea_wpl.sdim = {'x', 'y'};
fea_wpl.geom = struct;

gobj = gobj_ellipse( [0 0], [.1], [.2], 'E1' );
fea_wpl = geom_add_gobj( fea_wpl, gobj );

gobj = gobj_extrude( fea_wpl.geom.objects{1}, 0.02, [0  0  1], wpl );
fea = geom_add_gobj( fea, gobj );
clear fea_wpl wpl

fea = geom_apply_chamfer( fea, 'EXT1', 0.01, [1 2 3 4 5 6] );
fea = geom_apply_chamfer( fea, 'EXT1', 0.009, [1 2 3 4 5 6] );
fea = geom_apply_transformation( fea, 'CH1', [ 0  0  0 ], [2.5 2.5 .05], 0, [ 1  0  0 ], [0.5  0.5  0.51], true );
fea = geom_apply_transformation( fea, 'TF1', [-1.25 -1.25  0 ], [ 1  1  1 ], 0, [ 1  0  0 ], [1.25  1.25  0.0255], true );
fea.geom = geom_revert_object( fea.geom, 'TF2' );
fea = geom_apply_transformation( fea, 'TF1', [-1.25 -1.25  -.025 ], [ 1  1  1 ], 0, [ 1  0  0 ], [1.25  1.25  0.0255], true );
gobj = gobj_block( [-1], [1], [-1], [1], [-1], [1], 'B1' );
fea = geom_add_gobj( fea, gobj );

%% Grid operations.
fea.grid = gridgen( fea, 'gridgen', 'gmsh', 'hmax', 0.19, 'nsm', 25 );

%% Geometry operations.
del_gobj = fea.geom.objects{2};
fea.geom.objects([2]) = [];
fea.geom = geom_update_tags( fea.geom );
fea = geom_apply_chamfer( fea, 'TF2', 0.001, [1 10 11 12 13 14 2 3 4 5 6 7 8 9] );
fea = geom_apply_chamfer( fea, 'TF2', 0.0001, [1 10 11 12 13 14 2 3 4 5 6 7 8 9] );
fea.geom = geom_revert_object( fea.geom, 'TF2' );
fea.geom = geom_revert_object( fea.geom, 'TF1' );
fea.geom = geom_revert_object( fea.geom, 'CH1' );
fea = geom_apply_transformation( fea, 'EXT1', [-.5 -.5 -.5], [ 1  1  1 ], 0, [ 1  0  0 ], [0.5  0.5  0.51], true );
fea.geom = geom_revert_object( fea.geom, 'TF1' );
fea = geom_apply_transformation( fea, 'EXT1', [-.5 -.5 -.5], [ 1  1  1 ], 0, [ 1  0  0 ], [0.5  0.5  0.51], true );
fea = geom_apply_chamfer( fea, 'TF1', 0.003, [1 2 3 4 5 6] );
fea.geom = geom_revert_object( fea.geom, 'CH1' );
fea = geom_apply_chamfer( fea, 'TF1', 0.0066, [1 2 3 4 5 6] );
fea = geom_apply_chamfer( fea, 'CH1', 0.0033, [1 10 11 12 13 14 2 3 4 5 6 7 8 9] );
fea.geom = geom_revert_object( fea.geom, 'CH2' );
fea = geom_apply_chamfer( fea, 'CH1', 0.0015, [1 10 11 12 13 14 2 3 4 5 6 7 8 9] );
fea.geom = geom_revert_object( fea.geom, 'CH2' );
fea = geom_apply_chamfer( fea, 'CH1', 0.001, [1 10 11 12 13 14 2 3 4 5 6 7 8 9] );
fea.geom = geom_revert_object( fea.geom, 'CH2' );
fea = geom_apply_chamfer( fea, 'CH1', 0.002, [1 10 11 12 13 14 2 3 4 5 6 7 8 9] );
fea.geom = geom_revert_object( fea.geom, 'CH2' );
fea = geom_apply_chamfer( fea, 'CH1', 0.002, [1 10 11 12 13 14 2 3 4 5 6 7 8 9] );

%% Grid operations.

%% Geometry operations.
gobj = gobj_block( [-2], [2], [-1], [1], [-1], [1], 'B1' );
fea = geom_add_gobj( fea, gobj );

%% Grid operations.
fea.grid = gridgen( fea, 'gridgen', 'gmsh', 'hmax', 0.22, 'nsm', 25 );

%% Geometry operations.
fea = geom_apply_transformation( fea, 'CH2', [ 0  0  0 ], [ 1  1  .1], 0, [ 1  0  0 ], [0  0  0.01], true );

%% Grid operations.
fea.grid = gridgen( fea, 'gridgen', 'gmsh', 'hmax', 0.22, 'nsm', 25 );

%% Geometry operations.
fea = geom_apply_transformation( fea, 'TF2', [ 0  0  .1 ], [ 1  1  1 ], 0, [ 1  0  0 ], [0  0  0.001], true );

%% Grid operations.

%% Geometry operations.
fea = geom_apply_transformation( fea, 'TF3', [ 0  0  .1], [ 1  1  1 ], 0, [ 1  0  0 ], [0  0  0.101], true );

%% Grid operations.

%% Geometry operations.

%% Grid operations.
fea.grid = gridgen( fea, 'gridgen', 'gmsh', 'hmax', 0.22, 'nsm', 25 );
fea = gridrefine( fea );
fea.grid = gridgen( fea, 'gridgen', 'gmsh', 'hmax', 0.055653, 'nsm', 25 );

%% Geometry operations.
fea.geom = geom_revert_object( fea.geom, 'TF4' );
fea.geom = geom_revert_object( fea.geom, 'TF3' );
fea.geom = geom_revert_object( fea.geom, 'TF2' );

%% Grid operations.
fea.grid = gridgen( fea, 'gridgen', 'gmsh', 'hmax', 0.22, 'nsm', 25 );

%% Geometry operations.

