Index: /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.cpp	(revision 27728)
@@ -29,4 +29,5 @@
 	this->definitionenum = -1;
 	this->name = NULL;
+	this->J = 0.;
 }
 /*}}}*/
@@ -37,4 +38,16 @@
 	this->name		= xNew<char>(strlen(in_name)+1);
 	xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
+
+	this->J = 0.;
+}
+/*}}}*/
+Cfdragcoeffabsgrad::Cfdragcoeffabsgrad(char* in_name, int in_definitionenum, IssmDouble in_J){/*{{{*/
+
+	this->definitionenum=in_definitionenum;
+
+	this->name		= xNew<char>(strlen(in_name)+1);
+	xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
+
+	this->J = in_J;
 }
 /*}}}*/
@@ -45,5 +58,5 @@
 /*Object virtual function resolutoin: */
 Object* Cfdragcoeffabsgrad::copy() {/*{{{*/
-	Cfdragcoeffabsgrad* mf = new Cfdragcoeffabsgrad(this->name,this->definitionenum);
+	Cfdragcoeffabsgrad* mf = new Cfdragcoeffabsgrad(this->name,this->definitionenum, this->J);
 	return (Object*) mf;
 }
@@ -69,4 +82,5 @@
 	marshallhandle->call(this->definitionenum);
 	marshallhandle->call(this->name);
+	marshallhandle->call(this->J);
 } 
 /*}}}*/
@@ -90,15 +104,15 @@
 
 	/*recover parameters: */
-	IssmDouble J=0.;
+	IssmDouble J_part=0.;
 	IssmDouble J_sum=0.;
 
 	for(Object* & object : femmodel->elements->objects){
 		Element* element=xDynamicCast<Element*>(object);
-		J+=this->Cfdragcoeffabsgrad_Calculation(element);
+		J_part+=this->Cfdragcoeffabsgrad_Calculation(element);
 	}
 
-	ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+	ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
 	ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
-	J=J_sum;
+	this->J=J_sum;
 
 	return J;
Index: /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.h	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.h	(revision 27728)
@@ -16,10 +16,12 @@
 	public: 
 
-		int   definitionenum;
-		char *name;
+		int         definitionenum;
+		char       *name;
+		IssmDouble  J;
 
 		/*Cfdragcoeffabsgrad constructors, destructors :*/
 		Cfdragcoeffabsgrad();
 		Cfdragcoeffabsgrad(char* in_name, int in_definitionenum);
+		Cfdragcoeffabsgrad(char* in_name, int in_definitionenum, IssmDouble in_J);
 		~Cfdragcoeffabsgrad();
 
Index: /issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.cpp	(revision 27728)
@@ -32,7 +32,21 @@
 	this->datatime=0.;
 	this->timepassedflag = false;
-}
-/*}}}*/
-Cflevelsetmisfit::Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
+	this->J = 0.;
+}
+/*}}}*/
+Cflevelsetmisfit::Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime){/*{{{*/
+
+	this->definitionenum=in_definitionenum;
+
+	this->name		= xNew<char>(strlen(in_name)+1);
+	xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
+
+	this->model_enum=in_model_enum;
+	this->datatime=in_datatime;
+	this->timepassedflag=false;
+	this->J = 0.;
+}
+/*}}}*/
+Cflevelsetmisfit::Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag, IssmDouble in_J){/*{{{*/
 
 	this->definitionenum=in_definitionenum;
@@ -44,4 +58,5 @@
 	this->datatime=in_datatime;
 	this->timepassedflag=in_timepassedflag;
+	this->J = in_J;
 }
 /*}}}*/
@@ -52,5 +67,5 @@
 /*Object virtual function resolutoin: */
 Object* Cflevelsetmisfit::copy() {/*{{{*/
-	Cflevelsetmisfit* mf = new Cflevelsetmisfit(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag);
+	Cflevelsetmisfit* mf = new Cflevelsetmisfit(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag, this->J);
 	return (Object*) mf;
 }
@@ -82,4 +97,5 @@
 	marshallhandle->call(this->datatime);
 	marshallhandle->call(this->timepassedflag);
+	marshallhandle->call(this->J);
 } 
 /*}}}*/
