Index: /issm/trunk/src/c/parallel/objectivefunctionC.cpp
===================================================================
--- /issm/trunk/src/c/parallel/objectivefunctionC.cpp	(revision 1824)
+++ /issm/trunk/src/c/parallel/objectivefunctionC.cpp	(revision 1825)
@@ -23,4 +23,5 @@
 	
 	/*parameters: */
+	Model*    model=NULL;
 	FemModel* femmodel=NULL;
 	double* param_g=NULL;
@@ -41,10 +42,19 @@
 	int     sub_analysis_type;
 	Vec     u_g=NULL;
+	Vec     u_g_full=NULL;
 	double* u_g_double=NULL;
 	int     numberofnodes;
+		
+	/*thermalstatic: */
+	int     thermalstatic=0;
+	int     isstokes=0;
+	DataSet* results_thermalstatic=NULL;
+	int dofs01[2]={0,1};
 
+	/*Recover active model: */
+	model=optargs->model;
+	femmodel=model->Active();
 
 	/*Recover parameters: */
-	femmodel=optargs->femmodel;
 	param_g=optargs->param_g;
 	grad_g=optargs->grad_g;
@@ -62,4 +72,6 @@
 	femmodel->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
 	femmodel->parameters->FindParam((void*)&numberofdofspernode,"numberofdofspernode");
+	femmodel->parameters->FindParam((void*)&thermalstatic,"thermalstatic");
+	femmodel->parameters->FindParam((void*)&isstokes,"isstokes");
 
 	/*First copy param_g so we don't modify it: */
@@ -76,7 +88,24 @@
 	inputs->Add(control_type,param_g_copy,1,numberofnodes);
 
-	//Run diagnostic with updated parameters.
-	diagnostic_core_nonlinear(&u_g,NULL,NULL,NULL,femmodel,inputs,DiagnosticAnalysisEnum(),sub_analysis_type);
-	VecToMPISerial(&u_g_double,u_g); VecFree(&u_g);
+	if(!thermalstatic){
+		//Run diagnostic with updated parameters.
+		diagnostic_core_nonlinear(&u_g,NULL,NULL,femmodel,inputs,DiagnosticAnalysisEnum(),sub_analysis_type);
+		VecToMPISerial(&u_g_double,u_g); VecFree(&u_g);
+	}
+	else{
+		//Run full thermalstatic solution with updated parameters.
+		results_thermalstatic=new DataSet(ResultsEnum());
+		thermalstatic_core(results_thermalstatic,model,inputs);
+		
+		//get u_g 
+		results_thermalstatic->FindResult(&u_g,"u_g");
+		delete results_thermalstatic;
+
+		//extract the correct number of dofs (3 or 4)
+		VecDuplicatePatch(&u_g_full,u_g);VecFree(&u_g);
+		if(!isstokes)VecPartition(&u_g, u_g_full, dofsetgen(2,dofs01,3,numberofnodes*3), numberofnodes*2);
+		VecFree(&u_g_full);
+	}
+
 	inputs->Add("velocity",u_g_double,numberofdofspernode,numberofnodes);
 
