Index: issm/trunk/src/c/DataSet/DataSet.cpp
===================================================================
--- issm/trunk/src/c/DataSet/DataSet.cpp	(revision 1187)
+++ issm/trunk/src/c/DataSet/DataSet.cpp	(revision 1188)
@@ -1261,5 +1261,5 @@
 }
 
-void  DataSet::Gradj(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){
+void  DataSet::Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){
 
 
@@ -1272,5 +1272,5 @@
 
 			element=(Element*)(*object);
-			element->Gradj(grad_g,lambda_g,inputs,analysis_type,sub_analysis_type,control_type);
+			element->Gradj(grad_g,inputs,analysis_type,sub_analysis_type,control_type);
 		}
 	}
Index: issm/trunk/src/c/DataSet/DataSet.h
===================================================================
--- issm/trunk/src/c/DataSet/DataSet.h	(revision 1187)
+++ issm/trunk/src/c/DataSet/DataSet.h	(revision 1188)
@@ -74,5 +74,5 @@
 		DataSet* Copy(void);
 		void  Du(Vec du_g,void* inputs,int analysis_type,int sub_analysis_type);
-		void  Gradj(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type);
+		void  Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type);
 		void  Misfit(double* pJ, void* inputs,int analysis_type,int sub_analysis_type);
 		void  FieldDepthAverageAtBase(Vec field,double* field_serial,char* fieldname);
Index: issm/trunk/src/c/Gradjx/Gradjx.cpp
===================================================================
--- issm/trunk/src/c/Gradjx/Gradjx.cpp	(revision 1187)
+++ issm/trunk/src/c/Gradjx/Gradjx.cpp	(revision 1188)
@@ -14,5 +14,5 @@
 
 void Gradjx( Vec* pgrad_g, int numberofnodes, DataSet* elements,DataSet* nodes, DataSet* loads, DataSet* materials, 
-		double* lambda_g, ParameterInputs* inputs,int analysis_type,int sub_analysis_type,char* control_type){
+			ParameterInputs* inputs,int analysis_type,int sub_analysis_type,char* control_type){
 
 	/*output: */
@@ -26,5 +26,5 @@
 
 	/*Compute gradients: */
-	elements->Gradj(grad_g,lambda_g,inputs,analysis_type,sub_analysis_type,control_type);
+	elements->Gradj(grad_g,inputs,analysis_type,sub_analysis_type,control_type);
 
 	/*Assemble vector: */
Index: issm/trunk/src/c/Gradjx/Gradjx.h
===================================================================
--- issm/trunk/src/c/Gradjx/Gradjx.h	(revision 1187)
+++ issm/trunk/src/c/Gradjx/Gradjx.h	(revision 1188)
@@ -10,5 +10,5 @@
 /* local prototypes: */
 void Gradjx( Vec* pgrad_g, int numberofnodes, DataSet* elements,DataSet* nodes, DataSet* loads, DataSet* materials, 
-			double* lambda_g, ParameterInputs* inputs,int analysis_type,int sub_analysis_type,char* control_type);
+			ParameterInputs* inputs,int analysis_type,int sub_analysis_type,char* control_type);
 
 #endif  /* _GRADJX_H */