@@ -106,24 +122,23 @@
 	 /*recover time parameters: */
 	 femmodel->parameters->FindParam(&time,TimeEnum);
-
-	 IssmDouble J=0.;
-	 IssmDouble J_sum=0.;
-
 	 if(datatime<=time && !timepassedflag){
+
+		 IssmDouble J_part = 0.;
+		 IssmDouble J_sum  = 0.;
+
 		 for(Object* & object : femmodel->elements->objects){
 			 Element* element=xDynamicCast<Element*>(object);
-			 J+=this->Cflevelsetmisfit_Calculation(element,model_enum);
+			 J_part+=this->Cflevelsetmisfit_Calculation(element,model_enum);
 		 }
 
-		 ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+		 ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
 		 ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
-		 J=J_sum;
 
 		 this->timepassedflag = true;
-		 return J;
+		 this->J = J_sum;
 	 }
-	 else return J;
- }
-	/*}}}*/
+
+	 return this->J;
+ }/*}}}*/
 IssmDouble Cflevelsetmisfit::Cflevelsetmisfit_Calculation(Element* element, int model_enum){/*{{{*/
 
Index: /issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.h	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.h	(revision 27728)
@@ -21,8 +21,10 @@
 		IssmDouble  datatime;
 		bool        timepassedflag;
+		IssmDouble  J;
 
 		/*Cflevelsetmisfit constructors, destructors :*/
 		Cflevelsetmisfit();
-		Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag);
+		Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime);
+		Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag, IssmDouble in_J);
 		~Cflevelsetmisfit();
 
Index: /issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.cpp	(revision 27728)
@@ -30,9 +30,22 @@
 	this->name = NULL;
 	this->weights_enum = UNDEF;
-	this->misfit=0;
 	this->timepassedflag = false;
+	this->J = 0.;
 }
 /*}}}*/
-Cfrheologybbarabsgrad::Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum, bool in_timepassedflag){/*{{{*/
+Cfrheologybbarabsgrad::Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum){/*{{{*/
+
+	this->definitionenum=in_definitionenum;
+
+	this->name		= xNew<char>(strlen(in_name)+1);
+	xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
+
+	this->weights_enum=in_weights_enum;
+	this->timepassedflag=false;
+
+	this->J=0;
+}
+/*}}}*/
+Cfrheologybbarabsgrad::Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum, bool in_timepassedflag, IssmDouble in_J){/*{{{*/
 
 	this->definitionenum=in_definitionenum;
@@ -44,16 +57,14 @@
 	this->timepassedflag=in_timepassedflag;
 
-	this->misfit=0;
+	this->J=in_J;
 }
 /*}}}*/
 Cfrheologybbarabsgrad::~Cfrheologybbarabsgrad(){/*{{{*/
 	if(this->name)xDelete(this->name);
-	this->misfit=0;
 }
 /*}}}*/
 /*Object virtual function resolutoin: */
 Object* Cfrheologybbarabsgrad::copy() {/*{{{*/
-	Cfrheologybbarabsgrad* mf = new Cfrheologybbarabsgrad(this->name,this->definitionenum, this->weights_enum,this->timepassedflag);
-	mf->misfit=this->misfit;
+	Cfrheologybbarabsgrad* mf = new Cfrheologybbarabsgrad(this->name,this->definitionenum, this->weights_enum,this->timepassedflag,this->J);
 	return (Object*) mf;
 }
@@ -83,5 +94,5 @@
 	marshallhandle->call(this->weights_enum);
 	marshallhandle->call(this->timepassedflag);
-	marshallhandle->call(this->misfit);
+	marshallhandle->call(this->J);
 } 
 /*}}}*/
@@ -105,18 +116,18 @@
 
 	/*recover parameters: */
-	IssmDouble J=0.;
+	IssmDouble J_part=0.;
 	IssmDouble J_sum=0.;
 
 	for(Object* & object : femmodel->elements->objects){
 		Element* element=xDynamicCast<Element*>(object);
-		J+=this->Cfrheologybbarabsgrad_Calculation(element,weights_enum);
+		J_part+=this->Cfrheologybbarabsgrad_Calculation(element,weights_enum);
 	}
 
