Index: /issm/trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp
===================================================================
--- /issm/trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp	(revision 26456)
+++ /issm/trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp	(revision 26457)
@@ -792,6 +792,10 @@
 		iomodel->FetchDataToInput(inputs,elements,"md.initialization.vx",VxShearEnum,0.);
 		iomodel->FetchDataToInput(inputs,elements,"md.initialization.vy",VyShearEnum,0.);
+	}
+   if(iomodel->domaintype==Domain2DhorizontalEnum){
 		iomodel->FetchDataToInput(inputs,elements,"md.initialization.vx",VxBaseEnum,0.);
 		iomodel->FetchDataToInput(inputs,elements,"md.initialization.vy",VyBaseEnum,0.);
+		iomodel->FetchDataToInput(inputs,elements,"md.initialization.vx",VxSurfaceEnum,0.);
+		iomodel->FetchDataToInput(inputs,elements,"md.initialization.vy",VySurfaceEnum,0.);
 	}
 	iomodel->FetchDataToInput(inputs,elements,"md.stressbalance.loadingforcex",LoadingforceXEnum);
@@ -2120,8 +2124,15 @@
 
 	/*Add vx and vy as inputs to the tria element: */
+	/*Also add surface vx and vy for the misfit, and base vx and vy for friction*/
 	element->AddBasalInput(VxEnum,vx,element->GetElementType());
-	if(dim==2)element->AddBasalInput(VyEnum,vy,element->GetElementType());
+	element->AddBasalInput(VxSurfaceEnum,vx,element->GetElementType());
+	element->AddBasalInput(VxBaseEnum,vx,element->GetElementType());
+	if(dim==2) {
+		element->AddBasalInput(VyEnum,vy,element->GetElementType());
+		element->AddBasalInput(VySurfaceEnum,vy,element->GetElementType());
+		element->AddBasalInput(VyBaseEnum,vy,element->GetElementType());
+	}
 	element->AddBasalInput(VelEnum,vel,element->GetElementType());
-
+	
 	/*Free ressources:*/
 	xDelete<IssmDouble>(vel);
@@ -2724,4 +2735,10 @@
 	element->AddBasalInput(VelEnum,vel,element->GetElementType());
 
+	/*Also add surface vx and vy for the misfit, and base vx and vy for friction*/
+	element->AddBasalInput(VxSurfaceEnum,vx,element->GetElementType());
+	element->AddBasalInput(VySurfaceEnum,vy,element->GetElementType());
+	element->AddBasalInput(VxBaseEnum,vx,element->GetElementType());
+	element->AddBasalInput(VyBaseEnum,vy,element->GetElementType());
+
 	/*Free ressources:*/
 	xDelete<IssmDouble>(vel);
@@ -2789,5 +2806,5 @@
 
 	/*build friction object, used later on: */
-	Friction* friction=new Friction(element,dim,true);
+	Friction* friction=new Friction(element, dim);
 
 	/*Recover portion of element that is grounded*/
@@ -3280,7 +3297,4 @@
 		vx[i]=vbx[i]+vshx[i]*(n[i]+1)/(n[i]+2);
 		vy[i]=vby[i]+vshy[i]*(n[i]+1)/(n[i]+2);
-		// HOTFIX: set surface velocity to VxEnum and VyEnum
-	//	vx[i]=vbx[i]+vshx[i];
-	//	vy[i]=vby[i]+vshy[i];
 	}
 		
@@ -3474,5 +3488,6 @@
 
 	/*build friction object, used later on: */
-	Friction* friction=new Friction(element,dim==3?2:1);
+	/*dim=4 is special for HO, which is actually 2.5D*/
+	Friction* friction=new Friction(element,dim==3?4:1);
 
 	/*Recover portion of element that is grounded*/
Index: /issm/trunk-jpl/src/c/classes/Loads/Friction.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Friction.cpp	(revision 26456)
+++ /issm/trunk-jpl/src/c/classes/Loads/Friction.cpp	(revision 26457)
@@ -20,13 +20,10 @@
 	this->dim=0;
 	this->law=0;
-	this->isMLHO=false;
-
 }
 /*}}}*/
