%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [q0,edof,emat,bc,F_ext,mat,ndim,nel,node,ndof,nip,nlod] = ex_humr1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tol  =  1e-8;

emod = 500;
nue  = 0.3;
rho0 = 1.00;
psi0 = 0.01;
expm = 3.0;
expn = 2.0;
dt   = 5.0;

mat = [emod,nue,rho0,psi0,expm,expn,dt];
%material parameters
%emod  nue  psi0*  rho0* expm  expn   dt
%500  0.20  0.01   1.20  3.00  2.00  2.0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate node points q0 and connectivity edof
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[q0,edof]=in_humr1; 

[nel,sizen]  = size(edof);
[ndof,sizen] = size(q0);
 for ie=1:nel emat(ie) = 1; end;

 node = ndof/3;
 nip  = 1;
 ndim = 3;
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dirichlet and neumann boundary conditions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
%F_ext = zeros(ndof,1);
%nlod  = 3;

ymin  = min(q0(2:3:ndof)) * 0.98; % elbow side?
ymax  = max(q0(2:3:ndof)) * 0.95; % shoulder side?
nb    = 1;

for nfix=2:3:ndof
  if(q0(nfix)<=ymin)     
%    bc(nb,1) = nfix-1;
%    bc(nb,2) = 0;
%    nb = nb+1;
%    bc(nb,1) = nfix;
%    bc(nb,2) = 0;
%    nb = nb+1;
%    bc(nb,1) = nfix+1;
%    bc(nb,2) = 0;
%    nb = nb+1;
%	disp(['*** elbow node: ',num2str((nfix+1)/3)]);  	
  end  
end

for nfix=2:3:ndof
  if(q0(nfix)>=ymax)     
%    bc(nb,1) = nfix-1;
%    bc(nb,2) = 0;
%    nb = nb+1;
%    bc(nb,1) = nfix;
%    bc(nb,2) = 0;
%    nb = nb+1;
%    bc(nb,1) = nfix+1;
%    bc(nb,2) = 0;
%    nb = nb+1;
%	disp(['*** sholder node: ',num2str((nfix+1)/3)]);  	
  end  
end

%for nfor=2:3:ndof
%  if(q0(nfor)<=ymin)
%    bc(nb,1) = nfor;
%    bc(nb,2) = 0.01*ymin; 
%    nb = nb+1;
%%%	F_ext(nfor,1)=-0.001;
%  end    
%end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
fixnod1=[56;68;97;104;241;243;336];                     % small bone
fixnod2=[54;74;81;85;91;93;101;247;250;343;354];        % big bone inside
fixnod3=[41;45;49;50;52;59;60;69;75;78;237;248];        % big bone outside
fixnod4=[1;2;3;4;5;6;7;8;9;10;12;13;14;15;17;18;20;21;30;32;...
         35;36;42;47;48;51;55;57;58;64;73;80;83;95;96;106;...
         119;128;134;138;144;145;146;149;150;151;154;161;167;...
         171;174;175;176;177;222;342;345];              % shoulder
		 
fixnod =[1;2;3;4;5;6;7;8;9;10;...
		12;13;14;15;17;18;20;...
		21;...
		30;32;35;36;...
		41;42;45;47;48;49;...
		50;51;52;54;55;56;57;58;59;...
		60;64;68;69;...
		73;74;75;78;...
		80;81;83;85;...
		91;93;95;96;97;...
		101;104;106;...
		119;...
		128;...
		134;138;...
		144;145;146;149;...
		150;151;154;...
		161;167;...
		171;174;175;176;177;...
		222;237;241;243;247;248;250;...
		336;342;343;345;354];
		
nb = 1;
for i=1:87
    nd=fixnod(i);
    bc(nb,1) = nd*3-2;
    bc(nb,2) = 0;
    nb = nb+1;
    bc(nb,1) = nd*3-1;
    bc(nb,2) = 0;
    nb = nb+1;
    bc(nb,1) = nd*3;
    bc(nb,2) = 0;
    nb = nb+1;	
end

F_ext = zeros(ndof,1);
nlod = 5;

F0 = 0.02;
F0 = 0.0005;

% elbow pointing force
% F_ext(306*3-2,1) =-0.1881 * F0;
F_ext(306*3-2,1) = 0.1881 * F0;
%F_ext(306*3-2,1) = 0.2881 * F0;
F_ext(306*3-1,1) =-0.9407 * F0;
F_ext(306*3-0,1) =+0.2822 * F0;

% shoulder pointing force
F_ext(310*3-2,1) =+0.1826 * F0;
%F_ext(310*3-2,1) =+0.0826 * F0;
F_ext(310*3-1,1) =+0.9129 * F0;
F_ext(310*3-0,1) =-0.3651 * F0;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
% points to fix on Coarse Model:  
% 184,13,3,20,55,119,151,167,171,145        <-- or any 6 of these
%
% points to fix on Fine Model: 
% 180, 515, 20, 516, 55, 106, 167, 177, 514 <-- or any 6 of these
%
% points to apply force-- apply approx 200lbs at each node
%
% towards elbow    coarse: node #306   200lb * [0.1881  0.9407  -0.2822]
% towards shoulder coarse: node #310   200lb * [0.1826  0.9129  -0.3651]
%
% towards elbow    fine:   node #446   200lb * [0.1881  0.9407  -0.2822]
% towards shoulder fine:   node #453   200lb * [0.1826  0.9129  -0.3651]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