Index: issm/trunk/src/c/objects/Beam.cpp
===================================================================
--- issm/trunk/src/c/objects/Beam.cpp	(revision 1187)
+++ issm/trunk/src/c/objects/Beam.cpp	(revision 1188)
@@ -571,15 +571,15 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Beam::Gradj"
-void  Beam::Gradj(_p_Vec*, double*, void*, int, int,char*){
+void  Beam::Gradj(_p_Vec*, void*, int, int,char*){
 	throw ErrorException(__FUNCT__," not supported yet!");
 }
 #undef __FUNCT__ 
 #define __FUNCT__ "Beam::GradjDrag"
-void  Beam::GradjDrag(_p_Vec*, double*, void*, int,int ){
+void  Beam::GradjDrag(_p_Vec*, void*, int,int ){
 	throw ErrorException(__FUNCT__," not supported yet!");
 }
 #undef __FUNCT__ 
 #define __FUNCT__ "Beam::GradjB"
-void  Beam::GradjB(_p_Vec*, double*, void*, int, int){
+void  Beam::GradjB(_p_Vec*, void*, int, int){
 	throw ErrorException(__FUNCT__," not supported yet!");
 }
Index: issm/trunk/src/c/objects/Beam.h
===================================================================
--- issm/trunk/src/c/objects/Beam.h	(revision 1187)
+++ issm/trunk/src/c/objects/Beam.h	(revision 1188)
@@ -80,7 +80,7 @@
 		void  GetThicknessList(double* thickness_list);
 		void  Du(_p_Vec*,void*, int,int);
-		void  Gradj(_p_Vec*, double*, void*, int, int,char*);
-		void  GradjDrag(_p_Vec*, double*, void*, int,int );
-		void  GradjB(_p_Vec*, double*, void*, int,int );
+		void  Gradj(_p_Vec*, void*, int, int,char*);
+		void  GradjDrag(_p_Vec*, void*, int,int );
+		void  GradjB(_p_Vec*, void*, int,int );
 		double Misfit(void*,int,int );
 		void  GetNodalFunctions(double* l1l2, double gauss_coord);
Index: issm/trunk/src/c/objects/Element.h
===================================================================
--- issm/trunk/src/c/objects/Element.h	(revision 1187)
+++ issm/trunk/src/c/objects/Element.h	(revision 1188)
@@ -35,7 +35,7 @@
 		virtual void  GetBedList(double* bed_list)=0;
 		virtual void  Du(Vec du_g,void* inputs,int analysis_type,int sub_analysis_type)=0;
-		virtual void  Gradj(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type)=0;
-		virtual void  GradjDrag(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type)=0;
-		virtual void  GradjB(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type)=0;
+		virtual void  Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type)=0;
+		virtual void  GradjDrag(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type)=0;
+		virtual void  GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type)=0;
 		virtual double Misfit(void* inputs,int analysis_type,int sub_analysis_type)=0;
 		virtual void  ComputePressure(Vec p_g)=0;
Index: issm/trunk/src/c/objects/Penta.cpp
===================================================================
--- issm/trunk/src/c/objects/Penta.cpp	(revision 1187)
+++ issm/trunk/src/c/objects/Penta.cpp	(revision 1188)
@@ -1207,11 +1207,11 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Penta::Gradj"
-void  Penta::Gradj(Vec grad_g,double* adjoint,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){
+void  Penta::Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){
 
 	if (strcmp(control_type,"drag")==0){
-		GradjDrag( grad_g,adjoint,inputs,analysis_type,sub_analysis_type);
+		GradjDrag( grad_g,inputs,analysis_type,sub_analysis_type);
 	}
 	else if (strcmp(control_type,"B")==0){
-		GradjB( grad_g,adjoint, inputs,analysis_type,sub_analysis_type);
+		GradjB( grad_g, inputs,analysis_type,sub_analysis_type);
 	}
 	else throw ErrorException(__FUNCT__,exprintf("%s%s","control type not supported yet: ",control_type));
@@ -1220,5 +1220,5 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Penta::GradjDrag"
-void  Penta::GradjDrag(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type){
+void  Penta::GradjDrag(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type){
 	
 	
@@ -1232,5 +1232,5 @@
 		
 		tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
-		tria->GradjDrag( grad_g,lambda_g,inputs,analysis_type,sub_analysis_type);
+		tria->GradjDrag( grad_g,inputs,analysis_type,sub_analysis_type);
 		delete tria;
 		return;
@@ -1240,5 +1240,5 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Penta::GradjB"
-void  Penta::GradjB(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type){
+void  Penta::GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type){
 	throw ErrorException(__FUNCT__," not supported yet!");
 }
Index: issm/trunk/src/c/objects/Penta.h
===================================================================
--- issm/trunk/src/c/objects/Penta.h	(revision 1187)
+++ issm/trunk/src/c/objects/Penta.h	(revision 1188)
@@ -87,7 +87,7 @@
 		int   GetOnBed();
 		void  Du(Vec du_g,void* inputs,int analysis_type,int sub_analysis_type);
-		void  Gradj(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type);
-		void  GradjDrag(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type);
-		void  GradjB(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type);
+		void  Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type);
+		void  GradjDrag(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type);
+		void  GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type);
 		double Misfit(void* inputs,int analysis_type,int sub_analysis_type);
 		
Index: issm/trunk/src/c/objects/Sing.cpp
===================================================================
--- issm/trunk/src/c/objects/Sing.cpp	(revision 1187)
+++ issm/trunk/src/c/objects/Sing.cpp	(revision 1188)
@@ -455,15 +455,15 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Sing::Gradj"
-void  Sing::Gradj(_p_Vec*, double*, void*, int, int ,char*){
+void  Sing::Gradj(_p_Vec*, void*, int, int ,char*){
 	throw ErrorException(__FUNCT__," not supported yet!");
 }
 #undef __FUNCT__ 
 #define __FUNCT__ "Sing::GradjDrag"
-void  Sing::GradjDrag(_p_Vec*, double*, void*, int,int){
+void  Sing::GradjDrag(_p_Vec*, void*, int,int){
 	throw ErrorException(__FUNCT__," not supported yet!");
 }
 #undef __FUNCT__ 
 #define __FUNCT__ "Sing::GradjB"
-void  Sing::GradjB(_p_Vec*, double*, void*, int,int){
+void  Sing::GradjB(_p_Vec*, void*, int,int){
 	throw ErrorException(__FUNCT__," not supported yet!");
 }
Index: issm/trunk/src/c/objects/Sing.h
===================================================================
--- issm/trunk/src/c/objects/Sing.h	(revision 1187)
+++ issm/trunk/src/c/objects/Sing.h	(revision 1188)
@@ -75,7 +75,7 @@
 		void  GetThicknessList(double* thickness_list);
 		void  Du(_p_Vec*,void*,int,int);
-		void  Gradj(_p_Vec*, double*, void*, int, int,char*);
-		void  GradjDrag(_p_Vec*, double*, void*, int,int);
-		void  GradjB(_p_Vec*, double*, void*, int,int);
+		void  Gradj(_p_Vec*, void*, int, int,char*);
+		void  GradjDrag(_p_Vec*, void*, int,int);
+		void  GradjB(_p_Vec*, void*, int,int);
 		double Misfit(void*,int,int);
 
Index: issm/trunk/src/c/objects/Tria.cpp
===================================================================
--- issm/trunk/src/c/objects/Tria.cpp	(revision 1187)
+++ issm/trunk/src/c/objects/Tria.cpp	(revision 1188)
@@ -2217,11 +2217,11 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Tria::Gradj"
-void  Tria::Gradj(Vec grad_g,double* adjoint,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){
+void  Tria::Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type){
 
 	if (strcmp(control_type,"drag")==0){
-		GradjDrag( grad_g,adjoint,inputs,analysis_type,sub_analysis_type);
+		GradjDrag( grad_g,inputs,analysis_type,sub_analysis_type);
 	}
 	else if (strcmp(control_type,"B")==0){
-		GradjB( grad_g,adjoint,inputs,analysis_type,sub_analysis_type);
+		GradjB( grad_g,inputs,analysis_type,sub_analysis_type);
 	}
 	else throw ErrorException(__FUNCT__,exprintf("%s%s","control type not supported yet: ",control_type));
@@ -2230,5 +2230,5 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Tria::GradjDrag"
-void  Tria::GradjDrag(Vec grad_g,double* adjoint,void* vinputs,int analysis_type,int sub_analysis_type){
+void  Tria::GradjDrag(Vec grad_g,void* vinputs,int analysis_type,int sub_analysis_type){
 
 
@@ -2313,20 +2313,16 @@
 		throw ErrorException(__FUNCT__,"missing velocity input parameter");
 	}
-
+	if(!inputs->Recover("adjoint",&adjxadjy_list[0][0],2,dofs2,numgrids,(void**)nodes)){
+		throw ErrorException(__FUNCT__,"missing adjoint input parameter");
+	}
+
+	/*Initialize parameter lists: */
 	for(i=0;i<numgrids;i++){
 		vx_list[i]=vxvy_list[i][0];
 		vy_list[i]=vxvy_list[i][1];
-	}
-
-	/*Initialize parameter lists: */
-	for(i=0;i<numgrids;i++){
-		//vx_list[i]=velocity[doflist[i*numberofdofspernode+0]];
-		//vy_list[i]=velocity[doflist[i*numberofdofspernode+1]];
-		//vxvy_list[i][0]=vx_list[i];
-		//vxvy_list[i][1]=vy_list[i];
-		adjx_list[i]=adjoint[doflist[i*numberofdofspernode+0]];
-		adjy_list[i]=adjoint[doflist[i*numberofdofspernode+1]];
-	}
-	
+		adjx_list[i]=adjxadjy_list[i][0];
+		adjy_list[i]=adjxadjy_list[i][1];
+	}
+
 	/* Get gaussian points and weights (make this a statically initialized list of points? fstd): */
 	GaussTria( &num_gauss, &first_gauss_area_coord, &second_gauss_area_coord, &third_gauss_area_coord, &gauss_weights, 4);
@@ -2435,5 +2431,5 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "Tria::GradjB"
-void  Tria::GradjB(Vec grad_g,double* adjoint,void* vinputs,int analysis_type,int sub_analysis_type){
+void  Tria::GradjB(Vec grad_g,void* vinputs,int analysis_type,int sub_analysis_type){
 
 	int i;
@@ -2511,18 +2507,14 @@
 		throw ErrorException(__FUNCT__,"missing velocity input parameter");
 	}
-
+	if(!inputs->Recover("adjoint",&adjxadjy_list[0][0],2,dofs2,numgrids,(void**)nodes)){
+		throw ErrorException(__FUNCT__,"missing adjoint input parameter");
+	}
+
+	/*Initialize parameter lists: */
 	for(i=0;i<numgrids;i++){
 		vx_list[i]=vxvy_list[i][0];
 		vy_list[i]=vxvy_list[i][1];
-	}
-
-	/*Initialize parameter lists: */
-	for(i=0;i<numgrids;i++){
-		//vx_list[i]=velocity[doflist[i*numberofdofspernode+0]];
-		//vy_list[i]=velocity[doflist[i*numberofdofspernode+1]];
-		//vxvy_list[i][0]=vx_list[i];
-		//vxvy_list[i][1]=vy_list[i];
-		adjx_list[i]=adjoint[doflist[i*numberofdofspernode+0]];
-		adjy_list[i]=adjoint[doflist[i*numberofdofspernode+1]];
+		adjx_list[i]=adjxadjy_list[i][0];
+		adjy_list[i]=adjxadjy_list[i][1];
 	}
 	
Index: issm/trunk/src/c/objects/Tria.h
===================================================================
--- issm/trunk/src/c/objects/Tria.h	(revision 1187)
+++ issm/trunk/src/c/objects/Tria.h	(revision 1188)
@@ -94,7 +94,7 @@
 		void  GetJacobian(double* J, double* xyz_list,double* gauss_l1l2l3);
 		void  Du(Vec du_g,void* inputs,int analysis_type,int sub_analysis_type);
-		void  Gradj(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type);
-		void  GradjDrag(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type);
-		void  GradjB(Vec grad_g,double* lambda_g,void* inputs,int analysis_type,int sub_analysis_type);
+		void  Gradj(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type,char* control_type);
+		void  GradjDrag(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type);
+		void  GradjB(Vec grad_g,void* inputs,int analysis_type,int sub_analysis_type);
 		double Misfit(void* inputs,int analysis_type,int sub_analysis_type);
 
Index: issm/trunk/src/c/parallel/GradJCompute.cpp
===================================================================
--- issm/trunk/src/c/parallel/GradJCompute.cpp	(revision 1187)
+++ issm/trunk/src/c/parallel/GradJCompute.cpp	(revision 1188)
@@ -71,7 +71,8 @@
 	_printf_("%s\n","      compute gradJ:");
 	VecToMPISerial(&lambda_g_double,lambda_g);VecFree(&lambda_g);
+	inputs->Add("adjoint",lambda_g_double,2,numberofnodes);
 
 	Gradjx( &grad_g, numberofnodes,femmodel->elements,femmodel->nodes, femmodel->loads, femmodel->materials, 
-				lambda_g_double, inputs,analysis_type,sub_analysis_type,control_type);
+				inputs,analysis_type,sub_analysis_type,control_type);
 	
 	/*Free ressources:*/
Index: issm/trunk/src/m/solutions/cielo/GradJCompute.m
===================================================================
--- issm/trunk/src/m/solutions/cielo/GradJCompute.m	(revision 1187)
+++ issm/trunk/src/m/solutions/cielo/GradJCompute.m	(revision 1188)
@@ -22,3 +22,3 @@
 
 %Compute gradJ 
-grad_g=Gradj(m.elements,m.nodes,m.loads,m.materials,m.parameters,lambda_g,inputs,analysis_type,sub_analysis_type);
+grad_g=Gradj(m.elements,m.nodes,m.loads,m.materials,m.parameters,inputs,analysis_type,sub_analysis_type);
Index: issm/trunk/src/mex/Gradj/Gradj.cpp
===================================================================
--- issm/trunk/src/mex/Gradj/Gradj.cpp	(revision 1187)
+++ issm/trunk/src/mex/Gradj/Gradj.cpp	(revision 1188)
@@ -16,5 +16,4 @@
 	DataSet* materials=NULL;
 	char*    control_type=NULL;
-	double*  lambda_g=NULL;
 	ParameterInputs* inputs=NULL;
 	char*    analysis_type_string=NULL;
@@ -41,5 +40,4 @@
 	FetchData((void**)&numberofnodes,NULL,NULL,mxGetField(PARAMETERS,0,"numberofnodes"),"Integer",NULL);
 	FetchData((void**)&control_type,NULL,NULL,mxGetField(PARAMETERS,0,"control_type"),"String",NULL);
-	FetchData((void**)&lambda_g,NULL,NULL,LAMBDAG,"Vector","Vec");
 	FetchData((void**)&analysis_type_string,NULL,NULL,ANALYSIS,"String",NULL);
 	analysis_type=AnalysisTypeAsEnum(analysis_type_string);
@@ -52,5 +50,5 @@
 
 	/*!Call core code: */
-	Gradjx(&grad_g,numberofnodes,elements,nodes,loads,materials,lambda_g,inputs,analysis_type,sub_analysis_type,control_type);
+	Gradjx(&grad_g,numberofnodes,elements,nodes,loads,materials,inputs,analysis_type,sub_analysis_type,control_type);
 
 	/*write output : */
@@ -62,5 +60,4 @@
 	delete loads;
 	delete materials;
-	xfree((void**)&lambda_g);
 	xfree((void**)&control_type);
 	delete inputs;
@@ -76,5 +73,5 @@
 {
 	_printf_("\n");
-	_printf_("   usage: [grad_g] = %s(elements, nodes,loads, materials, parameters, lambda_g,inputs);\n",__FUNCT__);
+	_printf_("   usage: [grad_g] = %s(elements, nodes,loads, materials, parameters,inputs);\n",__FUNCT__);
 	_printf_("\n");
 }
Index: issm/trunk/src/mex/Gradj/Gradj.h
===================================================================
--- issm/trunk/src/mex/Gradj/Gradj.h	(revision 1187)
+++ issm/trunk/src/mex/Gradj/Gradj.h	(revision 1188)
@@ -22,8 +22,7 @@
 #define MATERIALS (mxArray*)prhs[3]
 #define PARAMETERS (mxArray*)prhs[4]
-#define LAMBDAG (mxArray*)prhs[5]
-#define INPUTS (mxArray*)prhs[6]
-#define ANALYSIS (mxArray*)prhs[7]
-#define SUBANALYSIS (mxArray*)prhs[8]
+#define INPUTS (mxArray*)prhs[5]
+#define ANALYSIS (mxArray*)prhs[6]
+#define SUBANALYSIS (mxArray*)prhs[7]
 
 /* serial output macros: */
@@ -34,5 +33,5 @@
 #define NLHS  1
 #undef NRHS
-#define NRHS  9
+#define NRHS  8
 
 