-	ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+	ISSM_MPI_Allreduce( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
 	ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
-	J=J_sum;
 
-	timepassedflag = true;
-	return J;
+	this->timepassedflag = true;
+	this->J = J_sum;
+	return this->J;
 }/*}}}*/
 IssmDouble Cfrheologybbarabsgrad::Cfrheologybbarabsgrad_Calculation(Element* element, int weights_enum){/*{{{*/
@@ -124,5 +135,5 @@
 	int        domaintype,numcomponents;
 	IssmDouble Jelem=0.;
-	IssmDouble misfit,Jdet;
+	IssmDouble Jdet;
 	IssmDouble dp[2],weight;
 	IssmDouble* xyz_list = NULL;
Index: /issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.h	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.h	(revision 27728)
@@ -21,10 +21,10 @@
 		int         weights_enum;
 		bool			timepassedflag;
-
-		IssmDouble  misfit; //value carried over in time.
+		IssmDouble  J;
 
 		/*Cfrheologybbarabsgrad constructors, destructors :*/
 		Cfrheologybbarabsgrad();
-		Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum,  bool timepassedflag);
+		Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum);
+		Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum,  bool in_timepassedflag, IssmDouble in_J);
 		~Cfrheologybbarabsgrad();
 
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.cpp	(revision 27728)
@@ -31,8 +31,9 @@
 	this->datatime=0.;
 	this->timepassedflag = false;
-
-}
-/*}}}*/
-Cfsurfacelogvel::Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
+	this->J = 0.;
+
+}
+/*}}}*/
+Cfsurfacelogvel::Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime){/*{{{*/
 
 	this->definitionenum=in_definitionenum;
@@ -42,5 +43,20 @@
 
 	this->datatime=in_datatime;
+
+	this->timepassedflag=false;
+	this->J=0.;
+
+}
+/*}}}*/
+Cfsurfacelogvel::Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool in_timepassedflag,IssmDouble in_J){/*{{{*/
+
+	this->definitionenum=in_definitionenum;
+
+	this->name		= xNew<char>(strlen(in_name)+1);
+	xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
+
+	this->datatime=in_datatime;
 	this->timepassedflag=in_timepassedflag;
+	this->J=in_J;
 
 }
@@ -52,5 +68,5 @@
 /*Object virtual function resolutoin: */
 Object* Cfsurfacelogvel::copy() {/*{{{*/
-	Cfsurfacelogvel* mf = new Cfsurfacelogvel(this->name,this->definitionenum,this->datatime,this->timepassedflag);
+	Cfsurfacelogvel* mf = new Cfsurfacelogvel(this->name,this->definitionenum,this->datatime,this->timepassedflag, this->J);
 	return (Object*) mf;
 }
@@ -64,4 +80,5 @@
 	_printf_("    datatime: " << datatime << "\n");
 	_printf_("	  timepassedflag: "<<timepassedflag<<"\n");
+	_printf_("	  J: "<<J<<"\n");
 }
 /*}}}*/
@@ -78,4 +95,5 @@
 	marshallhandle->call(this->datatime);
 	marshallhandle->call(this->timepassedflag);
+	marshallhandle->call(this->J);
 } 
 /*}}}*/
@@ -104,22 +122,20 @@
 	if(this->datatime<=time && !this->timepassedflag){
 
-		IssmDouble J=0.;
+		IssmDouble J_part=0.;
 		IssmDouble J_sum=0.;
 
 		for(Object* & object : femmodel->elements->objects){
 			Element* element=xDynamicCast<Element*>(object);
-			J+=this->Cfsurfacelogvel_Calculation(element,definitionenum);
-		}
-
-		ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+			J_part+=this->Cfsurfacelogvel_Calculation(element,definitionenum);
+		}
+
+		ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
 		ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
-		J=J_sum;
 
 		this->timepassedflag = true;
