% Demonstration of Electrical Impedance Tomography using a 2D diffusion
% model in a rectangular grid. Here we produce pictures of a non-physical
% situation for the sake of our argument.
%
% Samuli Siltanen March 2025

% Set the dimension of the model
N = 3;

% Record number of electrodes
Ne = 4*(N-1);

% Injected current amplitude (milli-Amperes)
I = 1;

% Define the conductivity as one everywhere
% condmatH: conductivity values between horizontal neighbors, Nx(N-1) matrix
% condmatV: conductivity values between vertical neighbors, (N-1)x N matrix
% The conductivity between boundary pixels and outside is assumed to be one.
condmatH = ones(N,N-1);
condmatV = ones(N-1,N);

% Fill in the values to the non-physical potential matrix. This 
% non-solution will serve as a question to learners: can this be the solution?
potmat = zeros(3);
potmat(2,1) = -1;
potmat(2,2) = -2;
potmat(2,3) = -3;

% Fill in the matching (non-physical) values to the boundary data vectors
bdata_vol = zeros(Ne,1);
bdata_vol(1) = -4; 
bdata_cur = zeros(Ne,1);
bdata_cur(1) = -1; 
bdata_cur(5) = 1; 

% Plot potentials as colors, show currents
fignum = 1;
show_inside = 1;
plot_curr = 1;
currmatH = zeros(N,N-1);
currmatH(2,:) = -1;
currmatV = zeros(N-1,N);
EIT_FD_demo2D_potential_plot(potmat,currmatH,currmatV,fignum,bdata_vol,bdata_cur,plot_curr,show_inside)
disp('saving potential color image')
print -dpng -r500  images/FD_EIT_2D_demoA_3x3_case1_potential_color.png
disp('potential color image saved')


% Plot potentials as numbers
fignum = 5;
plot_x = 0;
show_inside = 1;
fsize = 16;
EIT_FD_demo2D_text_plot(potmat,fignum,bdata_vol,plot_x,show_inside,fsize,0)
disp('saving potential numbers image')
print -dpng -r500  images/FD_EIT_2D_demoA_3x3_case1_potential_numbers.png
disp('potential numbers image saved')

% Plot variable names
fignum = 6;
plot_x = 1;
show_inside = 1;
fsize = 20;
EIT_FD_demo2D_text_plot(potmat,fignum,bdata_vol,plot_x,show_inside,fsize)
disp('saving variables image')
print -dpng -r500 images/FD_EIT_2D_demoA_3x3_case1_variables.png
disp('variables image saved')
