Index: /issm/trunk/test/Validation/EISMINT/Diagnostic1/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic1/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic1/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+200000 0
+200000 200000
+0 200000 
+0 0
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic1/Front.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic1/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic1/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic1/README
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic1/README	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic1/README	(revision 16)
@@ -0,0 +1,10 @@
+Test on an idealized geometry 
+
+Diagnostic equations:
+To launch this test, use runme
+
+tests 3 and 4:
+A=5.7*10^-19 Pa^-3.a^-1 -> B=1.7687*10^8 Pa.s^1/3
+
+density 5100 -> 1488 nodes and 2839 elements
+dentity 3550 -> 3221 nodes and 6232 elements
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic1/Square.par
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic1/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic1/Square.par	(revision 16)
@@ -0,0 +1,123 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.81;
+	md.rho_ice=917;
+	md.rho_water=1028;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=500*ones(md.numberofgrids,1);
+	md.firn_layer=0*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	%md.B=paterson(md.observed_temperature);
+	md.B=1.7687*10^8*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=0.2*ones(md.numberofgrids,1); %10m/a
+	md.melting=0*ones(md.numberofgrids,1); %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic1/runme.m
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic1/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic1/runme.m	(revision 16)
@@ -0,0 +1,15 @@
+%Test on the diagnostic model and the prognostic in 2d
+
+%tests 3 and 4: using Glen's flow law
+md=model;
+md=mesh(md,'DomainOutline.exp',5100); %test3
+%md=mesh(md,'DomainOutline.exp',3550); %test4
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all'); %MacAyeal's model and 2d
+
+%Compute solution for MacAyeal's model 
+md=solve(md,'diagnostic','ice');
+
+%plot results
+plotmodel(md,'data','vx','data','vy','contourlevels',{0,20,40,-20,-40},'contourlevels',{-100,-200,-300,-400,-500,-600})
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic2/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic2/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic2/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+200000 0
+200000 200000
+0 200000 
+0 0
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic2/Front.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic2/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic2/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic2/README
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic2/README	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic2/README	(revision 16)
@@ -0,0 +1,18 @@
+Test on an idealized geometry 
+
+Diagnostic equations:
+To launch this test, use runme
+
+tests 5 and 6:
+A=5.7*10^-19 Pa^-3.a^-1 -> B=1.7687*10^8 Pa.s^1/3
+
+density 5100 -> 1488 grids and 2839 elements
+dentity 3550 -> 3221 grids and 6232 elements
+
+the upper boundary condition is now
+pos=find(md.y==200000); %grids on the upper boundary condition
+md.dirichletvalues_diag(pos,2)=400*(((md.x(pos)-100000)/25000).^2-ones(size(pos,1),1)).*heaviside((1+eps)*ones(size(pos,1),1)-((md.x(pos)-100000)/25000).^2);
+
+We first find all the grids on the upper boundary condition.
+Then we modify the velocity in the y direction to model an icestream.
+We used 1+eps instead of 1 in the heaiviside function to avoid the case of 0, since Matlab return NaN for the value of 0.
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic2/Square.par
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic2/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic2/Square.par	(revision 16)
@@ -0,0 +1,125 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.81;
+	md.rho_ice=917;
+	md.rho_water=1028;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=500*ones(md.numberofgrids,1);
+	md.firn_layer=0*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	%md.B=paterson(md.observed_temperature);
+	md.B=1.7687*10^8*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=0.2*ones(md.numberofgrids,1); %10m/a
+	md.melting=0*ones(md.numberofgrids,1); %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	pos=find(md.y==max(md.y)); %grids on the upper boundary condition
+	md.dirichletvalues_diag(pos,2)=400*(((md.x(pos)-100000)/25000).^2-ones(size(pos,1),1)).*heaviside((1+eps)*ones(size(pos,1),1)-((md.x(pos)-100000)/25000).^2);
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/EISMINT/Diagnostic2/runme.m
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Diagnostic2/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Diagnostic2/runme.m	(revision 16)
@@ -0,0 +1,15 @@
+%Test on the diagnostic model and the prognostic in 2d
+
+%test 5 and 6 : 
+md=model;
+md=mesh(md,'DomainOutline.exp',5100); %test3
+%md=mesh(md,'DomainOutline.exp',3550); %test4
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all'); %MacAyeal's model and 2d
+
+%Compute solution for MacAyeal's model 
+md=solve(md,'diagnostic','ice');
+
+%plot results
+plotmodel(md,'data','vx','data','vy','contourlevels',{0,20,40,-20,-40,-60,60},'contourlevels',{-100,-200,-300,-400,-500,-600,-700,-800})
Index: /issm/trunk/test/Validation/EISMINT/MassConservation/CrossLine.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/MassConservation/CrossLine.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/MassConservation/CrossLine.exp	(revision 16)
@@ -0,0 +1,7 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+2 1.
+# X pos Y pos
+10000 199999 
+10000 1
Index: /issm/trunk/test/Validation/EISMINT/MassConservation/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/MassConservation/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/MassConservation/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+200000 0
+200000 200000
+0 200000 
+0 0
Index: /issm/trunk/test/Validation/EISMINT/MassConservation/Front.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/MassConservation/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/MassConservation/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/EISMINT/MassConservation/README
===================================================================
--- /issm/trunk/test/Validation/EISMINT/MassConservation/README	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/MassConservation/README	(revision 16)
@@ -0,0 +1,18 @@
+Test on an idealized geometry 
+Mass conservation
+To launch this test, use runme
+
+The velocity is fixed everywhere with:
+u=0, v=-400m/yr
+The thickness is initialised with 500m everywhere (in hydrostatic equilibrium)
+
+The upper boundary (y=20000) is a dirichlet for prognostic model. 
+Tis thickness has to evolve with time. So you have to add these two lines in the icetransient2d.m just before running the iceprognostic_core
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+pos=find(m_p.ys~=0);
+m_p.ys(pos)=500+500/5*sin(2*pi*time/(200*md.yts))*ones(size(pos,1),1);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ 
+The propagation of the signal is attenuated with time, a little bit less if there is no artificial diffusivity.
+One can usethe CrossLine to see precisely the thickness in the middle of the iceshelf.
Index: /issm/trunk/test/Validation/EISMINT/MassConservation/Square.par
===================================================================
--- /issm/trunk/test/Validation/EISMINT/MassConservation/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/MassConservation/Square.par	(revision 16)
@@ -0,0 +1,134 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.81;
+	md.rho_ice=917;
+	md.rho_water=1028;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=500*ones(md.numberofgrids,1);
+	md.firn_layer=0*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	%md.B=paterson(md.observed_temperature);
+	md.B=1.7687*10^8*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=0.0*ones(md.numberofgrids,1); %10m/a
+	md.melting=0*ones(md.numberofgrids,1); %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	%analytical test
+	pos=find(md.y==200000); %grids on the upper boundary condition
+	md.gridondirichlet_diag=ones(md.numberofgrids,1);
+	md.dirichletvalues_diag(:,1)=0;
+	md.dirichletvalues_diag(:,2)=-400;
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	%analytical test
+	pos=find(md.y==200000); %grids on the upper boundary condition
+	md.gridondirichlet_prog(pos)=1;
+	md.dirichletvalues_prog(pos)=500;
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/EISMINT/MassConservation/runme.m
===================================================================
--- /issm/trunk/test/Validation/EISMINT/MassConservation/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/MassConservation/runme.m	(revision 16)
@@ -0,0 +1,26 @@
+%This test is a test from the EISMINT for Ice shelves 
+% Vincent Rommelaere 1996
+
+%The goal is to test the prognostic model
+md=model;
+md=mesh(md,'DomainOutline.exp',4550);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+%Evolution of the ice shelf
+md.ndt=500*md.yts;
+md.dt=5*md.yts;
+md.artificial_diffusivity=0; %Better result with no artificial diffusivity
+
+%launch transient solution
+md=solve(md,'transient');
+
+%plot results
+plotmodel(md,'data',md.transient_results(end).thickness,'sectionvalue','CrossLine.exp')
+
+%Don't forget to add these lines in icetransient2d.m, just before the computation of the thickness to change the thickness on the upper boundary condition
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%pos=find(m_p.ys~=0);
+%m_p.ys(pos)=500+500/5*sin(2*pi*time/(200*md.yts))*ones(size(pos,1),1);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Index: /issm/trunk/test/Validation/EISMINT/README
===================================================================
--- /issm/trunk/test/Validation/EISMINT/README	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/README	(revision 16)
@@ -0,0 +1,14 @@
+These tests corresponds to the EISMINT tests proposed by Vincent Rommelaere in 1996.
+
+The description of the tests and some results are detailed in description_EISMINT.pdf
+
+The test MassConservation is to a square ice shelf whose velocity is fixed everywhere.
+The thickness at one boundary is fluctuating and we want to see if this evolution is propagated correctly.
+
+The test Diagnostic1 deals with a Square ice shelf fixed with dirichlet values on three borders and an ice front on 
+the last one. This test corresponds to tests 3 and 4 in the section: Diagnostic Equations of the document.
+
+The test Diagnostic2 deals with a Square ice shelf as in Diagnostic1 but one boundary condition is changed to
+account an ice tream entering the ice shelf. This test corresponds to tests 3 and 4 in the section: Diagnostic Equations 
+
+The test Transient is the evolution of Diagnostic2 during 5000 years. It corresponds to the section Coupled model of ice shelf flow.
Index: /issm/trunk/test/Validation/EISMINT/Transient/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Transient/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Transient/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+200000 0
+200000 200000
+0 200000 
+0 0
Index: /issm/trunk/test/Validation/EISMINT/Transient/Front.exp
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Transient/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Transient/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/EISMINT/Transient/README
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Transient/README	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Transient/README	(revision 16)
@@ -0,0 +1,13 @@
+Test on an idealized geometry 
+
+Coupled model of ice shelf flow
+
+For this test you can add a dirichlet value for the thickness of the upper boundary condition like this:
+%Evolution of the ice shelf
+pos=find(md.y==200000); %grids on the upper boundary condition
+md.gridondirichlet_prog(pos)=1;
+md.dirichletvalues_prog(pos)=500;
+md.ndt=5000*md.yts;
+md.dt=500*md.yts;
+
+The ice shelf seems to stabilize around 5000 years.
Index: /issm/trunk/test/Validation/EISMINT/Transient/Square.par
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Transient/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Transient/Square.par	(revision 16)
@@ -0,0 +1,129 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.81;
+	md.rho_ice=917;
+	md.rho_water=1028;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=500*ones(md.numberofgrids,1);
+	md.firn_layer=0*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	%md.B=paterson(md.observed_temperature);
+	md.B=1.7687*10^8*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=0.2*ones(md.numberofgrids,1); %10m/a
+	md.melting=0*ones(md.numberofgrids,1); %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	pos=find(md.y==max(md.y)); %grids on the upper boundary condition
+	md.dirichletvalues_diag(pos,2)=400*(((md.x(pos)-100000)/25000).^2-ones(size(pos,1),1)).*heaviside((1+eps)*ones(size(pos,1),1)-((md.x(pos)-100000)/25000).^2);
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(md.y==max(md.y)); %grids on the upper boundary condition
+	md.gridondirichlet_prog(pos)=1;
+	md.dirichletvalues_prog(pos)=500;
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/EISMINT/Transient/runme.m
===================================================================
--- /issm/trunk/test/Validation/EISMINT/Transient/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/EISMINT/Transient/runme.m	(revision 16)
@@ -0,0 +1,19 @@
+%Test on the diagnostic model and the prognostic in 2d
+
+%Evolution of the ice shelf
+md=model;
+md=mesh(md,'DomainOutline.exp',7100);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all'); %MacAyeal's model and 2d
+
+%Compute solution for MacAyeal's model 
+md=solve(md,'diagnostic','ice');
+
+%Launch transient solution
+md.ndt=5000*md.yts; %time of evolution
+md.dt=500*md.yts; %time vetween two iterations
+md=solve(md,'transient');
+
+%plot results
+plotmodel(md,'data',md.transient_results(end).vx,'data',md.transient_results(end).vy,'data',md.transient_results(end).thickness)
Index: /issm/trunk/test/Validation/ISMIP/README
===================================================================
--- /issm/trunk/test/Validation/ISMIP/README	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/README	(revision 16)
@@ -0,0 +1,11 @@
+These tests correspond to the ISMIP-HOM (Higher Order Models) tests proposed by Frank Pattyn and Tony Payne in 2006.
+
+The decription of the tests and some results are detailed in description.pdf.
+
+They all use a square ice sheets except TestE that is an application in 2d to a real glacier.
+
+The bed of TestA and TestB is frozen whereas a sliding law is applies in TestC and TestD to check the friction law.
+Files Square.par contain all the parameters for the tests.
+
+The domain of the square ice sheets can be changed to compare the results with the results of the intercomparison project.
+Many results are given in results.pdf.
Index: /issm/trunk/test/Validation/ISMIP/TestA/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestA/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestA/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/ISMIP/TestA/README
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestA/README	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestA/README	(revision 16)
@@ -0,0 +1,4 @@
+TestA is a test on a square ice sheet.
+The bed is definied as a series of sinusoidal bumps in x and y.
+The bed is frozen everywhere so the velocity is zero on the bed.
+Periodic boundary conditions are applied on the boundary.
Index: /issm/trunk/test/Validation/ISMIP/TestA/Square.par
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestA/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestA/Square.par	(revision 16)
@@ -0,0 +1,129 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=910;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_abs=NaN;
+	md.eps_rel=0.01;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+	md.viscosity_overshoot=0;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	md.surface=-md.x*tan(0.5*pi/180);
+	md.bed=md.surface-1000+500*sin(md.x*2*pi/max(md.x)).*sin(md.y*2*pi/max(md.x));
+	md.thickness=md.surface-md.bed;
+	md.firn_layer=0*ones(md.numberofgrids,1);
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=6.8067*10^7*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	%Create grid on boundary fist (because wi can not use mesh)
+	md.gridonboundary=zeros(md.numberofgrids,1);
+	pos=find(md.x==0 | md.y==0 | md.x==max(md.x) | md.y==max(md.y));
+	md.gridonboundary(pos)=1;
+
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_diag=md.segments(pos,:);
+	md.segmentonneumann_diag=zeros(0,3);
+	%md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog=md.segments(pos,:);
+	md.segmentonneumann_prog=zeros(0,3);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog2=md.segments(pos,:);
+	md.segmentonneumann_prog2=zeros(0,3);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ISMIP/TestA/runme.m
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestA/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestA/runme.m	(revision 16)
@@ -0,0 +1,38 @@
+%This test is a test from the ISMP-HOM Intercomparison project
+%Pattyn and Payne 2006
+
+%TestA 
+L=80000; %in m
+nx=20; %numberof nodes in x direction
+ny=20;
+md=model;
+md=squaremesh(md,L,L,nx,ny);
+md=geography(md,'',''); %ice sheet test
+md=parameterize(md,'Square.par');
+md=extrude(md,10,1);
+
+%Create dirichlet on the bed on top of the borders
+pos=find(md.gridonbed);
+md.gridondirichlet_diag(pos)=1;
+
+md=setelementstype(md,'pattyn','all');
+%md=setelementstype(md,'pattyn','all','stokes','all'); 
+
+%Create dirichlet on the bed only
+md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+pos=find(md.gridonbed);
+md.gridondirichlet_diag(pos)=1;
+
+%Create MPCs to have periodic boundary conditions
+posx=find(md.x==0);
+posx2=find(md.x==max(md.x));
+
+posy=find(md.y==0 & md.x~=0 & md.x~=max(md.x)); %Don't take the same grids two times
+posy2=find(md.y==max(md.y) & md.x~=0 & md.x~=max(md.x));
+
+md.penalties=[posx,posx2;posy,posy2];
+
+%Compute the diagnostic
+md=solve(md,'diagnostic','ice');
+
+plotmodel(md,'data','vx','data','vy','data','vz','layer#all',md.numlayers,'contourlevels',{9.2,18.4,27.6,46,73.6,82.8},'contourlevels',{0,-1.2,-0.9,-0.6,-0.3,1.2},'contourlevels',{-5.2,-3.9,-1.3,0,1.3,3.9,5.2})
Index: /issm/trunk/test/Validation/ISMIP/TestB/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestB/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestB/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/ISMIP/TestB/README
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestB/README	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestB/README	(revision 16)
@@ -0,0 +1,4 @@
+TestB is a test on a square ice sheet.
+The bed is definied as a sinusoidal bumps in x direction (the bed does not vary with y).
+The bed is frozen everywhere so the velocity is zero on the bed.
+Periodic boundary conditions are applied on the boundary.
Index: /issm/trunk/test/Validation/ISMIP/TestB/Square.par
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestB/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestB/Square.par	(revision 16)
@@ -0,0 +1,129 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=910;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_abs=NaN;
+	md.eps_rel=0.01;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+	md.viscosity_overshoot=0;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	md.surface=-md.x*tan(0.5*pi/180);
+	md.bed=md.surface-1000+500*sin(md.x*2*pi/max(md.x));
+	md.thickness=md.surface-md.bed;
+	md.firn_layer=0*ones(md.numberofgrids,1);
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=6.8067*10^7*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	%Create grid on boundary fist (because wi can not use mesh)
+	md.gridonboundary=zeros(md.numberofgrids,1);
+	pos=find(md.x==0 | md.y==0 | md.x==max(md.x) | md.y==max(md.y));
+	md.gridonboundary(pos)=1;
+
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_diag=md.segments(pos,:);
+	md.segmentonneumann_diag=zeros(0,3);
+	%md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog=md.segments(pos,:);
+	md.segmentonneumann_prog=zeros(0,3);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog2=md.segments(pos,:);
+	md.segmentonneumann_prog2=zeros(0,3);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ISMIP/TestB/runme.m
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestB/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestB/runme.m	(revision 16)
@@ -0,0 +1,38 @@
+%This test is a test from the ISMP-HOM Intercomparison project
+%Pattyn and Payne 2006
+
+%TestB 
+L=80000; %in m
+nx=20; %numberof nodes in x direction
+ny=20;
+md=model;
+md=squaremesh(md,L,L,nx,ny);
+md=geography(md,'',''); %ice sheet test
+md=parameterize(md,'Square.par');
+md=extrude(md,10,1);
+
+%Create dirichlet on the bed on top of the boundary
+pos=find(md.gridonbed);
+md.gridondirichlet_diag(pos)=1;
+
+%md=setelementstype(md,'pattyn','all','stokes','all'); 
+md=setelementstype(md,'pattyn','all');
+
+%Create dirichlet on the bed only
+md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+pos=find(md.gridonbed);
+md.gridondirichlet_diag(pos)=1;
+
+%Create MPCs to have periodic boundary conditions
+posx=find(md.x==0);
+posx2=find(md.x==max(md.x));
+
+posy=find(md.y==0 & md.x~=0 & md.x~=max(md.x)); %Don't take the same grids two times
+posy2=find(md.y==max(md.y) & md.x~=0 & md.x~=max(md.x));
+
+md.penalties=[posx,posx2;posy,posy2];
+
+%Compute the diagnostic
+md=solve(md,'diagnostic','ice');
+
+plotmodel(md,'data','vx','data','vy','data','vz','layer#all',md.numlayers)
Index: /issm/trunk/test/Validation/ISMIP/TestC/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestC/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestC/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/ISMIP/TestC/README
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestC/README	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestC/README	(revision 16)
@@ -0,0 +1,6 @@
+TestC is a test on a square ice sheet.
+The bed is fla in this test, but the basal drag has sinusoidal bumps in x and y.
+To fit the model, we have to divide the drag coefficient by the effective pressure, 
+and to do so, the effective must be stricly positive everywhere so we moved up the surface.
+Periodic boundary conditions are applied on the boundaries.
+
Index: /issm/trunk/test/Validation/ISMIP/TestC/Square.par
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestC/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestC/Square.par	(revision 16)
@@ -0,0 +1,130 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=910;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_abs=NaN;
+	md.eps_rel=0.11;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+	md.viscosity_overshoot=0;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	md.surface=2000-md.x*tan(0.1*pi/180); %to have z>0
+	md.bed=md.surface-1000;
+	md.thickness=md.surface-md.bed;
+	md.firn_layer=0*ones(md.numberofgrids,1);
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=sqrt(md.yts.*(1000+1000*sin(md.x*2*pi/max(md.x)).*sin(md.y*2*pi/max(md.x)))./(md.g*(md.rho_ice*md.thickness+md.rho_water*md.bed)));
+
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=6.8067*10^7*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	%Create grid on boundary fist (because wi can not use mesh)
+	md.gridonboundary=zeros(md.numberofgrids,1);
+	pos=find(md.x==0 | md.y==0 | md.x==max(md.x) | md.y==max(md.y));
+	md.gridonboundary(pos)=1;
+
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_diag=md.segments(pos,:);
+	md.segmentonneumann_diag=zeros(0,3);
+	%md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog=md.segments(pos,:);
+	md.segmentonneumann_prog=zeros(0,3);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog2=md.segments(pos,:);
+	md.segmentonneumann_prog2=zeros(0,3);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ISMIP/TestC/runme.m
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestC/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestC/runme.m	(revision 16)
@@ -0,0 +1,35 @@
+%This test is a test from the ISMP-HOM Intercomparison project
+%Pattyn and Payne 2006
+
+%TestC 
+L=80000; %in m
+nx=20; %number of nodes in x direction
+ny=20;
+md=model;
+md=squaremesh(md,L,L,nx,ny);
+md=geography(md,'',''); %ice sheet test
+md=parameterize(md,'Square.par');
+md=extrude(md,10,1);
+
+md=setelementstype(md,'pattyn','all');
+%md=setelementstype(md,'pattyn','all','stokes','all'); 
+
+%Add dirichlet values on the corners (we need dirichlet somewhere
+md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+pos=find((md.x==0 |md.x==L) & (md.y==0 | md.y==L));
+%pos=find((md.x==0 |md.x==L | md.y==0 | md.y==L)); %dirichlet on all the boundaries
+md.gridondirichlet_diag(pos)=1;
+
+%Create MPCs to have periodic boundary conditions
+posx=find(md.x==0);
+posx2=find(md.x==L);
+
+posy=find(md.y==0 & md.x~=0 & md.x~=L); %Don't take the same grids two times
+posy2=find(md.y==L & md.x~=0 & md.x~=L);
+
+md.penalties=[posx,posx2;posy,posy2];
+
+%Compute the diagnostic
+md=solve(md,'diagnostic','ice');
+
+plotmodel(md,'data','vx','data','vy','data','vz','layer#all',md.numlayers,'contourlevels',{10.878,16.317,21.756,43.51,59.829},'contourlevels',{-2.421,-1.614,-0.807,3.228},'contourlevels',{-2.48,-1.86,0,0.62,1.24,1.86,2.48})
Index: /issm/trunk/test/Validation/ISMIP/TestD/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestD/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestD/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/ISMIP/TestD/README
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestD/README	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestD/README	(revision 16)
@@ -0,0 +1,5 @@
+TestD is a test on a square ice sheet.
+The bed is flat as in TestC, but the basal drag has sinusoidal variations in x.
+To fit the model, we have to divide the drag coefficient by the effective pressure, 
+and to do so, the effective must be stricly positive everywhere so we moved up the surface.
+Periodic boundary conditions are applied on the boundaries.
Index: /issm/trunk/test/Validation/ISMIP/TestD/Square.par
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestD/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestD/Square.par	(revision 16)
@@ -0,0 +1,130 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=910;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_abs=NaN;
+	md.eps_rel=0.01;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+	md.viscosity_overshoot=0;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	md.surface=2000-md.x*tan(0.1*pi/180); %to have z>0
+	md.bed=md.surface-1000;
+	md.thickness=md.surface-md.bed;
+	md.firn_layer=0*ones(md.numberofgrids,1);
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=sqrt(md.yts.*(1000+1000*sin(md.x*2*pi/max(md.x)))./(md.g*(md.rho_ice*md.thickness+md.rho_water*md.bed)));
+
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=6.8067*10^7*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	%Create grid on boundary fist (because wi can not use mesh)
+	md.gridonboundary=zeros(md.numberofgrids,1);
+	pos=find(md.x==0 | md.y==0 | md.x==max(md.x) | md.y==max(md.y));
+	md.gridonboundary(pos)=1;
+
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_diag=md.segments(pos,:);
+	md.segmentonneumann_diag=zeros(0,3);
+	%md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog=md.segments(pos,:);
+	md.segmentonneumann_prog=zeros(0,3);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog2=md.segments(pos,:);
+	md.segmentonneumann_prog2=zeros(0,3);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ISMIP/TestD/runme.m
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestD/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestD/runme.m	(revision 16)
@@ -0,0 +1,40 @@
+%This test is a test from the ISMP-HOM Intercomparison project
+%Pattyn and Payne 2006
+
+%TestD 
+L=40000; %in m
+nx=45; %numberof nodes in x direction
+ny=45;
+md=model;
+md=squaremesh(md,L,L,nx,ny);
+md.z=zeros(md.numberofgrids,1);
+md=geography(md,'',''); %ice sheet test
+md=parameterize(md,'Square.par');
+md=extrude(md,10,1);
+
+md=setelementstype(md,'pattyn','all');
+%md=setelementstype(md,'pattyn','all','stokes','all'); 
+
+%No dirichlet in this model, just periodic boundary conditions
+md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+pos=find((md.x==0 |md.x==80000 ) & (md.y==0 | md.y==80000));
+md.gridondirichlet_diag(pos)=1;
+
+%We need one grd on dirichlet (in the middle)
+%md.gridondirichlet_diag(33)=1;
+%md.dirichletvalues_diag(1,:)=[18/md.yts -3/md.yts];
+
+%%Create MPCs to have periodic boundary conditions
+%posx=find(md.x==0);
+%posx2=find(md.x==max(md.x));
+%
+%posy=find(md.y==0 & md.x~=0 & md.x~=max(md.x)); %Don't take the same grids two times
+%posy2=find(md.y==max(md.y) & md.x~=0 & md.x~=max(md.x));
+%
+%md.penalties=[posx,posx2;posy,posy2];
+
+error
+%Compute the diagnostic
+md=solve(md,'diagnostic','ice');
+
+plotmodel(md,'data','vx','data','vy','data','vz','layer#all',md.numlayers)
Index: /issm/trunk/test/Validation/ISMIP/TestE/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestE/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestE/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 -1000
+-1000 1000
+201000 1000
+201000 -1000
+-1000 -1000
Index: /issm/trunk/test/Validation/ISMIP/TestE/README
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestE/README	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestE/README	(revision 16)
@@ -0,0 +1,6 @@
+TestE is a test on a real glacier with a 2d geometry.
+In the first case, bed is frozen everywhere so the velocity is zero on the bed.
+In the second case, there is slidind on a small part of the bed.
+
+Velocity and thickness are nul on the extremities of the glaciers.
+Penalties are added on the other boundary conditions in order to respect the 2d aspect of the model.
Index: /issm/trunk/test/Validation/ISMIP/TestE/Square.par
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestE/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestE/Square.par	(revision 16)
@@ -0,0 +1,141 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=910;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.lowmem=1;
+	md.eps_abs=NaN;
+	md.eps_rel=0.01;
+	md.penalty_offset=3;
+	md.penalty_melting=10^7;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+	md.viscosity_overshoot=0;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	data=load('data.mat');
+	data=data.data;
+	md.surface=zeros(md.numberofgrids,1);
+	md.bed=zeros(md.numberofgrids,1);
+	for i=1:md.numberofgrids
+		y=md.y(i);
+		point1=floor(y/100)+1;
+		point2=min(point1+1,51);
+		coeff=(y-(point1-1)*100)/100;
+		md.bed(i)=(1-coeff)*data(point1,2)+coeff*data(point2,2);
+		md.surface(i)=(1-coeff)*data(point1,3)+coeff*data(point2,3);
+	end
+	md.thickness=md.surface-md.bed;
+	md.firn_layer=0*ones(md.numberofgrids,1);
+	md.thickness(find(~md.thickness))=0.01;
+	md.bed=md.surface-md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=zeros(md.numberofgrids,1);
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=6.8067*10^7*ones(md.numberofgrids,1);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	%Create grid on boundary fist (because wi can not use mesh)
+	md.gridonboundary=zeros(md.numberofgrids,1);
+	pos=find(md.x==0 | md.y==0 | md.x==max(md.x) | md.y==max(md.y));
+	md.gridonboundary(pos)=1;
+
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.y==0 | md.y==max(md.y));md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_diag=md.segments(pos,:);
+	md.segmentonneumann_diag=zeros(0,3);
+	%md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog=md.segments(pos,:);
+	md.segmentonneumann_prog=zeros(0,3);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	%pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	%md.segmentonneumann_prog2=md.segments(pos,:);
+	md.segmentonneumann_prog2=zeros(0,3);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ISMIP/TestE/data.txt
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestE/data.txt	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestE/data.txt	(revision 16)
@@ -0,0 +1,52 @@
+0000 3200 3200 0
+0100 3163.89 3166.62 0
+0200 3122 3142 0
+0300 3072.97 3124.98 0
+0400 3023 3108 0
+0500 2976.14 3089.65 0
+0600 2938 3073 0
+0700 2913.63 3059 0
+0800 2895 3045 0
+0900 2876.69 3031 0
+1000 2861 3017 0
+1100 2851.82 3009.18 0
+1200 2843 3003 0
+1300 2830.07 2991.94 0
+1400 2816.00 2981 0
+1500 2800.45 2970.5 0
+1600 2783.00 2960.0 0
+1700 2757.07 2949.5 0
+1800 2733 2939 0
+1900 2718.92 2928.5 0
+2000 2705 2918 0
+2100 2690.41 2903.5 0
+2200 2676 2889 1
+2300 2666.89 2881.72 1
+2400 2663 2875 1
+2500 2663.37 2865.54 1
+2600 2663 2854 0
+2700 2655.89 2840.1 0
+2800 2648 2826 0
+2900 2645.67 2811.78 0
+3000 2641 2797 0
+3100 2628.12 2777.02 0
+3200 2613 2755 0
+3300 2595.88 2735.72 0
+3400 2581 2720 0
+3500 2575.02 2709.72 0
+3600 2571 2700 0
+3700 2563.61 2688.22 0
+3800 2557 2677 0
+3900 2553 2668 0
+4000 2549 2659 0
+4100 2544 2649 0
+4200 2539 2639 0
+4300 2534 2629 0
+4400 2529 2619 0
+4500 2524.50 2609.50 0
+4600 2520 2600 0
+4700 2515 2583.78 0
+4800 2510 2560 0
+4900 2505 2532.47 0
+5000 2500 2500 0
+
Index: /issm/trunk/test/Validation/ISMIP/TestE/runme.m
===================================================================
--- /issm/trunk/test/Validation/ISMIP/TestE/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ISMIP/TestE/runme.m	(revision 16)
@@ -0,0 +1,31 @@
+%This test is a test from the ISMP-HOM Intercomparison project
+%Pattyn and Payne 2006
+
+%TestE 
+Lx=10; %in m
+Ly=5000; %in m
+nx=3; %number of nodes in x direction
+ny=51;
+md=model;
+md=squaremesh(md,Lx,Ly,nx,ny);
+md=geography(md,'',''); %ice sheet test
+md=parameterize(md,'Square.par');
+md=extrude(md,10,1);
+
+md.gridondirichlet_diag(find(md.gridonbed))=1; %case 1: no slip
+%md.gridondirichlet_diag(find(md.gridonbed & (md.y<2200 | md.y> 2500)))=1; %case 2: slip between 2200 and 2500m
+
+%md=setelementstype(md,'pattyn','all');
+md=setelementstype(md,'pattyn','all','stokes','all'); 
+
+md.gridonstokes(find(md.x==0 | md.x==Lx))=0;
+%Create MPCs to have periodic boundary conditions
+posx=find(md.x==0);
+posx2=find(md.x==max(md.x));
+
+md.penalties=[posx,posx2];
+
+%Compute the diagnostic
+md=solve(md,'diagnostic','ice');
+
+plotmodel(md,'data','vx','data','vy','data','vz','layer#all',md.numlayers)
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Front.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Pattyn.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Pattyn.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Pattyn.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-10 -10
+1000010 -10
+1000010 1000010
+-10 1000010
+-10 -10
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Shelf.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Shelf.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Shelf.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:iceshelf
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1 -1
+1000001 -1
+1000001 1000001
+-1 1000001
+-1 -1
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Square.par
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/Square.par	(revision 16)
@@ -0,0 +1,122 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmin=300;
+	hmax=1000;
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness+10;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/runme.m
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test1_iceshelf/runme.m	(revision 16)
@@ -0,0 +1,60 @@
+% This file can be run to compare MacAyeal and Pattyn's model ie a 2d and a 3d model.
+% This test deals with a  mesh includind an iceshelf ans an icesheet. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'Shelf.exp','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'Macayeal','all');
+
+%Compute solution for a 2d model
+md=solve(md,'diagnostic','ice');
+vel_2d=md.vel;
+
+%Compute solution for a 3d model
+md=extrude(md,5,3);
+md=setelementstype(md,'Pattyn','Pattyn.exp','fill','Macayeal');
+md=solve(md,'diagnostic','ice');
+
+%Calculate the average velocity on each grid
+vel_3d=zeros(md.numberofgrids2d,1);
+grid_vel=0;
+
+for i=1:md.numberofgrids2d
+	for j=1:(md.numlayers-1)
+		grid_vel=grid_vel+1/(2*(md.numlayers-1))*(md.vel(i+j*md.numberofgrids2d,1)+md.vel(i+(j-1)*md.numberofgrids2d,1));
+	end
+	vel_3d(i,1)=grid_vel;
+	grid_vel=0;
+end
+
+vel_diff=(vel_2d-vel_3d)./vel_2d;
+vel_diff(find(vel_2d==vel_3d))=0;
+
+%Plot of the velocity from the macayeal and pattyn model 
+figure(1)
+subplot(2,2,1)
+p1=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_2d,'FaceColor','interp','EdgeColor','none');
+title('MacAyeal model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+   
+subplot(2,2,2)
+p2=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_3d,'FaceColor','interp','EdgeColor','none');
+title('Pattyn model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+
+subplot(2,2,3)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_diff*100,'FaceColor','interp','EdgeColor','none');
+title('Relative misfit [%]','FontSize',14,'FontWeight','bold')
+colorbar;
+
+subplot(2,2,4)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_2d-vel_3d,'FaceColor','interp','EdgeColor','none');
+title('Absolute misfit [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar;
+
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Front.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Pattyn.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Pattyn.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Pattyn.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-10 -10
+1000010 -10
+1000010 1000010
+-10 1000010
+-10 -10
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Square.par
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/Square.par	(revision 16)
@@ -0,0 +1,122 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmin=300;
+	hmax=1000;
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness+10;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=10*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/runme.m
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test2_icesheet/runme.m	(revision 16)
@@ -0,0 +1,60 @@
+% This file can be run to compare MacAyeal and Pattyn's model ie a 2d and a 3d model.
+% This test deals with a  mesh includind an iceshelf ans an icesheet. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+
+%Compute solution for a 2d model
+md=setelementstype(md,'Macayeal','all');
+md=solve(md,'diagnostic','ice');
+vel_2d=md.vel;
+
+%Compute solution for a 3d model
+md=extrude(md,5,3);
+md=setelementstype(md,'Pattyn','all');
+md=solve(md,'diagnostic','ice');
+
+%Calculate the average velocity on each grid
+vel_3d=zeros(md.numberofgrids2d,1);
+grid_vel=0;
+
+for i=1:md.numberofgrids2d
+	for j=1:(md.numlayers-1)
+		grid_vel=grid_vel+1/(2*(md.numlayers-1))*(md.vel(i+j*md.numberofgrids2d,1)+md.vel(i+(j-1)*md.numberofgrids2d,1));
+	end
+	vel_3d(i,1)=grid_vel;
+	grid_vel=0;
+end
+
+vel_diff=(vel_2d-vel_3d)./vel_2d;
+vel_diff(find(vel_2d==vel_3d))=0;
+
+%Plot of the velocity from the macayeal and pattyn model 
+figure(1)
+subplot(2,2,1)
+p1=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_2d,'FaceColor','interp','EdgeColor','none');
+title('MacAyeal model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+   
+subplot(2,2,2)
+p2=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_3d,'FaceColor','interp','EdgeColor','none');
+title('Pattyn model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+
+subplot(2,2,3)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_diff*100,'FaceColor','interp','EdgeColor','none');
+title('Relative misfit [%]','FontSize',14,'FontWeight','bold')
+colorbar;
+
+subplot(2,2,4)
+p4=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_2d-vel_3d,'FaceColor','interp','EdgeColor','none');
+title('Absolute misfit [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar;
+
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Front.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 500000
+-1000 1100000
+1100000 1100000
+1100000 500000
+-1000 500000
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Pattyn.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Pattyn.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Pattyn.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-10 -10
+1000010 -10
+1000010 1000010
+-10 1000010
+-10 -10
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Shelf.exp
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Shelf.exp	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Shelf.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:iceshelf
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1 600001
+1000001 600001
+1000001 1000001
+-1 1000001
+-1 600001
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Square.par
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/Square.par	(revision 16)
@@ -0,0 +1,122 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmin=300;
+	hmax=1000;
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness+10;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/runme.m
===================================================================
--- /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/MacAyealVsPattyn/test3_icesheet_iceshelf/runme.m	(revision 16)
@@ -0,0 +1,61 @@
+% This file can be run to compare MacAyeal and Pattyn's model ie a 2d and a 3d model.
+% This test deals with a  mesh includind an iceshelf ans an icesheet. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'Shelf.exp','');
+md=parameterize(md,'Square.par');
+
+%Compute solution for a 2d model
+md=setelementstype(md,'Macayeal','all');
+md=solve(md,'diagnostic','ice');
+vel_2d=md.vel;
+
+%Compute solution for a 3d model
+md=extrude(md,5,3);
+md=setelementstype(md,'Pattyn','all');
+md=solve(md,'diagnostic','ice');
+
+%Calculate the average velocity on each grid
+vel_3d=zeros(md.numberofgrids2d,1);
+grid_vel=0;
+
+for i=1:md.numberofgrids2d
+	for j=1:(md.numlayers-1)
+		grid_vel=grid_vel+1/(2*(md.numlayers-1))*(md.vel(i+j*md.numberofgrids2d,1)+md.vel(i+(j-1)*md.numberofgrids2d,1));
+	end
+	vel_3d(i,1)=grid_vel;
+	grid_vel=0;
+end
+
+vel_diff=(vel_2d-vel_3d)./vel_2d;
+vel_diff(find(vel_2d==vel_3d))=0;
+vel_diff(find(vel_2d==0))=0;
+
+%Plot of the velocity from the macayeal and pattyn model 
+figure(1)
+subplot(2,2,1)
+p1=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_2d,'FaceColor','interp','EdgeColor','none');
+title('MacAyeal model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+   
+subplot(2,2,2)
+p2=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_3d,'FaceColor','interp','EdgeColor','none');
+title('Pattyn model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+
+subplot(2,2,3)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+abs(vel_diff)*100,'FaceColor','interp','EdgeColor','none');
+title('Relative misfit [%]','FontSize',14,'FontWeight','bold')
+colorbar;
+
+subplot(2,2,4)
+p4=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_2d-vel_3d,'FaceColor','interp','EdgeColor','none');
+title('Absolute misfit [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar;
+
Index: /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Front.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Shelf.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Shelf.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Shelf.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:iceshelf
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1 -1
+1000001 -1
+1000001 1000001
+-1 1000001
+-1 -1
Index: /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Square.par
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/Square.par	(revision 16)
@@ -0,0 +1,122 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmin=300;
+	hmax=1000;
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/runme.m
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test1_iceshelf/runme.m	(revision 16)
@@ -0,0 +1,85 @@
+% This file can be run to compare MacAyeal and Pattyn's model ie a 2d and a 3d model.
+% This test deals with a  mesh includind an iceshelf ans an icesheet. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+%Compute solution for a Pattyn model
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'Shelf.exp','');
+md=parameterize(md,'Square.par');
+md=extrude(md,5,3);
+md=setelementstype(md,'Pattyn','all');
+
+md=solve(md,'diagnostic','ice');
+vel_pattyn=md.vel;
+vx_pattyn=md.vx;
+vy_pattyn=md.vy;
+vz_pattyn=md.vz;
+pressure_pattyn=md.pressure;
+
+mdpattyn=md;
+save modelpattyn mdpattyn;
+
+%Compute solution for a Stokes model
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'Shelf.exp','');
+md=parameterize(md,'Square.par');
+md=extrude(md,5,3);
+md=setelementstype(md,'Stokes','all','Pattyn','all');
+
+md=solve(md,'diagnostic','ice');
+vel_stokes=md.vel;
+vx_stokes=md.vx;
+vy_stokes=md.vy;
+vz_stokes=md.vz;
+pressure_stokes=md.pressure;
+
+mdstokes=md;
+save modelstokes mdstokes;
+
+error('debug')
+
+
+
+%Calculate the average velocity on each grid
+vel_3d=zeros(md.numberofgrids2d,1);
+grid_vel=0;
+
+for i=1:md.numberofgrids2d
+	for j=1:(md.numlayers-1)
+		grid_vel=grid_vel+1/(2*(md.numlayers-1))*(md.vel(i+j*md.numberofgrids2d,1)+md.vel(i+(j-1)*md.numberofgrids2d,1));
+	end
+	vel_3d(i,1)=grid_vel;
+	grid_vel=0;
+end
+
+vel_diff=(vel_2d-vel_3d)./vel_2d;
+vel_diff(find(vel_2d==vel_3d))=0;
+
+%Plot of the velocity from the stokes and pattyn model 
+figure(1)
+subplot(2,2,1)
+p1=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_pattyn,'FaceColor','interp','EdgeColor','none');
+title('MacAyeal model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+   
+subplot(2,2,2)
+p2=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_stokes,'FaceColor','interp','EdgeColor','none');
+title('Pattyn model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+
+subplot(2,2,3)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+(vel_pattyn-vel_stokes),'FaceColor','interp','EdgeColor','none');
+title('Relative misfit [%]','FontSize',14,'FontWeight','bold')
+colorbar;
+
+subplot(2,2,4)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+(vel_pattyn-vel_stokes)*100,'FaceColor','interp','EdgeColor','none');
+title('Absolute misfit [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar;
+
Index: /issm/trunk/test/Validation/PattynStokes/test2_icesheet/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test2_icesheet/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test2_icesheet/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/PattynStokes/test2_icesheet/Front.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test2_icesheet/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test2_icesheet/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/PattynStokes/test2_icesheet/Square.par
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test2_icesheet/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test2_icesheet/Square.par	(revision 16)
@@ -0,0 +1,121 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps=10;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmin=300;
+	hmax=1000;
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness+10;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/PattynStokes/test2_icesheet/runme.m
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test2_icesheet/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test2_icesheet/runme.m	(revision 16)
@@ -0,0 +1,85 @@
+% This file can be run to compare MacAyeal and Pattyn's model ie a 2d and a 3d model.
+% This test deals with a  mesh includind an iceshelf ans an icesheet. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+%Compute solution for a Pattyn model
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,5,3);
+md=extrude(md,'Pattyn','all');
+
+md=solve(md,'diagnostic','ice');
+vel_pattyn=md.vel;
+vx_pattyn=md.vx;
+vy_pattyn=md.vy;
+vz_pattyn=md.vz;
+pressure_pattyn=md.pressure;
+
+mdpattyn=md;
+save modelpattyn mdpattyn;
+
+%Compute solution for a Stokes model
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,5,3);
+md=extrude(md,'Pattyn','all','Stokes','all');
+
+md=solve(md,'diagnostic','ice');
+vel_stokes=md.vel;
+vx_stokes=md.vx;
+vy_stokes=md.vy;
+vz_stokes=md.vz;
+pressure_stokes=md.pressure;
+
+mdstokes=md;
+save modelstokes mdstokes;
+
+error('debug')
+
+
+
+%Calculate the average velocity on each grid
+vel_3d=zeros(md.numberofgrids2d,1);
+grid_vel=0;
+
+for i=1:md.numberofgrids2d
+	for j=1:(md.numlayers-1)
+		grid_vel=grid_vel+1/(2*(md.numlayers-1))*(md.vel(i+j*md.numberofgrids2d,1)+md.vel(i+(j-1)*md.numberofgrids2d,1));
+	end
+	vel_3d(i,1)=grid_vel;
+	grid_vel=0;
+end
+
+vel_diff=(vel_2d-vel_3d)./vel_2d;
+vel_diff(find(vel_2d==vel_3d))=0;
+
+%Plot of the velocity from the stokes and pattyn model 
+figure(1)
+subplot(2,2,1)
+p1=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_pattyn,'FaceColor','interp','EdgeColor','none');
+title('MacAyeal model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+   
+subplot(2,2,2)
+p2=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_stokes,'FaceColor','interp','EdgeColor','none');
+title('Pattyn model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+
+subplot(2,2,3)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+(vel_pattyn-vel_stokes),'FaceColor','interp','EdgeColor','none');
+title('Relative misfit [%]','FontSize',14,'FontWeight','bold')
+colorbar;
+
+subplot(2,2,4)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+(vel_pattyn-vel_stokes)*100,'FaceColor','interp','EdgeColor','none');
+title('Absolute misfit [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar;
+
Index: /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Front.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Shelf.exp
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Shelf.exp	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Shelf.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:iceshelf
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1 600001
+1000001 600001
+1000001 1000001
+-1 1000001
+-1 600001
Index: /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Square.par
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/Square.par	(revision 16)
@@ -0,0 +1,122 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmin=300;
+	hmax=1000;
+	ymin=min(md.y);
+	ymax=max(md.y);
+	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=-di*md.thickness-2*10^(-4)*min(0,md.y-600000);
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperature');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/runme.m
===================================================================
--- /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/PattynStokes/test3_icesheet_iceshelf/runme.m	(revision 16)
@@ -0,0 +1,85 @@
+% This file can be run to compare MacAyeal and Pattyn's model ie a 2d and a 3d model.
+% This test deals with a  mesh includind an iceshelf ans an icesheet. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+%Compute solution for a Pattyn model
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'Shelf.exp','');
+md=parameterize(md,'Square.par');
+md=extrude(md,5,3);
+md=extrude(md,'Pattyn','all');
+
+md=solve(md,'diagnostic','ice');
+vel_pattyn=md.vel;
+vx_pattyn=md.vx;
+vy_pattyn=md.vy;
+vz_pattyn=md.vz;
+pressure_pattyn=md.pressure;
+
+mdpattyn=md;
+save modelpattyn mdpattyn;
+
+%Compute solution for a Stokes model
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'Shelf.exp','');
+md=parameterize(md,'Square.par');
+md=extrude(md,5,3);
+md=extrude(md,'Pattyn','all','Stokes','all');
+
+md=solve(md,'diagnostic','ice');
+vel_stokes=md.vel;
+vx_stokes=md.vx;
+vy_stokes=md.vy;
+vz_stokes=md.vz;
+pressure_stokes=md.pressure;
+
+mdstokes=md;
+save modelstokes mdstokes;
+
+error('debug')
+
+
+
+%Calculate the average velocity on each grid
+vel_3d=zeros(md.numberofgrids2d,1);
+grid_vel=0;
+
+for i=1:md.numberofgrids2d
+	for j=1:(md.numlayers-1)
+		grid_vel=grid_vel+1/(2*(md.numlayers-1))*(md.vel(i+j*md.numberofgrids2d,1)+md.vel(i+(j-1)*md.numberofgrids2d,1));
+	end
+	vel_3d(i,1)=grid_vel;
+	grid_vel=0;
+end
+
+vel_diff=(vel_2d-vel_3d)./vel_2d;
+vel_diff(find(vel_2d==vel_3d))=0;
+
+%Plot of the velocity from the stokes and pattyn model 
+figure(1)
+subplot(2,2,1)
+p1=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_pattyn,'FaceColor','interp','EdgeColor','none');
+title('MacAyeal model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+   
+subplot(2,2,2)
+p2=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_stokes,'FaceColor','interp','EdgeColor','none');
+title('Pattyn model [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar; 
+
+subplot(2,2,3)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+(vel_pattyn-vel_stokes),'FaceColor','interp','EdgeColor','none');
+title('Relative misfit [%]','FontSize',14,'FontWeight','bold')
+colorbar;
+
+subplot(2,2,4)
+p3=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+(vel_pattyn-vel_stokes)*100,'FaceColor','interp','EdgeColor','none');
+title('Absolute misfit [m/yr]','FontSize',14,'FontWeight','bold')
+colorbar;
+
Index: /issm/trunk/test/Validation/RoundIceSheet/Circ.par
===================================================================
--- /issm/trunk/test/Validation/RoundIceSheet/Circ.par	(revision 16)
+++ /issm/trunk/test/Validation/RoundIceSheet/Circ.par	(revision 16)
@@ -0,0 +1,129 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.81;
+	md.rho_ice=910;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	client_server_mode='no';
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.penalty_offset=3.5;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+	disp('      creating thickness');
+	hmin=0.01;
+	hmax=2756.7;
+	radius=(sqrt((md.x).^2+(md.y).^2));
+	radiusmax=max(radius);
+	md.thickness=hmin*ones(size(md.x,1),1)+hmax*(4*((1/2)^(4/3)*ones(size(md.x,1),1)-((radius)./(2*radiusmax)).^(4/3))).^(3/8);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=0*md.thickness;
+	md.surface=md.bed+md.thickness;
+
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=20*ones(md.numberofgrids,1); %q=1. %no drag is specified in the analytical solution
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperatures');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=6.81*10^(7)*ones(md.numberofgrids,1); %to have the same B as the analytical solution 
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=0.3*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	disp('      creating velocities');
+	constant=0.3;
+	md.vx_obs=constant/2*md.x.*(md.thickness).^-1;
+	md.vy_obs=constant/2*md.y.*(md.thickness).^-1;
+
+	%md.vx_obs=zeros(md.numberofgrids,1);
+	%md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=(sqrt((md.vx_obs).^2+(md.vy_obs).^2));
+	
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',1);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+	
+	radius=sqrt((md.x).*md.x+(md.y).*md.y);
+	pos=find(radius==min(radius));md.gridondirichlet_diag(pos)=1;
+	md.x(pos)=0; md.y(pos)=0; %the closest node to the center is changed to be exactly at the center
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model: ');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model: ');
+	md.melting=zeros(md.numberofgrids,1);
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperatures
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);
+	%md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/RoundIceSheet/CreateDomainOutline.m
===================================================================
--- /issm/trunk/test/Validation/RoundIceSheet/CreateDomainOutline.m	(revision 16)
+++ /issm/trunk/test/Validation/RoundIceSheet/CreateDomainOutline.m	(revision 16)
@@ -0,0 +1,27 @@
+function contour=CreateDomainOutline(numberofpoints,radius)
+%This funtion returns the coordinates of points on a circular domain. There is numberofpoints points
+%The radius of the circle is by default 1 but can change it.
+%Radius is the radius of the circular domain you wish to create
+
+if ((floor(numberofpoints)-numberofpoints)~=0)
+	error('domainoutline argument must be a positive integer')
+end
+
+if ((radius-abs(radius))~=0)
+	error('radius must be a positive number')
+end
+
+%Calculate the cartesians coordinates of the points
+x_list=ones(numberofpoints,1);
+y_list=ones(numberofpoints,1);
+
+theta=(0:2*pi/numberofpoints:2*pi*(1-1/numberofpoints))';
+
+x_list=radius*x_list.*cos(theta);
+y_list=radius*y_list.*sin(theta);
+
+contour.x=x_list;
+contour.y=y_list;
+contour.density=1;
+
+end
Index: /issm/trunk/test/Validation/RoundIceSheet/README
===================================================================
--- /issm/trunk/test/Validation/RoundIceSheet/README	(revision 16)
+++ /issm/trunk/test/Validation/RoundIceSheet/README	(revision 16)
@@ -0,0 +1,9 @@
+The aim of the directory is to compare the solution calculated with the model Ice and an analytic solution.
+
+The test deals with a round icesheet (circular domain) and an azimuthal symmetry.
+
+To launch the test, you have to run the file Comparison in Matlab.
+
+You can choose the precision of the domainoutline and of the mesh. To do that, open the file Comparison and change numberofgrids for the prcision of the domainoutline (it indicates the numberofgrids on the circular domain) and change the density (it refines the mech).
+
+
Index: /issm/trunk/test/Validation/RoundIceSheet/runme.m
===================================================================
--- /issm/trunk/test/Validation/RoundIceSheet/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/RoundIceSheet/runme.m	(revision 16)
@@ -0,0 +1,97 @@
+%The aim of this program is to compare a model with an analytical solution given in MacAyeal EISMINT : Lessons in Ice-Sheet Modeling
+%The constants used in the file circ.par are the ones used in the analytical solution.
+%This solution is valid for a circular contour
+
+%You can adjust the parameters numberofpoints and density to refine the mesh and check the precision of your solution. You can change the number of layers of the domain with the parameter layernumber.
+
+%To begin with the numerical model
+md=model;
+
+numberofgrids=20;
+density=190000;
+layernumber=4;
+
+%First we have to create the domain outline 
+contour=CreateDomainOutline(numberofgrids,750000);
+
+expgen('DomainOutline.exp',contour,1);
+md=mesh(md,'DomainOutline.exp',density)
+
+%move the closest node to the center
+[mini pos]=min(md.x.^2+md.y.^2);
+md.x(pos)=0;
+md.y(pos)=0;
+
+%Then we have to create the geography and the parameters of the mesh
+md=geography(md,'',''); %We can not test iceshelves nor ice rises with this analytical solution
+
+%We now create a file Front.exp needed to parameterize but the analytical solution can't support an icefront so this file is empty
+front=CreateDomainOutline(numberofgrids,1000000);
+
+expgen('Front.exp',front,1);
+
+md=parameterize(md,'Circ.par');
+
+%Calculation of the analytical 2d velocity field
+constant=0.3;
+vx_obs=constant/2*md.x.*(md.thickness).^-1;
+vy_obs=constant/2*md.y.*(md.thickness).^-1;
+vel_obs=(sqrt((md.vx_obs).^2+(md.vy_obs).^2));
+
+%We extrude the model to have a 3d model
+md=extrude(md,layernumber,3);
+md=setelementstype(md,'Pattyn','all');
+
+%Spc the grids on the bed
+pos=find(md.gridonbed);
+md.gridondirichlet_diag(pos)=1;
+
+%Now we can solve the problem 
+md=solve(md,'diagnostic','ice');
+
+%Calculate the depth averaged velocity field (2d):
+vel=zeros(md.numberofgrids2d,1);
+
+grid_vel=0;
+for i=1:md.numberofgrids2d
+	for j=1:(md.numlayers-1)
+		grid_vel=grid_vel+1/(2*(md.numlayers-1))*(sqrt(md.vx(i+j*md.numberofgrids2d,1).^2+md.vy(i+j*md.numberofgrids2d,1).^2)+sqrt(md.vx(i+(j-1)*md.numberofgrids2d,1).^2+md.vy(i+(j-1)*md.numberofgrids2d,1).^2));
+	end
+	vel(i,1)=grid_vel;
+	grid_vel=0;
+end
+
+%Plot of the velocity from the exact and calculated solutions
+figure(1)
+subplot(2,2,1)
+p=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel,'FaceColor','interp','EdgeColor','none');
+title('Modelled velocity','FontSize',14,'FontWeight','bold')
+colorbar; 
+caxis([0 200]);
+   
+subplot(2,2,2)
+p=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+vel_obs,'FaceColor','interp','EdgeColor','none');
+title('Analytical velocity','FontSize',14,'FontWeight','bold')
+colorbar; 
+caxis([0 200]);
+
+subplot(2,2,3)
+hold on;
+plot(sqrt((md.x(1:md.numberofgrids2d)).^2+(md.y(1:md.numberofgrids2d)).^2),vel,'r.');
+plot(sqrt((md.x2d).^2+(md.y2d).^2),vel_obs,'b.');
+title('Analytical vs calculated velocity','FontSize',14,'FontWeight','bold');
+xlabel('distance to the center of the icesheet [m]','FontSize',14,'FontWeight','bold');
+ylabel('velocity [m/yr]','FontSize',14,'FontWeight','bold');
+legend('calculated velocity','exact velocity');
+axis([0 750000 0 200]);
+hold off;
+
+subplot(2,2,4)
+p=patch('Faces',md.elements2d,'Vertices',[md.x2d md.y2d],'FaceVertexCData',...
+abs(vel-vel_obs)./vel_obs*100,'FaceColor','interp','EdgeColor','none');
+title('Relative misfit [%]','FontSize',14,'FontWeight','bold')
+colorbar;
+caxis([0 100]);
+
Index: /issm/trunk/test/Validation/ThermalTests/Melting/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Melting/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Melting/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/ThermalTests/Melting/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Melting/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Melting/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/ThermalTests/Melting/Square.par
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Melting/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Melting/Square.par	(revision 16)
@@ -0,0 +1,129 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	md.penalty_offset=5;
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmax=1000;
+	md.thickness=hmax*ones(md.numberofgrids,1)
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.surface=zeros(md.numberofgrids,1);
+	md.bed=-md.thickness;
+
+%	hmin=700;
+%	hmax=1000;
+%	ymin=min(md.y);
+%	ymax=max(md.y);
+%	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+%	md.firn_layer=10*ones(md.numberofgrids,1);
+%	md.surface=zeros(md.numberofgrids,1);
+%	md.bed=-md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperatures');
+	md.observed_temperature=(273.15)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=1*10^-3; %1 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ThermalTests/Melting/runme.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Melting/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Melting/runme.m	(revision 16)
@@ -0,0 +1,29 @@
+
+% This file can be run to check that the melting in simple conduction is correctly modeled.
+% There is no velocity (no advection) the only thermal boundary conditions are an imposed temperature
+% at upper surface and an impose flux at its base. The result must be a linear temperature from the upper to the lower
+% surface with an imposed slope (Geothermal flux). if it is not the case, something is thermal modeling has been changed...
+% Just run this file in Matlab, with a properly setup Ice code. 
+
+% Create model;
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,2,1);
+md=setelementstype(md,'Pattyn','all');
+thermalboundarycondition;
+
+%analytical results
+%melting heat = geothermal flux
+%Mb*L*rho=G   => Mb=G/L*rho
+melting=md.geothermalflux/(md.rho_ice*md.latentheat)*md.yts;
+
+%modeled  results
+md=solve(md,'thermalsteady');
+
+%plot results
+relative=abs((md.melting-melting)./melting)*100;
+relative(find(md.melting==melting))=0;
+plotmodel(md,'data','melting','title','modeled melting','data',melting,'title','analytical melting','data',md.melting-melting,'title','absolute error','data',relative,'title','relative error [%]','layer#all',1)
Index: /issm/trunk/test/Validation/ThermalTests/Melting/thermalboundarycondition.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Melting/thermalboundarycondition.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Melting/thermalboundarycondition.m	(revision 16)
@@ -0,0 +1,13 @@
+
+%Ok, start defining model BC 
+disp('      boundary conditions for thermal model ');
+if strcmp(md.type,'3d')
+%	pos2=find(md.elementonsurface); md.gridondirichlet_thermal(md.elements(pos2,4:6))=1; md.dirichletvalues_thermal(md.elements(pos2,4:6))=0;
+	md.vx=zeros(md.numberofgrids,1);
+	md.vy=zeros(md.numberofgrids,1);
+	md.vz=zeros(md.numberofgrids,1);
+	md.vel=zeros(md.numberofgrids,1);
+	md.pressure=zeros(md.numberofgrids,1);
+else
+	error('model must be 3d to be thermaly parameterized')
+end
Index: /issm/trunk/test/Validation/ThermalTests/Simpleadvection/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleadvection/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleadvection/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/ThermalTests/Simpleadvection/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleadvection/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleadvection/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/ThermalTests/Simpleadvection/Square.par
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleadvection/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleadvection/Square.par	(revision 16)
@@ -0,0 +1,121 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	%md.penalty_horiz=10^25; %penalty parameters for rifts
+	%md.penalty_vert=10^15; %penalty parameters for rifts
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmax=1000;
+	md.thickness=hmax*ones(md.numberofgrids,1);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.surface=zeros(md.numberofgrids,1);
+	md.bed=-md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperatures');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=0.1; %1 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ThermalTests/Simpleadvection/runme.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleadvection/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleadvection/runme.m	(revision 16)
@@ -0,0 +1,30 @@
+
+% This file can be run to check that the advection-diffusion  is correctly modeled.
+% There is u=v=0 and w=cst everywhere the only thermal boundary conditions are an imposed temperature
+% at upper surface and an impose flux at its base.
+% Just run this file in Matlab, with a properly setup Ice code. 
+
+% Create model;
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,20,1);   %NB: the more one extrudes, the better (10-> relative~0.35%, 20->0.1%, 30->0.05%)
+md=setelementstype(md,'Pattyn','all'); 
+thermalboundarycondition;
+
+%analytical results
+%d2T/dz2-w*rho_ice*c/k*dT/dz=0   T(surface)=0  T(bed)=10   => T=A exp(alpha z)+B
+alpha=0.1/md.yts*md.rho_ice*md.heatcapacity/md.thermalconductivity;   %alpha=w rho_ice c /k  and w=0.1m/an
+A=10/(exp(alpha*(-1000))-1);    %A=T(bed)/(exp(alpha*bed)-1)  with bed=-1000 T(bed)=10
+B=-A;
+md.observed_temperature=A*exp(alpha*md.z)+B;
+
+%modeled  results
+md=solve(md,'thermalsteady');
+
+%plot results
+relative=abs((md.temperature-md.observed_temperature)./md.observed_temperature)*100;
+relative(find(md.temperature==md.observed_temperature))=0;
+plotmodel(md,'data','temperature','title','modeled temperature','data','observed_temperature','view',3,'title','analytical temperature','view',3,'data',md.temperature-md.observed_temperature,'title','absolute error','view',3,'data',relative,'title','relative error [%]','view',3)
Index: /issm/trunk/test/Validation/ThermalTests/Simpleadvection/thermalboundarycondition.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleadvection/thermalboundarycondition.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleadvection/thermalboundarycondition.m	(revision 16)
@@ -0,0 +1,14 @@
+
+%Ok, start defining model BC 
+disp('      boundary conditions for thermal model ');
+if strcmp(md.type,'3d')
+	pos1=find(md.elementonbed);     md.gridondirichlet_thermal(md.elements(pos1,1:3))=1; md.dirichletvalues_thermal(md.elements(pos1,1:3))=10;
+	pos2=find(md.elementonsurface); md.gridondirichlet_thermal(md.elements(pos2,4:6))=1; md.dirichletvalues_thermal(md.elements(pos2,4:6))=0;
+	md.vx=zeros(md.numberofgrids,1);
+	md.vy=zeros(md.numberofgrids,1);
+	md.vz=0.1*ones(md.numberofgrids,1);
+	md.vel=sqrt( md.vx.^2+ md.vy.^2+ md.vz.^2);
+	md.pressure=zeros(md.numberofgrids,1);
+else
+	error('model must be 3d to be thermaly parameterized')
+end
Index: /issm/trunk/test/Validation/ThermalTests/Simpleconduction/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleconduction/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleconduction/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Shelf.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Shelf.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Shelf.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:iceshelf
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1 -1
+1000001 -1
+1000001 1000001
+-1 1000001
+-1 -1
Index: /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Square.par
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleconduction/Square.par	(revision 16)
@@ -0,0 +1,121 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	%md.penalty_horiz=10^25; %penalty parameters for rifts
+	%md.penalty_vert=10^15; %penalty parameters for rifts
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	h=1000;
+	md.thickness=h*ones(md.numberofgrids,1);
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.bed=zeros(md.numberofgrids,1);
+	md.surface=md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperatures');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=50*10^-3; %50 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ThermalTests/Simpleconduction/runme.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleconduction/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleconduction/runme.m	(revision 16)
@@ -0,0 +1,32 @@
+
+% This file can be run to check that the conduction is correctly modeled.
+% There is no velocity (no advection) the only thermal boundary conditions are an imposed temperature
+% at the lower and upper surface. The result must be a linear temperature from the upper to the lower
+% surface. if it is not the case, something is thermal modeling has been changed...
+% Just run this file in Matlab, with a properly setup Ice code. 
+
+% Create model;
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'Shelf.exp','');
+md=parameterize(md,'Square.par');
+md=extrude(md,11,1);
+md=setelementstype(md,'Pattyn','all');
+thermalboundarycondition;
+
+%analytical results
+%d2T/dz2=0 T(bed)=10 T(surface)=0  => T=10/thickness*z-10*surface/thickness
+%each layer of the 3d mesh must have a constant value
+Tlayer=10:-1:0;
+for layer=1:md.numlayers
+	md.observed_temperature((layer-1)*md.numberofgrids2d+1:layer*md.numberofgrids2d)=Tlayer(layer);
+end
+
+%modeled  results
+md=solve(md,'thermalsteady');
+
+%plot results
+relative=abs((md.temperature-md.observed_temperature)./md.observed_temperature)*100;
+relative(find(md.temperature==md.observed_temperature))=0;
+plotmodel(md,'data','temperature','title','modeled temperature','data','observed_temperature','view',3,'title','analytical temperature','view',3,'data',md.temperature-md.observed_temperature,'title','absolute error','view',3,'data',relative,'title','relative error [%]','view',3)
Index: /issm/trunk/test/Validation/ThermalTests/Simpleconduction/thermalboundarycondition.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simpleconduction/thermalboundarycondition.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simpleconduction/thermalboundarycondition.m	(revision 16)
@@ -0,0 +1,14 @@
+
+%Ok, start defining model BC 
+disp('      boundary conditions for thermal model ');
+if strcmp(md.type,'3d')
+	pos1=find(md.elementonbed);     md.gridondirichlet_thermal(md.elements(pos1,1:3))=1; md.dirichletvalues_thermal(md.elements(pos1,1:3))=10;
+	pos2=find(md.elementonsurface); md.gridondirichlet_thermal(md.elements(pos2,4:6))=1; md.dirichletvalues_thermal(md.elements(pos2,4:6))=0;
+	md.vx=zeros(md.numberofgrids,1);
+	md.vy=zeros(md.numberofgrids,1);
+	md.vz=zeros(md.numberofgrids,1);
+	md.vel=zeros(md.numberofgrids,1);
+	md.pressure=zeros(md.numberofgrids,1);
+else
+	error('model must be 3d to be thermaly parameterized')
+end
Index: /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/Front.exp
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/Front.exp	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/Square.par
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/Square.par	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/Square.par	(revision 16)
@@ -0,0 +1,130 @@
+
+%Ok, start defining model parameters here
+
+%material parameters
+	md.g=9.8;
+	md.rho_ice=917;
+	md.rho_water=1023;
+	di=md.rho_ice/md.rho_water;
+	md.yts=365*24*3600;
+	md.heatcapacity=2009;
+	md.thermalconductivity=2.2; %W/mK
+	md.beta=9.8*10^-8;
+
+%Solution parameters
+	%parallelization 
+	md.cluster='none';
+	md.np=2;
+	md.time=1;
+	md.exclusive=0;
+
+	%statics
+	md.eps_rel=0.01;
+	md.eps_abs=10;
+	%md.penalty_horiz=10^25; %penalty parameters for rifts
+	%md.penalty_vert=10^15; %penalty parameters for rifts
+	md.lowmem=1;
+	if md.numberofgrids<1000000,
+	md.sparsity=.001;
+	else
+	md.sparsity=.0001;
+	end
+
+	%dynamics
+	md.dt=1*md.yts; %1 year
+	md.ndt=md.dt*10; 
+	md.artificial_diffusivity=1;
+
+	%control
+	md.control_type={'drag'}; %'drag', 'B'
+	md.nsteps=5;
+	md.tolx=10^-4;
+	md.maxiter=20;
+	md.optscal=10;
+	md.fit='logarithmic'; %'absolute','relative','logarithmic'
+	md.meanvel=1000/md.yts; %1000 meters/year
+	md.epsvel=eps;
+
+
+	disp('      creating thickness');
+	hmax=1000;
+	md.thickness=hmax*ones(md.numberofgrids,1)
+	md.firn_layer=10*ones(md.numberofgrids,1);
+	md.surface=zeros(md.numberofgrids,1);
+	md.bed=-md.thickness;
+
+%	hmin=700;
+%	hmax=1000;
+%	ymin=min(md.y);
+%	ymax=max(md.y);
+%	md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+%	md.firn_layer=10*ones(md.numberofgrids,1);
+%	md.surface=zeros(md.numberofgrids,1);
+%	md.bed=-md.thickness;
+
+	disp('      creating velocities');
+	md.vx_obs=zeros(md.numberofgrids,1);
+	md.vy_obs=zeros(md.numberofgrids,1);
+	md.vel_obs=sqrt(md.vx_obs.^2+md.vy_obs.^2);
+	
+	disp('      creating drag');
+	md.drag_type=2; %0 none 1 plastic 2 viscous
+	md.drag=200*ones(md.numberofgrids,1); %q=1.
+	%Take care of iceshelves: no basal drag
+	pos=find(md.elementoniceshelf);
+	md.drag(md.elements(pos,:))=0;
+	md.p=ones(md.numberofelements,1);
+	md.q=ones(md.numberofelements,1);
+
+	disp('      creating temperatures');
+	md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+	disp('      creating flow law paramter');
+	md.B=paterson(md.observed_temperature);
+	md.n=3*ones(md.numberofelements,1);
+
+	disp('      creating accumulation rates');
+	md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+	md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+	%Deal with boundary conditions:
+	
+	disp('      boundary conditions for diagnostic model: ');
+	%Build gridonicefront, array of boundary grids belonging to the icefront:
+	gridinsideicefront=ArgusContourToMesh(md.elements,md.x,md.y,expread('Front.exp',1),'node',2);
+	gridonicefront=double(md.gridonboundary & gridinsideicefront);
+
+	md.gridondirichlet_diag=zeros(md.numberofgrids,1);
+	pos=find(md.gridonboundary & ~gridonicefront);md.gridondirichlet_diag(pos)=1;
+	md.dirichletvalues_diag=zeros(md.numberofgrids,2);
+
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_diag=md.segments(pos,:);
+	md.neumannvalues_diag=NaN*ones(length(md.segmentonneumann_diag),1); %dynamic boundary conditions (water pressure)
+
+	disp('      boundary conditions for prognostic model');
+	md.gridondirichlet_prog=zeros(md.numberofgrids,1);
+	md.dirichletvalues_prog=zeros(md.numberofgrids,1);
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog=md.segments(pos,:);
+	md.neumannvalues_prog=zeros(size(md.segmentonneumann_prog,1),1);
+	md.neumannvalues_prog(:)=NaN; %free radiation
+	
+	pos=find(gridonicefront(md.segments(:,1)) | gridonicefront(md.segments(:,2)));
+	md.segmentonneumann_prog2=md.segments(pos,:);
+	md.neumannvalues_prog2=zeros(size(md.segmentonneumann_prog2,1),1);
+	md.neumannvalues_prog2(:)=NaN; %free radiation
+	
+	disp('      boundary conditions for thermal model');
+	md.gridondirichlet_thermal=ones(md.numberofgrids,1); %surface temperature
+	md.dirichletvalues_thermal=md.observed_temperature;
+	md.geothermalflux=zeros(md.numberofgrids,1); 
+	pos=find(md.elementonicesheet);md.geothermalflux(md.elements(pos,:))=0.1; %1 mW/m^2
+
+
+	
+
+% Some Cielo code, ignore.
+if strcmp(md.cluster,'yes')
+	ServerDisconnect;
+end   
Index: /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/runme.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/runme.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/runme.m	(revision 16)
@@ -0,0 +1,29 @@
+
+% This file can be run to check that the geothermal flux in simple conduction is correctly modeled.
+% There is no velocity (no advection) the only thermal boundary conditions are an imposed temperature
+% at upper surface and an impose flux at its base. The result must be a linear temperature from the upper to the lower
+% surface with an imposed slope (Geothermal flux). if it is not the case, something is thermal modeling has been changed...
+% Just run this file in Matlab, with a properly setup Ice code. 
+
+% Create model;
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,11,1);
+md=setelementstype(md,'Pattyn','all');
+thermalboundarycondition;
+
+%analytical results
+%the result is linear with depth and is equal to 0 on the upper surface (See BC)
+%d2T/dz2=0  -k*dT/dz(bed)=G  T(surface)=0  => T=-G/k*(z-surface)
+md.observed_temperature=-0.1/md.thermalconductivity*md.z; %G=0.1 W/m2
+
+%modeled  results
+md=solve(md,'thermalsteady');
+
+%plot results
+relative=abs((md.temperature-md.observed_temperature)./md.observed_temperature)*100;
+relative(find(md.temperature==md.observed_temperature))=0;
+plotmodel(md,'data','temperature','title','modeled temperature','data','observed_temperature','view',3,'title','analytical temperature','view',3,'data',md.temperature-md.observed_temperature,'title','absolute error','view',3,'data',relative,'title','relative error [%]','view',3)
Index: /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/thermalboundarycondition.m
===================================================================
--- /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/thermalboundarycondition.m	(revision 16)
+++ /issm/trunk/test/Validation/ThermalTests/Simplegeothermalflux/thermalboundarycondition.m	(revision 16)
@@ -0,0 +1,13 @@
+
+%Ok, start defining model BC 
+disp('      boundary conditions for thermal model ');
+if strcmp(md.type,'3d')
+	pos2=find(md.elementonsurface); md.gridondirichlet_thermal(md.elements(pos2,4:6))=1; md.dirichletvalues_thermal(md.elements(pos2,4:6))=0;
+	md.vx=zeros(md.numberofgrids,1);
+	md.vy=zeros(md.numberofgrids,1);
+	md.vz=zeros(md.numberofgrids,1);
+	md.vel=zeros(md.numberofgrids,1);
+	md.pressure=zeros(md.numberofgrids,1);
+else
+	error('model must be 3d to be thermaly parameterized')
+end
Index: /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/Square.par
===================================================================
--- /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/Square.par	(revision 16)
@@ -0,0 +1,29 @@
+%Start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+md=SetIceShelfBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/runme.m
===================================================================
--- /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/runme.m	(revision 16)
@@ -0,0 +1,75 @@
+% This file can be run to check that the current version of Pattyn model is giving 
+% coherent results. This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test10_iceshelf_icefront_stokes: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all','stokes','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+vel_stokes=md.vel;
+
+%Load old velocities and compare with the new model
+load archive_stokes
+pos=find(archive_stokes-vel_stokes);
+error_vel=abs(norm((archive_stokes(pos)-vel_stokes(pos))./archive_stokes(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Stokes model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Stokes model are comform with the archive version'));
+end
+
+
+
+%Compute solution with Ice model
+md=solve(md,'thermalsteady','ice');
+temp_stokes=md.temperature;
+melting_stokes=md.melting;
+
+%Load old velocities and compare with the new model
+load archive_temperature
+post=find(archive_temperature-temp_stokes);
+error_temp=abs(norm((archive_temperature(post)-temp_stokes(post))./archive_temperature(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal model are comform with the archive version'));
+end
+
+%Load old velocities and compare with the new model
+load archive_melting
+post=find(archive_melting-melting_stokes);
+error_melting=abs(norm((archive_melting(post)-melting_stokes(post))./archive_melting(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
Index: /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test10_iceshelf_icefront_stokes/updatearchive.m	(revision 16)
@@ -0,0 +1,29 @@
+% This file can be run to update the velocity archives  of the test10.
+% This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all','stokes','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_stokes=md.vel;
+
+%Save the solution in the directory
+save archive_stokes archive_stokes
+
+%Compute solution with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the solution in the directory
+save archive_temperature archive_temperature
+save archive_melting archive_melting
Index: /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Pattyn.exp
===================================================================
--- /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Pattyn.exp	(revision 16)
+++ /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Pattyn.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+500001 0
+500001 1000001
+0 1000001
+0 0
Index: /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Square.par
===================================================================
--- /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Square.par	(revision 16)
@@ -0,0 +1,29 @@
+%Start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+md=SetIceShelfBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Stokes.exp
===================================================================
--- /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Stokes.exp	(revision 16)
+++ /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/Stokes.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+250000 500000
+750001 500000
+750001 1000001
+250000 1000001
+250000 500000
Index: /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/runme.m
===================================================================
--- /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/runme.m	(revision 16)
@@ -0,0 +1,74 @@
+% This file can be run to check that the current version of Pattyn model is giving 
+% coherent results. This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test11_penalties_iceshelf_allmodels: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','Pattyn.exp','fill','macayeal','stokes','Stokes.exp');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+velocity=md.vel;
+
+%Load old velocities and compare with the new model
+load archive_velocity 
+pos=find(archive_velocity-velocity);
+error_vel=abs(norm((archive_velocity(pos)-velocity(pos))./archive_velocity(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from diagnostic model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from diagnostic model are comform with the archive version'));
+end
+
+
+
+%Compute solution with Ice model
+md=solve(md,'thermalsteady','ice');
+temperature=md.temperature;
+melting_stokes=md.melting;
+
+%Load old temperatures and compare with the new model
+load archive_temperature
+post=find(archive_temperature-temperature);
+error_temp=abs(norm((archive_temperature(post)-temperature(post))./archive_temperature(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal model are comform with the archive version'));
+end
+
+
+%Load old melting and compare with the new model
+load archive_melting
+post=find(archive_melting-melting_stokes);
+error_melting=abs(norm((archive_melting(post)-melting_stokes(post))./archive_melting(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
Index: /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test11_penalties_iceshelf_allmodels/updatearchive.m	(revision 16)
@@ -0,0 +1,29 @@
+% This file can be run to update the velocity archives  of the test11.
+% This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','Pattyn.exp','fill','macayeal','stokes','Stokes.exp');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_velocity=md.vel;
+
+%Save the solution in the directory
+save archive_velocity  archive_velocity 
+
+%Compute solution with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the solution in the directory
+save archive_temperature archive_temperature
+save archive_melting archive_melting
Index: /issm/trunk/test/Verification/test1_icesheet_noicefront/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test1_icesheet_noicefront/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test1_icesheet_noicefront/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test1_icesheet_noicefront/Square.par
===================================================================
--- /issm/trunk/test/Verification/test1_icesheet_noicefront/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test1_icesheet_noicefront/Square.par	(revision 16)
@@ -0,0 +1,29 @@
+%Ok, start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+%Deal with boundary conditions:
+md=SetIceSheetBC(md);
Index: /issm/trunk/test/Verification/test1_icesheet_noicefront/runme.m
===================================================================
--- /issm/trunk/test/Verification/test1_icesheet_noicefront/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test1_icesheet_noicefront/runme.m	(revision 16)
@@ -0,0 +1,100 @@
+
+% This file can be run to check that the current version of macayeal and ice models are giving 
+% coherent results. This test deals with an icesheet without icefront for a 2d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test1_icesheet_noicefront: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+%Compute solution with MacAyeal's model
+md=solve(md,'diagnostic','macayeal');
+vel_macayeal=md.vel;
+
+%Compute solution with Ice model
+md.acceleration=0;
+md=solve(md,'diagnostic','ice');
+vel_ice=md.vel;
+
+%Compute solution with accelerated Ice model
+md.acceleration=1;
+md=solve(md,'diagnostic','ice');
+vel_acc=md.vel;
+
+%Compute solution with Hutter elements in Ice model
+md=setelementstype(md,'hutter','all');
+md=solve(md,'diagnostic','ice');
+vel_hutter=md.vel;
+
+
+%Load old velocities and compare with the new model
+
+%Macayeal
+load archive_macayeal
+pos=find(archive_macayeal-vel_macayeal);
+error_vel=abs(norm((archive_macayeal(pos)-vel_macayeal(pos))./archive_macayeal(pos),2));
+
+disp(sprintf('numerical difference between old and new version of MacAyeal is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR.  Results from MacAyeal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from MacAyeal model are comform with the archive version'));
+end
+
+%Ice
+load archive_ice
+pos=find(archive_ice-vel_ice);
+error_vel=abs(norm((archive_ice(pos)-vel_ice(pos))./archive_ice(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Ice model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Ice model are comform with the archive version'));
+end
+
+%Accelerated Ice
+load archive_acc
+pos=find(archive_acc-vel_acc);
+error_vel=abs(norm((archive_acc(pos)-vel_acc(pos))./archive_acc(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Accelerated Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Accelerated Ice model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Accelerated Ice model are comform with the archive version'));
+end
+
+%Ice with Hutter elements
+load archive_hutter
+pos=find(archive_hutter-vel_hutter);
+error_vel=abs(norm((archive_hutter(pos)-vel_hutter(pos))./archive_hutter(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Ice model with Hutter elements differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Ice model with Hutter elements are comform with the archive version'));
+end
+
Index: /issm/trunk/test/Verification/test1_icesheet_noicefront/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test1_icesheet_noicefront/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test1_icesheet_noicefront/updatearchive.m	(revision 16)
@@ -0,0 +1,44 @@
+% This file can be run to update the velocity archives  of the test1.
+% This test deals with an icesheet without icefront for a 2d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+%Compute solution with MacAyeal's model
+md=solve(md,'diagnostic','macayeal');
+archive_macayeal=md.vel;
+
+%Save the solution in the directory
+save archive_macayeal archive_macayeal
+
+%Compute solution with Ice model
+md.acceleration=0;
+md=solve(md,'diagnostic','ice');
+archive_ice=md.vel;
+
+%Save the solution in the directory
+save archive_ice archive_ice
+
+%Compute solution with accelerated Ice model
+md.acceleration=1;
+md=solve(md,'diagnostic','ice');
+archive_acc=md.vel;
+
+%Save the solution in the directory
+save archive_acc archive_acc
+
+%Compute solution with Hutter elements in Ice model
+md=setelementstype(md,'hutter','all');
+md=solve(md,'diagnostic','ice');
+archive_hutter=md.vel;
+
+%Save the solution in the directory
+save archive_hutter archive_hutter
+
Index: /issm/trunk/test/Verification/test2_icesheet_icefront/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test2_icesheet_icefront/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test2_icesheet_icefront/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test2_icesheet_icefront/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test2_icesheet_icefront/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test2_icesheet_icefront/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test2_icesheet_icefront/Hutter.exp
===================================================================
--- /issm/trunk/test/Verification/test2_icesheet_icefront/Hutter.exp	(revision 16)
+++ /issm/trunk/test/Verification/test2_icesheet_icefront/Hutter.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 500001
+0 500001
+0 0
Index: /issm/trunk/test/Verification/test2_icesheet_icefront/Square.par
===================================================================
--- /issm/trunk/test/Verification/test2_icesheet_icefront/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test2_icesheet_icefront/Square.par	(revision 16)
@@ -0,0 +1,39 @@
+%Start defining model parameters here
+
+%dynamics
+md.dt=1*md.yts; %1 year
+md.ndt=md.dt*10; 
+md.artificial_diffusivity=1;
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+disp('      creating accumulation rates');
+md.accumulation=ones(md.numberofgrids,1)/md.yts; %1m/a
+md.melting=0*ones(md.numberofgrids,1)/md.yts; %1m/a
+
+md=SetMarineIceSheetBC(md,'Front.exp');
+
Index: /issm/trunk/test/Verification/test2_icesheet_icefront/runme.m
===================================================================
--- /issm/trunk/test/Verification/test2_icesheet_icefront/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test2_icesheet_icefront/runme.m	(revision 16)
@@ -0,0 +1,115 @@
+% This file can be run to check that the current version of macayeal and ice models are giving 
+% coherent results. This test deals with an icesheet with icefront for a 2d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test2_icesheet_icefront: '; 
+
+% Create model;
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+%Compute solution with MacAyeal's model
+md=solve(md,'diagnostic','macayeal');
+vel_macayeal=md.vel;
+
+%Compute solution with Ice model
+md.acceleration=0;
+md=solve(md,'diagnostic','ice');
+vel_ice=md.vel;
+
+%Compute solution with accelerated Ice model
+md.acceleration=1;
+md=solve(md,'diagnostic','ice');
+vel_acc=md.vel;
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+thickness=md.new_thickness;
+
+%Compute solution with Hutter and MacAyeal elements in Ice model
+md=setelementstype(md,'fill','macayeal','Hutter','Hutter.exp');
+md=solve(md,'diagnostic','ice');
+vel_hutter=md.vel;
+
+
+
+%Load old velocities and compare with the new model
+
+%Macayeal
+load archive_macayeal
+pos=find(archive_macayeal-vel_macayeal);
+error_vel=abs(norm((archive_macayeal(pos)-vel_macayeal(pos))./archive_macayeal(pos),2));
+
+disp(sprintf('numerical difference between old and new version of MacAyeal is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR.  Results from MacAyeal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from MacAyeal model are comform with the archive version'));
+end
+
+%Ice
+load archive_ice
+pos=find(archive_ice-vel_ice);
+error_vel=abs(norm((archive_ice(pos)-vel_ice(pos))./archive_ice(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Ice model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Ice model are comform with the archive version'));
+end
+
+%Accelerated Ice
+load archive_acc
+pos=find(archive_acc-vel_acc);
+error_vel=abs(norm((archive_acc(pos)-vel_acc(pos))./archive_ice(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Accelerated Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Accelerated Ice model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Accelerated Ice model are comform with the archive version'));
+end
+
+%Ice prognostic
+load archive_thickness
+pos=find(archive_thickness-thickness);
+error_thickness=abs(norm((archive_thickness(pos)-thickness(pos))./archive_thickness(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_thickness));
+
+if (error_thickness>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from prognostic model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from prognostic model are comform with the archive version'));
+end
+
+%Ice with MacAyeal and Hutter elements
+load archive_hutter
+pos=find(archive_hutter-vel_hutter);
+error_vel=abs(norm((archive_hutter(pos)-vel_hutter(pos))./archive_ice(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Ice model with MacAyeal and Hutter elements differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Ice model with MacAyeal and Hutter elements are comform with the archive version'));
+end
Index: /issm/trunk/test/Verification/test2_icesheet_icefront/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test2_icesheet_icefront/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test2_icesheet_icefront/updatearchive.m	(revision 16)
@@ -0,0 +1,50 @@
+% This file can be run to update the velocity archives  of the test1.
+% This test deals with an icesheet with icefront for a 2d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+%Compute solution with MacAyeal's model
+md=solve(md,'diagnostic','macayeal');
+archive_macayeal=md.vel;
+
+%Save the solution in the directory
+save archive_macayeal archive_macayeal
+
+%Compute solution with Ice model
+md.acceleration=0;
+md=solve(md,'diagnostic','ice');
+archive_ice=md.vel;
+
+%Save the solution in the directory
+save archive_ice archive_ice
+
+%Compute solution with accelerated Ice model
+md.acceleration=1;
+md=solve(md,'diagnostic','ice');
+archive_acc=md.vel;
+
+%Save the solution in the directory
+save archive_acc archive_acc
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+archive_thickness=md.new_thickness;
+
+%Save the new thickness in the directory
+save archive_thickness archive_thickness
+
+%Compute solution with MacAyeal and Hutter elements in Ice model
+md=setelementstype(md,'fill','macayeal','Hutter','Hutter.exp');
+md=solve(md,'diagnostic','ice');
+archive_hutter=md.vel;
+
+%Save the solution in the directory
+save archive_hutter archive_hutter
Index: /issm/trunk/test/Verification/test3_iceshelf_icefront/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test3_iceshelf_icefront/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test3_iceshelf_icefront/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test3_iceshelf_icefront/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test3_iceshelf_icefront/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test3_iceshelf_icefront/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test3_iceshelf_icefront/Square.par
===================================================================
--- /issm/trunk/test/Verification/test3_iceshelf_icefront/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test3_iceshelf_icefront/Square.par	(revision 16)
@@ -0,0 +1,38 @@
+%Start defining model parameters here
+
+%dynamics
+md.dt=1*md.yts; %1 year
+md.ndt=md.dt*10; 
+md.artificial_diffusivity=1;
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+disp('      creating accumulation rate');
+md.accumulation=10*ones(md.numberofgrids,1);
+md.melting=0*ones(md.numberofgrids,1);
+
+md=SetIceShelfBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test3_iceshelf_icefront/runme.m
===================================================================
--- /issm/trunk/test/Verification/test3_iceshelf_icefront/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test3_iceshelf_icefront/runme.m	(revision 16)
@@ -0,0 +1,100 @@
+% This file can be run to check that the current version of macayeal and ice models are giving 
+% coherent results. This test deals with an iceshelf with icefront for a 2d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test3_iceshelf_icefront: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+%Compute solution with MacAyeal's model
+md=solve(md,'diagnostic','macayeal');
+vel_macayeal=md.vel;
+
+%Compute solution with Ice model
+md.acceleration=0;
+md=solve(md,'diagnostic','ice');
+vel_ice=md.vel;
+
+%Compute solution with accelerated Ice model
+md.acceleration=1;
+md=solve(md,'diagnostic','ice');
+vel_acc=md.vel;
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+thickness=md.new_thickness;
+
+
+
+%Load old velocities and compare with the new model
+
+%Macayeal
+load archive_macayeal
+pos=find(archive_macayeal-vel_macayeal);
+error_vel=abs(norm((archive_macayeal(pos)-vel_macayeal(pos))./archive_macayeal(pos),2));
+
+disp(sprintf('numerical difference between old and new version of MacAyeal is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR.  Results from MacAyeal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from MacAyeal model are comform with the archive version'));
+end
+
+%Ice
+load archive_ice
+pos=find(archive_ice-vel_ice);
+error_vel=abs(norm((archive_ice(pos)-vel_ice(pos))./archive_ice(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Ice model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Ice model are comform with the archive version'));
+end
+
+%Accelerated Ice
+load archive_acc
+pos=find(archive_acc-vel_acc);
+error_vel=abs(norm((archive_acc(pos)-vel_acc(pos))./archive_ice(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Accelerated Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Accelerated Ice model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Accelerated Ice model are comform with the archive version'));
+end
+
+%Ice prognostic
+load archive_thickness
+pos=find(archive_thickness-thickness);
+error_thickness=abs(norm((archive_thickness(pos)-thickness(pos))./archive_thickness(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_thickness));
+
+if (error_thickness>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from prognostic model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from prognostic model are comform with the archive version'));
+end
+
+
Index: /issm/trunk/test/Verification/test3_iceshelf_icefront/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test3_iceshelf_icefront/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test3_iceshelf_icefront/updatearchive.m	(revision 16)
@@ -0,0 +1,44 @@
+% This file can be run to update the velocity archives  of the test3.
+% This test deals with an iceshelf with icefront for a 2d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',50000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+%Compute solution with MacAyeal's model
+md=solve(md,'diagnostic','macayeal');
+archive_macayeal=md.vel;
+
+%Save the solution in the directory
+save archive_macayeal archive_macayeal
+
+%Compute solution with Ice model
+md.acceleration=0;
+md=solve(md,'diagnostic','ice');
+archive_ice=md.vel;
+
+%Save the solution in the directory
+save archive_ice archive_ice
+
+%Compute solution with accelerated Ice model
+md.acceleration=1;
+md=solve(md,'diagnostic','ice');
+archive_acc=md.vel;
+
+%Save the solution in the directory
+save archive_acc archive_acc
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+archive_thickness=md.new_thickness;
+
+%Save the new thickness in the directory
+save archive_thickness archive_thickness
+
+
Index: /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/Square.par
===================================================================
--- /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/Square.par	(revision 16)
@@ -0,0 +1,30 @@
+%Start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+%Deal with boundary conditions:
+md=SetIceSheetBC(md);
Index: /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/runme.m
===================================================================
--- /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/runme.m	(revision 16)
@@ -0,0 +1,94 @@
+% This file can be run to check that the current version of pattyn model is giving 
+% coherent results. This test deals with an icesheet without icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test4_icesheet_noicefront_3d: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+vel_pattyn=md.vel;
+
+%Load old velocities and compare with the new model
+load archive_pattyn
+pos=find(archive_pattyn);
+error_vel=abs(norm((archive_pattyn(pos)-vel_pattyn(pos))./archive_pattyn(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Pattyn model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Pattyn model are comform with the archive version'));
+end
+
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+temp_pattyn=md.temperature;
+melting_pattyn=md.melting;
+
+%Load old temperatures and compare with the new model
+load archive_temperature
+post=find(archive_temperature-temp_pattyn);
+error_temp=abs(norm((archive_temperature(post)-temp_pattyn(post))./archive_temperature(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal model are comform with the archive version'));
+end
+
+%Load old meltings and compare with the new model
+load archive_melting
+post=find(archive_melting);
+error_melting=abs(norm((archive_melting(post)-melting_pattyn(post))./archive_melting(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
+
+%Compute solution for Hutter elements only
+md=setelementstype(md,'hutter','all');
+md=solve(md,'diagnostic','ice');
+vel_hutter=md.vel;
+
+%Load old velocities for hutter and compare with the new model
+load archive_hutter
+pos=find(archive_hutter);
+error_vel=abs(norm((archive_hutter(pos)-vel_hutter(pos))./archive_hutter(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Hutter model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Hutter model are comform with the archive version'));
+end
+
+
Index: /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test4_icesheet_noicefront_3d/updatearchive.m	(revision 16)
@@ -0,0 +1,38 @@
+% This file can be run to update the velocity archives  of the test4.
+% This test deals with an icesheet without icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_pattyn=md.vel;
+
+%Save the solution in the directory
+save archive_pattyn archive_pattyn
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the solution in the directory
+save archive_temperature archive_temperature
+save archive_melting archive_melting
+
+%Compute solution with Ice model
+md=setelementstype(md,'hutter','all');
+md=solve(md,'diagnostic','ice');
+archive_hutter=md.vel;
+
+%Save the solution in the directory
+save archive_hutter archive_hutter
+
Index: /issm/trunk/test/Verification/test5_icesheet_icefront_3d/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test5_icesheet_icefront_3d/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test5_icesheet_icefront_3d/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test5_icesheet_icefront_3d/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test5_icesheet_icefront_3d/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test5_icesheet_icefront_3d/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test5_icesheet_icefront_3d/Square.par
===================================================================
--- /issm/trunk/test/Verification/test5_icesheet_icefront_3d/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test5_icesheet_icefront_3d/Square.par	(revision 16)
@@ -0,0 +1,33 @@
+%Start defining model parameters here
+
+%dynamic parameters for transient tests
+md.dt=md.yts;
+md.ndt=md.yts;
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness+10;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+md=SetMarineIceSheetBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test5_icesheet_icefront_3d/runme.m
===================================================================
--- /issm/trunk/test/Verification/test5_icesheet_icefront_3d/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test5_icesheet_icefront_3d/runme.m	(revision 16)
@@ -0,0 +1,124 @@
+% This file can be run to check that the current version of pattyn model is giving 
+% coherent results. This test deals with an icesheet with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test5_icesheet_icefront_3d: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+vel_pattyn=md.vel;
+
+
+
+%Load old velocities and compare with the new model
+load archive_pattyn
+pos=find(archive_pattyn-vel_pattyn);
+error_vel=abs(norm((archive_pattyn(pos)-vel_pattyn(pos))./archive_pattyn(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR.  Results from Pattyn model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Pattyn model are comform with the archive version'));
+end
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+temp_pattyn=md.temperature;
+melting_pattyn=md.melting;
+
+%Load old temperature and compare with the new model
+load archive_temperature
+post=find(archive_temperature-temp_pattyn);
+error_temp=abs(norm((archive_temperature(post)-temp_pattyn(post))./archive_temperature(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+        logoutput(logstring,sprintf('%s\n','    ERROR. Results from Thermal model differ from the archive version'));
+else
+        logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Thermal model are comform with the archive version'));
+end
+
+%Load old melting and compare with the new model
+load archive_melting
+post=find(archive_melting-melting_pattyn);
+error_melting=abs(norm((archive_melting(post)-melting_pattyn(post))./archive_melting(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting>tolerance);
+        logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+        logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
+
+%Compute temperature transient with Ice model
+md=solve(md,'thermaltransient','ice');
+temptrans_pattyn=md.thermaltransient_results(2).temperature;
+meltingtrans_pattyn=md.thermaltransient_results(2).melting;
+
+%Load old temperature transient and compare with the new model
+load archive_temperature_transient
+post2=find(archive_temperature_transient);
+error_temp=abs(norm((archive_temperature_transient(post2)-temptrans_pattyn(post2))./archive_temperature_transient(post2),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal transient model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal transient model are comform with the archive version'));
+end
+
+%Load old melting transient and compare with the new model
+load archive_melting_transient
+post2=find(archive_melting_transient);
+error_melting_transient=abs(norm((archive_melting_transient(post2)-meltingtrans_pattyn(post2))./archive_melting_transient(post2),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting_transient>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting transient model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting transient model are comform with the archive version'));
+end
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+thickness=md.new_thickness;
+
+%Load old temperature transient and compare with the new model
+load archive_thickness
+posth=find(archive_thickness);
+error_thickness=abs(norm((archive_thickness(posth)-thickness(posth))./archive_thickness(posth),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_thickness));
+
+if (error_thickness>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from prognostic model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from prognostic model are comform with the archive version'));
+end
+
Index: /issm/trunk/test/Verification/test5_icesheet_icefront_3d/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test5_icesheet_icefront_3d/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test5_icesheet_icefront_3d/updatearchive.m	(revision 16)
@@ -0,0 +1,46 @@
+% This file can be run to update the velocity archives  of the test5.
+% This test deals with an icesheet with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_pattyn=md.vel;
+
+%Save the solution in the directory
+save archive_pattyn archive_pattyn
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the temperature and melting in the directory
+save archive_temperature archive_temperature
+save archive_melting archive_melting
+
+%Compute temperature transient with Ice model
+md=solve(md,'thermaltransient','ice');
+archive_temperature_transient=md.thermaltransient_results(2).temperature;
+archive_melting_transient=md.thermaltransient_results(2).melting;
+
+%Save the temperature and melting transient in the directory
+save archive_temperature_transient archive_temperature_transient
+save archive_melting_transient archive_melting_transient
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+archive_thickness=md.new_thickness;
+
+%Save the new thickness in the directory
+save archive_thickness archive_thickness
+
Index: /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/Square.par
===================================================================
--- /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/Square.par	(revision 16)
@@ -0,0 +1,33 @@
+%Start defining model parameters here
+
+%dynamic parameters for transient tests
+md.dt=md.yts;
+md.ndt=md.yts;
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+md=SetIceShelfBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/runme.m
===================================================================
--- /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/runme.m	(revision 16)
@@ -0,0 +1,124 @@
+% This file can be run to check that the current version of Pattyn model is giving 
+% coherent results. This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test6_iceshelf_icefront_3d: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+vel_pattyn=md.vel;
+
+%Load old velocities and compare with the new model
+load archive_pattyn
+pos=find(archive_pattyn);
+error_vel=abs(norm((archive_pattyn(pos)-vel_pattyn(pos))./archive_pattyn(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Pattyn model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Pattyn model are comform with the archive version'));
+end
+
+
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+temp_pattyn=md.temperature;
+melting_pattyn=md.melting;
+
+%Load old temperature and compare with the new model
+load archive_temperature
+post=find(archive_temperature);
+error_temp=abs(norm((archive_temperature(post)-temp_pattyn(post))./archive_temperature(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal model are comform with the archive version'));
+end
+
+%Load old melting and compare with the new model
+load archive_melting
+post=find(archive_melting);
+error_melting=abs(norm((archive_melting(post)-melting_pattyn(post))./archive_melting(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
+
+%Compute temperature transient with Ice model
+md=solve(md,'thermaltransient','ice');
+temptrans_pattyn=md.thermaltransient_results(2).temperature;
+meltingtrans_pattyn=md.thermaltransient_results(2).melting;
+
+%Load old temperature transient and compare with the new model
+load archive_temperature_transient
+post2=find(archive_temperature_transient);
+error_temp=abs(norm((archive_temperature_transient(post2)-temptrans_pattyn(post2))./archive_temperature_transient(post2),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal transient model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal transient model are comform with the archive version'));
+end
+
+%Load old melting transient and compare with the new model
+load archive_melting_transient
+post2=find(archive_melting_transient);
+error_melting_transient=abs(norm((archive_melting_transient(post2)-meltingtrans_pattyn(post2))./archive_melting_transient(post2),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting_transient>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting transient model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting transient model are comform with the archive version'));
+end
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+thickness=md.new_thickness;
+
+%Load old temperature transient and compare with the new model
+load archive_thickness
+posth=find(archive_thickness);
+error_thickness=abs(norm((archive_thickness(posth)-thickness(posth))./archive_thickness(posth),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_thickness));
+
+if (error_thickness>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from prognostic model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from prognostic model are comform with the archive version'));
+end
+
Index: /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test6_iceshelf_icefront_3d/updatearchive.m	(revision 16)
@@ -0,0 +1,45 @@
+% This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_pattyn=md.vel;
+
+%Save the solution in the directory
+save archive_pattyn archive_pattyn
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the temperature and melting in the directory
+save archive_temperature archive_temperature
+save archive_melting archive_melting
+
+%Compute temperature transient with Ice model
+md=solve(md,'thermaltransient','ice');
+archive_temperature_transient=md.thermaltransient_results(2).temperature;
+archive_melting_transient=md.thermaltransient_results(2).melting;
+
+%Save the temperature and melting transient in the directory
+save archive_temperature_transient archive_temperature_transient
+save archive_melting_transient archive_melting_transient
+
+%Compute prognostic with Ice model
+md=solve(md,'prognostic','ice');
+archive_thickness=md.new_thickness;
+
+%Save the new thickness in the directory
+save archive_thickness archive_thickness
+
Index: /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Pattyn.exp
===================================================================
--- /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Pattyn.exp	(revision 16)
+++ /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Pattyn.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+500001 0
+500001 1000001
+0 1000001
+0 0
Index: /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Square.par
===================================================================
--- /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/Square.par	(revision 16)
@@ -0,0 +1,29 @@
+%Start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+md=SetIceShelfBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/iceshelf.exp
===================================================================
--- /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/iceshelf.exp	(revision 16)
+++ /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/iceshelf.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:iceshelf
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1 -1
+1000001 -1
+1000001 1000001
+-1 1000001
+-1 -1
Index: /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/runme.m
===================================================================
--- /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/runme.m	(revision 16)
@@ -0,0 +1,72 @@
+% This file can be run to check that the current version of Pattyn model is giving 
+% coherent results. This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test7_penalties_iceshelf_3d: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','Pattyn.exp','fill','macayeal');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+velocity=md.vel;
+
+%Load old velocities and compare with the new model
+load archive_velocity 
+pos=find(archive_velocity-velocity);
+error_vel=abs(norm((archive_velocity(pos)-velocity(pos))./archive_velocity(pos),2));
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from diagnostic model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from diagnostic model are comform with the archive version'));
+end
+
+
+
+%Compute solution with Ice model
+md=solve(md,'thermalsteady','ice');
+temperature=md.temperature;
+melting=md.melting;
+
+%Load old velocities and compare with the new model
+load archive_temperature
+post=find(archive_temperature-temperature);
+error_temp=abs(norm((archive_temperature(post)-temperature(post))./archive_temperature(post),2));
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal model are comform with the archive version'));
+end
+
+%Load old velocities and compare with the new model
+load archive_melting
+post=find(archive_melting-melting);
+error_melting=abs(norm((archive_melting(post)-melting(post))./archive_melting(post),2));
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+if (error_melting>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
+
+
+
Index: /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test7_penalties_iceshelf_3d/updatearchive.m	(revision 16)
@@ -0,0 +1,29 @@
+% This file can be run to update the velocity archives  of the test7.
+% This test deals with an iceshelf with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','Pattyn.exp','fill','macayeal');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_velocity=md.vel;
+
+%Save the solution in the directory
+save archive_velocity  archive_velocity 
+
+%Compute solution with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the solution in the directory
+save archive_temperature archive_temperature
+save archive_melting archive_melting
Index: /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/Square.par
===================================================================
--- /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/Square.par	(revision 16)
@@ -0,0 +1,30 @@
+%Start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness+10;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+%Deal with boundary conditions:
+md=SetIceSheetBC(md);
Index: /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/runme.m
===================================================================
--- /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/runme.m	(revision 16)
@@ -0,0 +1,75 @@
+% This file can be run to check that the current version of pattyn model is giving 
+% coherent results. This test deals with an icesheet without icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test8_icesheet_noicefront_stokes: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'macayeal','all','stokes','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+vel_stokes=md.vel;
+
+
+%Load old velocities and compare with the new model
+load archive_stokes
+pos=find(archive_stokes);
+error_vel=abs(norm((archive_stokes(pos)-vel_stokes(pos))./archive_stokes(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from Stokes model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Stokes model are comform with the archive version'));
+end
+
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+temp_stokes=md.temperature;
+melting_stokes=md.melting;
+
+%Load old temperatures and compare with the new model
+load archive_temperature
+post=find(archive_temperature-temp_stokes);
+error_temp=abs(norm((archive_temperature(post)-temp_stokes(post))./archive_temperature(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from thermal model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from thermal model are comform with the archive version'));
+end
+
+%Load old melting and compare with the new model
+load archive_melting
+post=find(archive_melting);
+error_melting=abs(norm((archive_melting(post)-melting_stokes(post))./archive_melting(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
Index: /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test8_icesheet_noicefront_stokes/updatearchive.m	(revision 16)
@@ -0,0 +1,29 @@
+% This file can be run to update the velocity archives  of the test8.
+% This test deals with an icesheet without icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'macayeal','all','stokes','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_stokes=md.vel;
+
+%Save the solution in the directory
+save archive_stokes archive_stokes
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the solution in the directory
+save archive_melting archive_melting
+save archive_temperature archive_temperature
Index: /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/Square.par
===================================================================
--- /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/Square.par	(revision 16)
@@ -0,0 +1,29 @@
+%Start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness+10;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+md=SetMarineIceSheetBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/runme.m
===================================================================
--- /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/runme.m	(revision 16)
@@ -0,0 +1,75 @@
+% This file can be run to check that the current version of pattyn model is giving 
+% coherent results. This test deals with an icesheet with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-14. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%Initialize log message for nightly runs.
+logstring='Verification/test9_icesheet_icefront_stokes: ';
+
+% Create model;
+
+tolerance=10^-13;
+
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all','stokes','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+vel_stokes=md.vel;
+
+
+
+%Load old velocities and compare with the new model
+load archive_stokes
+pos=find(archive_stokes-vel_stokes);
+error_vel=abs(norm((archive_stokes(pos)-vel_stokes(pos))./archive_stokes(pos),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_vel));
+
+if (error_vel>tolerance);
+	logoutput(logstring,sprintf('%s\n','    ERROR.  Results from Stokes model differ from the archive version'));
+else
+	logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Stokes model are comform with the archive version'));
+end
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+temp_stokes=md.temperature;
+melting_stokes=md.melting;
+
+%Load old temperature velocities and compare with the new model
+load archive_temperature
+post=find(archive_temperature-temp_stokes);
+error_temp=abs(norm((archive_temperature(post)-temp_stokes(post))./archive_temperature(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_temp));
+
+if (error_temp>tolerance);
+        logoutput(logstring,sprintf('%s\n','    ERROR. Results from Thermal model differ from the archive version'));
+else
+        logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from Thermal model are comform with the archive version'));
+end
+
+%Load old melting velocities and compare with the new model
+load archive_melting
+post=find(archive_melting-melting_stokes);
+error_melting=abs(norm((archive_melting(post)-melting_stokes(post))./archive_melting(post),2));
+
+disp(sprintf('numerical difference between old and new version of Ice is : %d', error_melting));
+
+if (error_melting>tolerance);
+        logoutput(logstring,sprintf('%s\n','    ERROR. Results from melting model differ from the archive version'));
+else
+        logoutput(logstring,sprintf('%s\n','    SUCCESS. Results from melting model are comform with the archive version'));
+end
Index: /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/updatearchive.m
===================================================================
--- /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/updatearchive.m	(revision 16)
+++ /issm/trunk/test/Verification/test9_icesheet_icefront_stokes/updatearchive.m	(revision 16)
@@ -0,0 +1,29 @@
+% This file can be run to update the velocity archives  of the test9.
+% This test deals with an icesheet with icefront for a 3d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup Ice code. 
+
+% The archive files will be saved in this directory but will not commited to ice1. 
+% Just commit the result if you want to.
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all','stokes','all');
+
+%Compute solution with Ice model
+md=solve(md,'diagnostic','ice');
+archive_stokes=md.vel;
+
+%Save the solution in the directory
+save archive_stokes archive_stokes
+
+%Compute temperature with Ice model
+md=solve(md,'thermalsteady','ice');
+archive_temperature=md.temperature;
+archive_melting=md.melting;
+
+%Save the solution in the directory
+save archive_temperature archive_temperature
+save archive_melting archive_melting
Index: /issm/trunk/test/Verification/test_cielo/DomainOutline.exp
===================================================================
--- /issm/trunk/test/Verification/test_cielo/DomainOutline.exp	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/DomainOutline.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test_cielo/DomainOutlineRifts.exp
===================================================================
--- /issm/trunk/test/Verification/test_cielo/DomainOutlineRifts.exp	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/DomainOutlineRifts.exp	(revision 16)
@@ -0,0 +1,13 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+8 1.
+# X pos Y pos
+0 0
+450000 0
+500000 300000
+550000 0
+1000000 0
+1000000 1000000
+0 1000000
+0 0
Index: /issm/trunk/test/Verification/test_cielo/Front.exp
===================================================================
--- /issm/trunk/test/Verification/test_cielo/Front.exp	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/Front.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:icefront
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1000 900000
+-1000 1100000
+1100000 1100000
+1100000 900000
+-1000 900000
Index: /issm/trunk/test/Verification/test_cielo/IceShelf.exp
===================================================================
--- /issm/trunk/test/Verification/test_cielo/IceShelf.exp	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/IceShelf.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:iceshelf
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+-1 -1
+1000001 -1
+1000001 1000001
+-1 1000001
+-1 -1
Index: /issm/trunk/test/Verification/test_cielo/Pattyn.exp
===================================================================
--- /issm/trunk/test/Verification/test_cielo/Pattyn.exp	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/Pattyn.exp	(revision 16)
@@ -0,0 +1,10 @@
+## Name:domainoutline
+## Icon:0
+# Points Count  Value
+5 1.
+# X pos Y pos
+0 0
+500001 0
+500001 1000001
+0 1000001
+0 0
Index: /issm/trunk/test/Verification/test_cielo/Rifts.exp
===================================================================
--- /issm/trunk/test/Verification/test_cielo/Rifts.exp	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/Rifts.exp	(revision 16)
@@ -0,0 +1,23 @@
+## Name:Rifts2
+## Icon:0
+# Points Count  Value
+2 1.000000
+# X pos Y pos
+500000 320000
+500000 700000
+
+## Name:Rifts3
+## Icon:0
+# Points Count  Value
+2 1.000000
+# X pos Y pos
+400000 300000
+200000 600000
+
+## Name:Rifts4
+## Icon:0
+# Points Count  Value
+2 1.000000
+# X pos Y pos
+600000 300000
+800000 600000
Index: /issm/trunk/test/Verification/test_cielo/Square.par
===================================================================
--- /issm/trunk/test/Verification/test_cielo/Square.par	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/Square.par	(revision 16)
@@ -0,0 +1,29 @@
+%Start defining model parameters here
+
+disp('      creating thickness');
+hmin=300;
+hmax=1000;
+ymin=min(md.y);
+ymax=max(md.y);
+md.thickness=hmax+(hmin-hmax)*(md.y-ymin)/(ymax-ymin);
+md.firn_layer=10*ones(md.numberofgrids,1);
+md.bed=-md.rho_ice/md.rho_water*md.thickness;
+md.surface=md.bed+md.thickness;
+
+disp('      creating drag');
+md.drag_type=2; %0 none 1 plastic 2 viscous
+md.drag=200*ones(md.numberofgrids,1); %q=1.
+%Take care of iceshelves: no basal drag
+pos=find(md.elementoniceshelf);
+md.drag(md.elements(pos,:))=0;
+md.p=ones(md.numberofelements,1);
+md.q=ones(md.numberofelements,1);
+
+disp('      creating temperature');
+md.observed_temperature=(273-20)*ones(md.numberofgrids,1);
+
+disp('      creating flow law paramter');
+md.B=paterson(md.observed_temperature);
+md.n=3*ones(md.numberofelements,1);
+
+md=SetIceShelfBC(md,'Front.exp');
Index: /issm/trunk/test/Verification/test_cielo/runme.m
===================================================================
--- /issm/trunk/test/Verification/test_cielo/runme.m	(revision 16)
+++ /issm/trunk/test/Verification/test_cielo/runme.m	(revision 16)
@@ -0,0 +1,171 @@
+% Create model;
+
+update_archive=0;
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+
+%First test macayeal: 
+md=setelementstype(md,'macayeal','all');
+
+md.cluster='wilkes';
+
+md=solve(md,'diagnostic_horiz','cielo'); pause(10);
+md=loadresultsfromcluster(md,'diagnostic_horiz');
+vel_cielo=md.vel;
+
+if update_archive,
+	vel_nightly=vel_cielo;
+	save diagnostic_horiz_macayeal  vel_nightly
+end
+
+load diagnostic_horiz_macayeal 
+
+plotmodel(md,'data',vel_nightly,'title','diagnostic_horiz_macayeal','data',vel_cielo,'data',vel_nightly-vel_cielo,'data',(vel_nightly-vel_cielo)./vel_nightly*100,'figure',1);
+
+
+%Then test full pattyn
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,3,3);
+
+md=setelementstype(md,'pattyn','all');
+
+md.cluster='wilkes';
+
+md=solve(md,'diagnostic_horiz','cielo'); pause(10);
+md=loadresultsfromcluster(md,'diagnostic_horiz');
+vel_cielo=md.vel;
+
+if update_archive,
+	vel_nightly=vel_cielo;
+	save diagnostic_horiz_pattyn  vel_nightly
+end
+
+load diagnostic_horiz_pattyn
+
+plotmodel(md,'data',vel_nightly,'title','diagnostic_horiz_pattyn','data',vel_cielo,'data',vel_nightly-vel_cielo,'data',(vel_nightly-vel_cielo)./vel_nightly*100,'figure',2);
+
+%Then test mixed macayeal pattyn
+
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=extrude(md,3,3);
+
+md=setelementstype(md,'pattyn','Pattyn.exp','fill','macayeal');
+
+md.cluster='wilkes';
+
+md=solve(md,'diagnostic_horiz','cielo'); pause(10);
+md=loadresultsfromcluster(md,'diagnostic_horiz');
+vel_cielo=md.vel;
+
+if update_archive,
+	vel_nightly=vel_cielo;
+	save diagnostic_horiz_mixed  vel_nightly
+end
+
+load diagnostic_horiz_mixed
+
+plotmodel(md,'data',vel_nightly,'title','diagnostic_horiz_mixed','data',vel_cielo,'data',vel_nightly-vel_cielo,'data',(vel_nightly-vel_cielo)./vel_nightly*100,'figure',3,'layer#all',1);
+
+%Now test macayeal with rifts
+md=model;
+md=mesh(md,'DomainOutlineRifts.exp','Rifts.exp',50000);
+md=rifttipsrefine(md,5000,80000);
+md=meshprocessrifts(md);
+
+md=geography(md,'all','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+
+md.cluster='wilkes';
+
+md=solve(md,'diagnostic_horiz','cielo'); pause(10);
+md=loadresultsfromcluster(md,'diagnostic_horiz');
+vel_cielo=md.vel;
+
+
+if update_archive,
+	vel_nightly=vel_cielo;
+	save diagnostic_horiz_rifts  vel_nightly
+end
+
+load diagnostic_horiz_rifts
+
+s=shearnorm2d(md);
+plotmodel(md,'data','vel','title','diagnostic_horiz_rifts','data',log10(s),'data','riftpenetration','data','riftvel','figure',4);
+plotmodel(md,'data',vel_nightly,'data',vel_cielo,'data',vel_nightly-vel_cielo,'data',(vel_nightly-vel_cielo)./vel_nightly*100,'figure',5);
+
+%Now test thermal
+md=model;
+md=mesh(md,'DomainOutline.exp',100000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=extrude(md,10,3);
+md=setelementstype(md,'pattyn','all');
+
+md.cluster='wilkes';
+
+md.vx=zeros(md.numberofgrids,1);
+md.vy=zeros(md.numberofgrids,1);
+md.vz=zeros(md.numberofgrids,1);
+md.pressure=lithostaticpressure(md.rho_ice,md.g,md.surface,md.thickness);
+
+md=solve(md,'thermalsteady','cielo');pause(10);
+md=loadresultsfromcluster(md,'thermalsteady');
+temperature_cielo=md.temperature;
+
+if update_archive,
+	temperature_nightly=temperature_cielo;
+	save thermalsteady  temperature_nightly
+end
+
+load thermalsteady
+
+plotmodel(md,'data',temperature_nightly,'title','thermalsteady','data',temperature_cielo,'data',temperature_nightly-temperature_cielo,'data',(temperature_nightly-temperature_cielo)./temperature_nightly*100,'figure',6);
+
+
+
+% run control method
+
+update_archive=1;
+
+md=model;
+md=mesh(md,'DomainOutline.exp',30000);
+md=geography(md,'','');
+md=parameterize(md,'Square.par');
+md=setelementstype(md,'macayeal','all');
+
+md.cluster='wilkes';
+md.np=8;
+md.debug=0;
+
+md.drag(:)=500;
+pos=find(md.y<200000);
+md.drag(pos)=0;
+
+md=solve(md,'diagnostic_horiz','cielo'); pause(10);
+md=loadresultsfromcluster(md,'diagnostic_horiz');
+md.vx_obs=md.vx;
+md.vy_obs=md.vy;
+
+md=solve(md,'control','cielo');pause(60);
+md=loadresultsfromcluster(md,'control');
+Jfit=md.cont_J;
+
+if update_archive
+	save control Jfit
+end
+load  control
+figure(7),plot(md.cont_J,Jfit);
+
+return;