-		return J_sum;
-	}
-	else{
-		return 0.;
-	}
+		this->J = J_sum;
+	}
+
+	return this->J;
 }/*}}}*/
 IssmDouble Cfsurfacelogvel::Cfsurfacelogvel_Calculation(Element* element, int definitionenum){/*{{{*/
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.h	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.h	(revision 27728)
@@ -20,8 +20,10 @@
 		IssmDouble	datatime;
 		bool			timepassedflag;
+		IssmDouble  J;
 
 		/*Cfsurfacelogvel constructors, destructors :*/
 		Cfsurfacelogvel();
-		Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool timepassedflag);
+		Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime);
+		Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool timepassedflag, IssmDouble in_J);
 		~Cfsurfacelogvel();
 
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.cpp	(revision 27728)
@@ -32,7 +32,21 @@
 	this->datatime         = 0.;
 	this->timepassedflag   = false;
-}
-/*}}}*/
-Cfsurfacesquare::Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
+	this->J                = 0.;
+}
+/*}}}*/
+Cfsurfacesquare::Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime){/*{{{*/
+
+	this->definitionenum=in_definitionenum;
+
+	this->name		= xNew<char>(strlen(in_name)+1);
+	xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
+
+	this->model_enum=in_model_enum;
+	this->datatime=in_datatime;
+	this->timepassedflag=false;
+	this->J=0.;
+}
+/*}}}*/
+Cfsurfacesquare::Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag, IssmDouble in_J){/*{{{*/
 
 	this->definitionenum=in_definitionenum;
@@ -44,4 +58,5 @@
 	this->datatime=in_datatime;
 	this->timepassedflag=in_timepassedflag;
+	this->J=in_J;
 }
 /*}}}*/
@@ -53,5 +68,5 @@
 /*Object virtual function resolutoin: */
 Object* Cfsurfacesquare::copy() {/*{{{*/
-	Cfsurfacesquare* mf = new Cfsurfacesquare(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag);
+	Cfsurfacesquare* mf = new Cfsurfacesquare(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag,this->J);
 	return (Object*) mf;
 }
@@ -66,4 +81,5 @@
 	_printf_("    datatime: " << datatime << "\n");
 	_printf_("	  timepassedflag: "<<timepassedflag<<"\n");
+	_printf_("	  J: "<<J<<"\n");
 }
 /*}}}*/
@@ -82,4 +98,5 @@
 	marshallhandle->call(this->datatime);
 	marshallhandle->call(this->timepassedflag);
+	marshallhandle->call(this->J);
 } 
 /*}}}*/
@@ -110,21 +127,20 @@
 	if(this->datatime<=time && !this->timepassedflag){
 
-		IssmDouble J=0.;
+		IssmDouble J_part=0.;
 		IssmDouble J_sum=0.;
 
 		for(Object* & object : femmodel->elements->objects){
 			Element* element=xDynamicCast<Element*>(object);
-			J+=this->Cfsurfacesquare_Calculation(element,model_enum);
+			J_part+=this->Cfsurfacesquare_Calculation(element,model_enum);
 		}
 
-		ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+		ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
 		ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
 
 		this->timepassedflag = true;
-		return J_sum;
+		this->J = J_sum;
 	}
-	else{
-		return 0.;
-	}
+
+	return this->J;
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.h	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.h	(revision 27728)
@@ -21,8 +21,10 @@
 		IssmDouble  datatime;
 		bool        timepassedflag;
+		IssmDouble  J;
 
 		/*Cfsurfacesquare constructors, destructors :*/
 		Cfsurfacesquare();
-		Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag);
+		Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime);
+		Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag, IssmDouble in_J);
 		~Cfsurfacesquare();
 
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacesquaretransient.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacesquaretransient.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacesquaretransient.cpp	(revision 27728)
@@ -159,6 +159,5 @@
 	/*Check that we have not yet calculated this cost function*/
 	if(this->passedflags[pos]){
-		return 0.;
-		//return this->J; //FIXME
+		return this->J;
 	}
 
@@ -172,5 +171,5 @@
 	/*Sum across partition*/
 	IssmDouble J_sum;
