% Script to assemble matrices for a 2D diffusion problem

%% set path
  addpath './subs_source/oned';  addpath './subs_source/twod'

%% set parameter values and assemble arrays
  param = p_data();
  [M1, M2, F, b,  x, e_conn] =  assemb_co(param);
      
%% clean-up path
  rmpath './subs_source/oned';  rmpath './subs_source/twod'
  
%% Steady state solutions
  z_tmp = -full(M2)\full(F+b); % Temperature distribution
  z_ss  = gather(z_tmp, 1);

%% Plot and save a surface plot
  if labindex == 1
      xx = x(1:param.nodesx, 1);
      yy = x(1:param.nodesx:param.nodesx*param.nodesy, 2);
      figure
      surf(xx, yy, reshape(z_ss, param.nodesx, param.nodesy)' );
      xlabel('\bf x'); ylabel('\bf y'); zlabel('\bf T')
      t_axis = axis;
      print -dpng fig_ss.png
      close all
  end