-Friction::Friction(Element* element_in,int dim_in,bool isMLHO_in){/*{{{*/
+Friction::Friction(Element* element_in,int dim_in){/*{{{*/
 
 	this->element=element_in;
 	this->dim=dim_in;
-	this->isMLHO=isMLHO_in;
 	element_in->FindParam(&this->law,FrictionLawEnum);
 }
@@ -859,6 +856,4 @@
 	IssmDouble vx,vy,vz,vmag;
 	
-	if(this->isMLHO) _assert_(dim==2);
-
 	switch(dim){
 		case 1:
@@ -867,12 +862,6 @@
 			break;
 		case 2:
-			if(this->isMLHO){
-				element->GetInputValue(&vx,gauss,VxBaseEnum);
-				element->GetInputValue(&vy,gauss,VyBaseEnum);
-			}
-			else{
-				element->GetInputValue(&vx,gauss,VxEnum);
-				element->GetInputValue(&vy,gauss,VyEnum);
-			}		
+			element->GetInputValue(&vx,gauss,VxBaseEnum);
+			element->GetInputValue(&vy,gauss,VyBaseEnum);
 			vmag=sqrt(vx*vx+vy*vy);
 			break;
@@ -883,4 +872,10 @@
 			vmag=sqrt(vx*vx+vy*vy+vz*vz);
 			break;
+		case 4:
+			/* This is for HO 3D case, since it requires the horizontal velocities */
+			element->GetInputValue(&vx,gauss,VxEnum);
+			element->GetInputValue(&vy,gauss,VyEnum);
+			vmag=sqrt(vx*vx+vy*vy);
+			break;
 		default:
 			_error_("not supported");
Index: /issm/trunk-jpl/src/c/classes/Loads/Friction.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Friction.h	(revision 26456)
+++ /issm/trunk-jpl/src/c/classes/Loads/Friction.h	(revision 26457)
@@ -17,9 +17,8 @@
 		int      dim;
 		int      law;
-		bool		isMLHO=false;
 
 		/*methods: */
 		Friction();
-		Friction(Element* element_in,int dim_in,bool isMLHO=0);
+		Friction(Element* element_in,int dim_in);
 		~Friction();
 
Index: /issm/trunk-jpl/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp	(revision 26456)
+++ /issm/trunk-jpl/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp	(revision 26457)
@@ -61,11 +61,23 @@
 	/*Retrieve all inputs we will be needing: */
 	DatasetInput* weights_input=topelement->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
-	Input* vx_input     =topelement->GetInput(VxEnum);                                 _assert_(vx_input);
-	Input* vxobs_input  =topelement->GetInput(InversionVxObsEnum);                     _assert_(vxobs_input);
+	Input* vx_input     = NULL;
+	Input* vxobs_input  = topelement->GetInput(InversionVxObsEnum);	_assert_(vxobs_input);
 	Input* vy_input     = NULL;
 	Input* vyobs_input  = NULL;
-	if(numcomponents==2){
-		vy_input    =topelement->GetInput(VyEnum);              _assert_(vy_input);
-		vyobs_input =topelement->GetInput(InversionVyObsEnum);  _assert_(vyobs_input);
+
+	/*Read SurfaceEnum from 2D models:SSA, L1L2, MLHO*/
+	if (domaintype == Domain2DhorizontalEnum) {
+		vx_input = topelement->GetInput(VxSurfaceEnum);					_assert_(vx_input);
+		if(numcomponents==2){
+			vy_input    =topelement->GetInput(VySurfaceEnum);        _assert_(vy_input);
+			vyobs_input =topelement->GetInput(InversionVyObsEnum);	_assert_(vyobs_input);
+		}
+	}
+	else {
+		vx_input = topelement->GetInput(VxEnum);							_assert_(vx_input);
+		if(numcomponents==2){
+			vy_input    =topelement->GetInput(VyEnum);					_assert_(vy_input);
+			vyobs_input =topelement->GetInput(InversionVyObsEnum);	_assert_(vyobs_input);
+		}
 	}
 
Index: /issm/trunk-jpl/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp	(revision 26456)
+++ /issm/trunk-jpl/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp	(revision 26457)
@@ -69,12 +69,24 @@
 	DatasetInput* weights_input=topelement->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
 	Input* S_input      = topelement->GetInput(SurfaceAreaEnum);     _assert_(S_input);
-	Input* vx_input     = topelement->GetInput(VxEnum);              _assert_(vx_input);
-	Input* vxobs_input  = topelement->GetInput(InversionVxObsEnum);  _assert_(vxobs_input);
-	Input* vy_input     = NULL;
-	Input* vyobs_input  = NULL;
-	if(numcomponents==2){
-		vy_input    =topelement->GetInput(VyEnum);              _assert_(vy_input);
-		vyobs_input =topelement->GetInput(InversionVyObsEnum);  _assert_(vyobs_input);
+   Input* vx_input     = NULL;
+   Input* vxobs_input  = topelement->GetInput(InversionVxObsEnum); _assert_(vxobs_input);
+   Input* vy_input     = NULL;
+   Input* vyobs_input  = NULL;
+
+   /*Read SurfaceEnum from 2D models:SSA, L1L2, MLHO*/
+   if (domaintype == Domain2DhorizontalEnum) {
+      vx_input = topelement->GetInput(VxSurfaceEnum);             _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VySurfaceEnum);        _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
 	}
+   else {
+      vx_input = topelement->GetInput(VxEnum);                    _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VyEnum);               _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
+   }
 
 	/* Start  looping on the number of gaussian points: */
Index: /issm/trunk-jpl/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp	(revision 26456)
+++ /issm/trunk-jpl/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp	(revision 26457)
@@ -63,12 +63,24 @@
 	/*Retrieve all inputs we will be needing: */
 	DatasetInput* weights_input=topelement->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
-	Input* vx_input     =topelement->GetInput(VxEnum);                                 _assert_(vx_input);
-	Input* vxobs_input  =topelement->GetInput(InversionVxObsEnum);                     _assert_(vxobs_input);
-	Input* vy_input     = NULL;
-	Input* vyobs_input  = NULL;
-	if(numcomponents==2){
-		vy_input    =topelement->GetInput(VyEnum);              _assert_(vy_input);
-		vyobs_input =topelement->GetInput(InversionVyObsEnum);  _assert_(vyobs_input);
+   Input* vx_input     = NULL;
+   Input* vxobs_input  = topelement->GetInput(InversionVxObsEnum);   _assert_(vxobs_input);
+   Input* vy_input     = NULL;
+   Input* vyobs_input  = NULL;
+
+   /*Read SurfaceEnum from 2D models:SSA, L1L2, MLHO*/
+   if (domaintype == Domain2DhorizontalEnum) {
+      vx_input = topelement->GetInput(VxSurfaceEnum);             _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VySurfaceEnum);        _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
 	}
+   else {
+      vx_input = topelement->GetInput(VxEnum);                    _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VyEnum);               _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
+   }
 
 	/* Start  looping on the number of gaussian points: */
Index: /issm/trunk-jpl/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp	(revision 26456)
+++ /issm/trunk-jpl/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp	(revision 26457)
@@ -63,12 +63,24 @@
 	/*Retrieve all inputs we will be needing: */
 	DatasetInput* weights_input=topelement->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
-	Input* vx_input     =topelement->GetInput(VxEnum);                                 _assert_(vx_input);
-	Input* vxobs_input  =topelement->GetInput(InversionVxObsEnum);                     _assert_(vxobs_input);
-	Input* vy_input     = NULL;
-	Input* vyobs_input  = NULL;
-	if(numcomponents==2){
-		vy_input    =topelement->GetInput(VyEnum);              _assert_(vy_input);
-		vyobs_input =topelement->GetInput(InversionVyObsEnum);  _assert_(vyobs_input);
+   Input* vx_input     = NULL;
+   Input* vxobs_input  = topelement->GetInput(InversionVxObsEnum);   _assert_(vxobs_input);
+   Input* vy_input     = NULL;
+   Input* vyobs_input  = NULL;
+
+   /*Read SurfaceEnum from 2D models:SSA, L1L2, MLHO*/
+   if (domaintype == Domain2DhorizontalEnum) {
+      vx_input = topelement->GetInput(VxSurfaceEnum);             _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VySurfaceEnum);        _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
 	}
+   else {
+      vx_input = topelement->GetInput(VxEnum);                    _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VyEnum);               _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
+   }
 
 	/* Start  looping on the number of gaussian points: */