-	ISSM_MPI_Allreduce( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+	ISSM_MPI_Allreduce((void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
 	ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
 
@@ -180,6 +179,5 @@
 
 	/*Return full cost function this far*/
-	//return this->J; //FIXME
-	return J_sum;
+	return this->J;
 }/*}}}*/
 IssmDouble Cfsurfacesquaretransient::Cfsurfacesquaretransient_Calculation(Element* element, int model_enum){/*{{{*/
Index: /issm/trunk-jpl/src/c/classes/DependentObject.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/DependentObject.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/DependentObject.cpp	(revision 27728)
@@ -70,11 +70,13 @@
 
 /*DependentObject methods: */
-void  DependentObject::Responsex(IssmDouble* poutput_value,FemModel* femmodel){/*{{{*/
+void  DependentObject::RecordResponsex(FemModel* femmodel){/*{{{*/
 
 	/*Is this some special type of response for which we need to go in the output definitions? :*/
 	if (StringToEnumx(this->name,false)==-1){
-		*poutput_value=OutputDefinitionsResponsex(femmodel,this->name);
+		this->response_value = OutputDefinitionsResponsex(femmodel,this->name);
 	}
-	else femmodel->Responsex(poutput_value,this->name);
+	else{
+		femmodel->Responsex(&this->response_value, this->name);
+	}
 }
 /*}}}*/
@@ -83,8 +85,4 @@
 }
 /*}}}*/
-void DependentObject::AddValue(IssmDouble in_value){/*{{{*/
-	this->response_value+=in_value;
-}
-/*}}}*/
 void DependentObject::ResetResponseValue(){/*{{{*/
 	this->response_value=0.;
Index: /issm/trunk-jpl/src/c/classes/DependentObject.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/DependentObject.h	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/DependentObject.h	(revision 27728)
@@ -35,7 +35,6 @@
 
 		/*DependentObject methods: */
-		void       Responsex(IssmDouble *poutput_value,FemModel*femmodel);
+		void       RecordResponsex(FemModel*femmodel);
 		IssmDouble GetValue(void);
-		void       AddValue(IssmDouble in_value);
 		void       ResetResponseValue(void);
 
Index: /issm/trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 27728)
@@ -2335,21 +2335,16 @@
 void FemModel::RequestedDependentsx(void){/*{{{*/
 
-	bool        isautodiff      = false;
-	IssmDouble  output_value;
-
-	int         num_dependents;
-	IssmPDouble *dependents;
-	DataSet*    dependent_objects=NULL;
-	int my_rank=IssmComm::GetRank();
-
 	/*AD mode on?: */
+	bool isautodiff;
 	parameters->FindParam(&isautodiff,AutodiffIsautodiffEnum);
 
 	if(isautodiff){
 		#ifdef _HAVE_AD_
+		int      num_dependents;
+		DataSet* dependent_objects=NULL;
 		parameters->FindParam(&num_dependents,AutodiffNumDependentsEnum);
 		parameters->FindParam(&dependent_objects,AutodiffDependentObjectsEnum);
 		if(num_dependents){
-			dependents=xNew<IssmPDouble>(num_dependents);
+			IssmPDouble* dependents=xNew<IssmPDouble>(num_dependents);
 
 			#if defined(_HAVE_CODIPACK_)
@@ -2364,8 +2359,10 @@
 
 			/*Go through our dependent variables, and compute the response:*/
+			int my_rank=IssmComm::GetRank();
 			int i = 0;
 			for(Object* & object : dependent_objects->objects){
 				DependentObject* dep=(DependentObject*)object;
-				dep->Responsex(&output_value,this);
+				dep->RecordResponsex(this);
+				IssmDouble output_value = dep->GetValue();
 				if (my_rank==0) {
 					#if defined(_HAVE_CODIPACK_)
@@ -2385,7 +2382,7 @@
 				i++;
 			}
+			xDelete<IssmPDouble>(dependents);
 		}
 		delete dependent_objects;
-		if(num_dependents)xDelete<IssmPDouble>(dependents);
 		#else
 		_error_("Should not be requesting dependents when an AD library is not available!");
@@ -4608,8 +4605,6 @@
 void FemModel::DakotaResponsesx(double* d_responses,char** responses_descriptors,int numresponsedescriptors,int d_numresponses){/*{{{*/
 
-	int        i,j;
-	int        my_rank;
-
 	/*intermediary: */
+	int    i,j;
 	char   root[50];
 	int    index;
@@ -4631,5 +4626,5 @@
 
 	/*retrieve my_rank: */
-	my_rank=IssmComm::GetRank();
+	int my_rank=IssmComm::GetRank();
 
 	/*save the d_responses pointer: */
Index: /issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp	(revision 27728)
@@ -329,6 +329,8 @@
 			i++;
 			DependentObject* dep=xDynamicCast<DependentObject*>(object);
-			if(solution_type==TransientSolutionEnum) output_value = dep->GetValue();
-			if(solution_type!=TransientSolutionEnum) dep->Responsex(&output_value,femmodel);
+
+			/*Get cost function for this dependent*/
+			dep->RecordResponsex(femmodel);
+			IssmDouble output_value = dep->GetValue();
 
 			#if defined(_HAVE_CODIPACK_)
@@ -349,4 +351,5 @@
 			_error_("not suppoted");
 			#endif
+
 			J+=output_value;
 		}
Index: /issm/trunk-jpl/src/c/cores/controlvalidation_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/controlvalidation_core.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/cores/controlvalidation_core.cpp	(revision 27728)
@@ -243,5 +243,4 @@
 
 	/*Get Dependents*/
-	IssmDouble  output_value;
 	int         num_dependents;
 	IssmPDouble *dependents;
@@ -257,10 +256,7 @@
 		DependentObject* dep=xDynamicCast<DependentObject*>(object);
 		i++;
-		if(solution_type==TransientSolutionEnum){
-			output_value = dep->GetValue();
-		}
-		else{
-			dep->Responsex(&output_value,femmodel);
-		}
+		dep->RecordResponsex(femmodel);
+		IssmDouble output_value = dep->GetValue();
+
 		_printf0_("=== output ="<<output_value<<" \n");
 		if(my_rank==0) {
@@ -339,10 +335,6 @@
 		for(Object* & object:dependent_objects->objects){
 			DependentObject* dep=xDynamicCast<DependentObject*>(object);
-			if(solution_type==TransientSolutionEnum){
-				output_value = dep->GetValue();
-			}
-			else{
-				dep->Responsex(&output_value,femmodel);
-			}
+			dep->RecordResponsex(femmodel);
+			IssmDouble output_value = dep->GetValue();
 			j+=output_value;
 		}
Index: /issm/trunk-jpl/src/c/cores/transient_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/transient_core.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/cores/transient_core.cpp	(revision 27728)
@@ -118,7 +118,5 @@
 			for(Object* & object:dependent_objects->objects){
 				DependentObject* dep=(DependentObject*)object;
-				IssmDouble  output_value;
-				dep->Responsex(&output_value,femmodel);
-				dep->AddValue(output_value);
+				dep->RecordResponsex(femmodel);
 			}
 		}
@@ -269,5 +267,4 @@
 
 	/*parameters: */
-	IssmDouble output_value;
 	IssmDouble finaltime,dt,yts,time;
 	bool       isoceancoupling;
@@ -342,6 +339,5 @@
 		for(Object* & object:dependent_objects->objects){
 			DependentObject* dep=(DependentObject*)object;
-			dep->Responsex(&output_value,femmodel);
-			dep->AddValue(output_value);
+			dep->RecordResponsex(femmodel);
 		}
 
@@ -401,15 +397,14 @@
 		IssmDouble       output_value = dep->GetValue();
 
-
 		J += output_value;
 
 		tape_codi.registerOutput(J);
-#if _CODIPACK_MAJOR_==2
+		#if _CODIPACK_MAJOR_==2
 		codi_global.output_indices.push_back(J.getIdentifier());
-#elif _CODIPACK_MAJOR_==1
+		#elif _CODIPACK_MAJOR_==1
 		codi_global.output_indices.push_back(J.getGradientData());
-#else
-#error "_CODIPACK_MAJOR_ not supported"
-#endif
+		#else
+		#error "_CODIPACK_MAJOR_ not supported"
+		#endif
 
 		/*Keep track of output for printing*/
@@ -477,6 +472,5 @@
 			for(Object* & object:dependent_objects->objects){
 				DependentObject* dep=(DependentObject*)object;
-				dep->Responsex(&output_value,femmodel);
-				dep->AddValue(output_value);
+				dep->RecordResponsex(femmodel);
 			}
 
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/Autodiff/CreateParametersAutodiff.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/Autodiff/CreateParametersAutodiff.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/Autodiff/CreateParametersAutodiff.cpp	(revision 27728)
@@ -151,8 +151,7 @@
 		if(num_dependent_objects){
 			iomodel->FindConstant(&names,&dummy,"md.autodiff.dependent_object_names");
-			iomodel->FetchData(&indices,&dummy,&dummy,"md.autodiff.dependent_object_indices");
 
 			for(i=0;i<num_dependent_objects;i++){
-				DependentObject* dep=new DependentObject(names[i],indices[i]);
+				DependentObject* dep=new DependentObject(names[i]);
 				dependent_objects->AddObject(dep);
 				num_dep++;
@@ -164,5 +163,4 @@
 			}
 			xDelete<char*>(names);
-			xDelete<int>(indices);
 		}
 		parameters->AddObject(new DataSetParam(AutodiffDependentObjectsEnum,dependent_objects));
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 27727)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 27728)
@@ -205,5 +205,5 @@
 
 					/*First create a cfsurfacesquare object for that specific string (cfsurfacesquare_model_string_s[j]):*/
-					output_definitions->AddObject(new Cfsurfacesquare(cfsurfacesquare_name_s[j],StringToEnumx(cfsurfacesquare_definitionstring_s[j]),StringToEnumx(cfsurfacesquare_model_string_s[j]),cfsurfacesquare_datatime_s[j],false));
+					output_definitions->AddObject(new Cfsurfacesquare(cfsurfacesquare_name_s[j],StringToEnumx(cfsurfacesquare_definitionstring_s[j]),StringToEnumx(cfsurfacesquare_model_string_s[j]),cfsurfacesquare_datatime_s[j]));
 
 					/*Now, for this particular cfsurfacesquare object, make sure we plug into the elements: the observation, and the weights.*/
@@ -413,5 +413,5 @@
 
 					/*First create a cfrheologybbarabsgrad object for that specific string (cfrheologybbarabsgrad_model_string_s[j]):*/
-					output_definitions->AddObject(new Cfrheologybbarabsgrad(cfrheologybbarabsgrad_name_s[j],StringToEnumx(cfrheologybbarabsgrad_definitionstring_s[j]),StringToEnumx(cfrheologybbarabsgrad_weights_string_s[j]),false));
+					output_definitions->AddObject(new Cfrheologybbarabsgrad(cfrheologybbarabsgrad_name_s[j],StringToEnumx(cfrheologybbarabsgrad_definitionstring_s[j]),StringToEnumx(cfrheologybbarabsgrad_weights_string_s[j])));
 
 					/*Now, for this particular cfrheologybbarabsgrad object, make sure we plug into the elements: the observation, and the weights.*/
@@ -496,5 +496,5 @@
 
 					/*First create a cfsurfacelogvel object for that specific string (cfsurfacelogvel_modeltring[j]):*/
-					output_definitions->AddObject(new Cfsurfacelogvel(cfsurfacelogvel_name[j],StringToEnumx(cfsurfacelogvel_definitionstring[j]),cfsurfacelogvel_datatime[j],false));
+					output_definitions->AddObject(new Cfsurfacelogvel(cfsurfacelogvel_name[j],StringToEnumx(cfsurfacelogvel_definitionstring[j]),cfsurfacelogvel_datatime[j]));
 
 					/*Now, for this particular cfsurfacelogvel object, make sure we plug into the elements: the observation, and the weights.*/
@@ -590,5 +590,5 @@
 
 					/*First create a cflevelsetmisfit object for that specific string (cflevelsetmisfit_model_string_s[j]):*/
-					output_definitions->AddObject(new Cflevelsetmisfit(cflevelsetmisfit_name_s[j],StringToEnumx(cflevelsetmisfit_definitionstring_s[j]),StringToEnumx(cflevelsetmisfit_model_string_s[j]),cflevelsetmisfit_datatime_s[j],false));
+					output_definitions->AddObject(new Cflevelsetmisfit(cflevelsetmisfit_name_s[j],StringToEnumx(cflevelsetmisfit_definitionstring_s[j]),StringToEnumx(cflevelsetmisfit_model_string_s[j]),cflevelsetmisfit_datatime_s[j]));
 
 					/*Now, for this particular cflevelsetmisfit object, make sure we plug into the elements: the observation, and the weights.*/