Index: /issm/trunk-jpl/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp	(revision 26456)
+++ /issm/trunk-jpl/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp	(revision 26457)
@@ -63,12 +63,24 @@
 	/*Retrieve all inputs we will be needing: */
 	DatasetInput* weights_input=topelement->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
-	Input* vx_input     =topelement->GetInput(VxEnum);                                 _assert_(vx_input);
-	Input* vxobs_input  =topelement->GetInput(InversionVxObsEnum);                     _assert_(vxobs_input);
-	Input* vy_input     = NULL;
-	Input* vyobs_input  = NULL;
-	if(numcomponents==2){
-		vy_input    =topelement->GetInput(VyEnum);              _assert_(vy_input);
-		vyobs_input =topelement->GetInput(InversionVyObsEnum);  _assert_(vyobs_input);
+   Input* vx_input     = NULL;
+   Input* vxobs_input  = topelement->GetInput(InversionVxObsEnum);   _assert_(vxobs_input);
+   Input* vy_input     = NULL;
+   Input* vyobs_input  = NULL;
+
+   /*Read SurfaceEnum from 2D models:SSA, L1L2, MLHO*/
+   if (domaintype == Domain2DhorizontalEnum) {
+      vx_input = topelement->GetInput(VxSurfaceEnum);             _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VySurfaceEnum);        _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
 	}
+   else {
+      vx_input = topelement->GetInput(VxEnum);                    _assert_(vx_input);
+      if(numcomponents==2){
+         vy_input    =topelement->GetInput(VyEnum);               _assert_(vy_input);
+         vyobs_input =topelement->GetInput(InversionVyObsEnum);   _assert_(vyobs_input);
+      }
+   }
 
 	/* Start  looping on the number of gaussian points: */
Index: /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h	(revision 26456)
+++ /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h	(revision 26457)
@@ -536,5 +536,9 @@
 	AdjointpEnum,
 	AdjointxEnum,
+	AdjointxBaseEnum,
+	AdjointxShearEnum,
 	AdjointyEnum,
+	AdjointyBaseEnum,
+	AdjointyShearEnum,
 	AdjointzEnum,
 	AirEnum,
