Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 5377)
+++ /issm/trunk/src/c/Makefile.am	(revision 5378)
@@ -1113,5 +1113,6 @@
 					./solutions/objectivefunctionC.cpp\
 					./solutions/gradient_core.cpp\
-					./solutions/adjoint_core.cpp\
+					./solutions/adjointdiagnostic_core.cpp\
+					./solutions/adjointbalancedthickness_core.cpp\
 					./solutions/prognostic_core.cpp\
 					./solutions/balancedthickness_core.cpp\
@@ -1126,4 +1127,5 @@
 					./solutions/SolutionConfiguration.cpp\
 					./solutions/CorePointerFromSolutionEnum.cpp\
+					./solutions/AdjointCorePointerFromSolutionEnum.cpp\
 					./solvers/solver_linear.cpp\
 					./solvers/solver_adjoint_linear.cpp\
Index: /issm/trunk/src/c/solutions/AdjointCorePointerFromSolutionEnum.cpp
===================================================================
--- /issm/trunk/src/c/solutions/AdjointCorePointerFromSolutionEnum.cpp	(revision 5378)
+++ /issm/trunk/src/c/solutions/AdjointCorePointerFromSolutionEnum.cpp	(revision 5378)
@@ -0,0 +1,45 @@
+/*!\file:  CorePointerFromSolutionEnum.cpp
+ * \brief: return type of analyses, number of analyses and core solution function.
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../toolkits/toolkits.h"
+#include "../objects/objects.h"
+#include "../shared/shared.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+#include "./solutions.h"
+#include "../modules/modules.h"
+#include "../include/include.h"
+#include "../solvers/solvers.h"
+
+void AdjointCorePointerFromSolutionEnum(void (**padjointcore)(FemModel*),int solutiontype){
+
+	/*output: */
+	void (*adjointcore)(FemModel*)=NULL;
+
+	switch(solutiontype){
+	
+		case DiagnosticSolutionEnum:
+			adjointcore=&adjointdiagnostic_core;
+			break;
+		case SteadystateSolutionEnum:
+			adjointcore=&adjointdiagnostic_core;
+			break;
+		case BalancedthicknessSolutionEnum:
+			adjointcore=&adjointbalancedthickness_core;
+			break;
+		default:
+			ISSMERROR("No adjoint has been implemented for solution %s yet",EnumToString(solutiontype));
+			break;
+	}
+	
+	/*Assign output pointer:*/
+	ISSMASSERT(padjointcore);
+	*padjointcore=adjointcore;
+
+}
Index: sm/trunk/src/c/solutions/adjoint_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/adjoint_core.cpp	(revision 5377)
+++ 	(revision )
@@ -1,64 +1,0 @@
-/*!\file:  adjoint_core.cpp
- * \brief compute inverse method adjoint state
- */ 
-
-#include "../toolkits/toolkits.h"
-#include "../objects/objects.h"
-#include "../shared/shared.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "./solutions.h"
-#include "../modules/modules.h"
-#include "../include/include.h"
-#include "../solvers/solvers.h"
-
-void adjoint_core(FemModel* femmodel){
-	
-	/*parameters: */
-	bool isstokes;
-	bool control_analysis;
-	bool conserve_loads   = true;
-	int  verbose          = 0;
-	int  solution_type;
-
-	/*retrieve parameters:*/
-	femmodel->parameters->FindParam(&verbose,VerboseEnum);
-	femmodel->parameters->FindParam(&isstokes,IsStokesEnum);
-	femmodel->parameters->FindParam(&control_analysis,ControlAnalysisEnum);
-	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
-
-	/*set analysis type to compute velocity: */
-	if (solution_type==SteadystateSolutionEnum || solution_type==DiagnosticSolutionEnum){
-		_printf_("%s\n","      computing velocities");
-		if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum);
-		else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum);
-		solver_diagnostic_nonlinear(femmodel,conserve_loads); 
-	}
-	else if (solution_type==BalancedthicknessSolutionEnum){
-		femmodel->SetCurrentConfiguration(BalancedthicknessAnalysisEnum);
-		solver_linear(femmodel); 
-	}
-	else{
-		ISSMERROR("Solution %s not implemented yet",EnumToString(solution_type));
-	}
-
-	/*Update inputs using adjoint solution, and same type of setup as diagnostic solution: */
-	_printf_("%s\n","      computing adjoint");
-	if (solution_type==SteadystateSolutionEnum || solution_type==DiagnosticSolutionEnum){
-		if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum,AdjointStokesAnalysisEnum);
-		else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum,AdjointHorizAnalysisEnum);
-	}
-	else if (solution_type==BalancedthicknessSolutionEnum){
-		femmodel->SetCurrentConfiguration(BalancedthicknessAnalysisEnum,AdjointBalancedthicknessAnalysisEnum);
-	}
-	solver_adjoint_linear(femmodel);
-	
-	if(solution_type==AdjointSolutionEnum && !control_analysis){
-		if(verbose)_printf_("saving results:\n");
-		InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointxEnum);
-		InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointyEnum);
-		if (isstokes){
-			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointzEnum);
-			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointpEnum);
-		}
-	}
-}
Index: /issm/trunk/src/c/solutions/adjointbalancedthickness_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/adjointbalancedthickness_core.cpp	(revision 5378)
+++ /issm/trunk/src/c/solutions/adjointbalancedthickness_core.cpp	(revision 5378)
@@ -0,0 +1,40 @@
+/*!\file:  adjointbalancedthickness_core.cpp
+ * \brief compute inverse method adjoint state
+ */ 
+
+#include "../toolkits/toolkits.h"
+#include "../objects/objects.h"
+#include "../shared/shared.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+#include "./solutions.h"
+#include "../modules/modules.h"
+#include "../include/include.h"
+#include "../solvers/solvers.h"
+
+void adjointbalancedthickness_core(FemModel* femmodel){
+	
+	/*parameters: */
+	bool control_analysis;
+	int  verbose = 0;
+	int  solution_type;
+
+	/*retrieve parameters:*/
+	femmodel->parameters->FindParam(&verbose,VerboseEnum);
+	femmodel->parameters->FindParam(&control_analysis,ControlAnalysisEnum);
+	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
+
+	/*set analysis type to compute velocity: */
+	_printf_("%s\n","      computing thickness");
+	femmodel->SetCurrentConfiguration(BalancedthicknessAnalysisEnum);
+	solver_linear(femmodel);
+
+	/*Update inputs using adjoint solution, and same type of setup as diagnostic solution: */
+	_printf_("%s\n","      computing adjoint");
+	femmodel->SetCurrentConfiguration(BalancedthicknessAnalysisEnum,AdjointBalancedthicknessAnalysisEnum);
+	solver_adjoint_linear(femmodel);
+	
+	if(solution_type==AdjointSolutionEnum && !control_analysis){
+		if(verbose)_printf_("saving results:\n");
+		InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointEnum);
+	}
+}
Index: /issm/trunk/src/c/solutions/adjointdiagnostic_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/adjointdiagnostic_core.cpp	(revision 5378)
+++ /issm/trunk/src/c/solutions/adjointdiagnostic_core.cpp	(revision 5378)
@@ -0,0 +1,50 @@
+/*!\file:  adjointdiagnostic_core.cpp
+ * \brief compute inverse method adjoint state
+ */ 
+
+#include "../toolkits/toolkits.h"
+#include "../objects/objects.h"
+#include "../shared/shared.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+#include "./solutions.h"
+#include "../modules/modules.h"
+#include "../include/include.h"
+#include "../solvers/solvers.h"
+
+void adjointdiagnostic_core(FemModel* femmodel){
+	
+	/*parameters: */
+	bool isstokes;
+	bool control_analysis;
+	bool conserve_loads   = true;
+	int  verbose          = 0;
+	int  solution_type;
+
+	/*retrieve parameters:*/
+	femmodel->parameters->FindParam(&verbose,VerboseEnum);
+	femmodel->parameters->FindParam(&isstokes,IsStokesEnum);
+	femmodel->parameters->FindParam(&control_analysis,ControlAnalysisEnum);
+	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
+
+	/*set analysis type to compute velocity: */
+	_printf_("%s\n","      computing velocities");
+	if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum);
+	else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum);
+	solver_diagnostic_nonlinear(femmodel,conserve_loads); 
+
+	/*Update inputs using adjoint solution, and same type of setup as diagnostic solution: */
+	_printf_("%s\n","      computing adjoint");
+	if(isstokes)femmodel->SetCurrentConfiguration(DiagnosticStokesAnalysisEnum,AdjointStokesAnalysisEnum);
+	else femmodel->SetCurrentConfiguration(DiagnosticHorizAnalysisEnum,AdjointHorizAnalysisEnum);
+	solver_adjoint_linear(femmodel);
+	
+	if(solution_type==AdjointSolutionEnum && !control_analysis){
+		if(verbose)_printf_("saving results:\n");
+		InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointxEnum);
+		InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointyEnum);
+		if (isstokes){
+			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointzEnum);
+			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,AdjointpEnum);
+		}
+	}
+}
Index: /issm/trunk/src/c/solutions/control_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/control_core.cpp	(revision 5377)
+++ /issm/trunk/src/c/solutions/control_core.cpp	(revision 5378)
@@ -37,6 +37,7 @@
 	OptPars optpars;
 
-	/*Solution core pointer*/
+	/*Solution and Adjoint core pointer*/
 	void (*solutioncore)(FemModel*)=NULL;
+	void (*adjointcore)(FemModel*)=NULL;
 
 	/*output: */
@@ -57,6 +58,7 @@
 	/*}}}*/
 
-	/*out of solution_type, figure out solution core function pointer*/
+	/*out of solution_type, figure out solution core and adjoint function pointer*/
 	CorePointerFromSolutionEnum(&solutioncore,solution_type);
+	AdjointCorePointerFromSolutionEnum(&adjointcore,solution_type);
 
 	/*some preliminary work to be done if running full-Stokes analysis: */
@@ -81,4 +83,7 @@
 		/*In case we are running a steady state control method, compute new temperature field using new parameter distribution: */
 		if (solution_type==SteadystateSolutionEnum) solutioncore(femmodel);
+
+		_printf_("%s\n","      compute adjoint state:");
+		adjointcore(femmodel);
 	
 		_printf_("%s\n","      computing gradJ...");
Index: /issm/trunk/src/c/solutions/gradient_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/gradient_core.cpp	(revision 5377)
+++ /issm/trunk/src/c/solutions/gradient_core.cpp	(revision 5378)
@@ -17,6 +17,8 @@
 	/*parameters: */
 	bool control_steady;
-	int control_type;
-	int verbose;
+	int  control_type;
+	int  verbose;
+
+	/*Intermediaries*/
 	Vec new_gradient=NULL;
 	Vec gradient=NULL;
@@ -28,7 +30,4 @@
 	femmodel->parameters->FindParam(&verbose,VerboseEnum);
 
-	if(verbose)_printf_("%s\n","      compute adjoint state:");
-	adjoint_core(femmodel);
-	
 	if(verbose)_printf_("%s\n","      compute gradient:");
 	Gradjx(&gradient, femmodel->elements,femmodel->nodes, femmodel->vertices,femmodel->loads, femmodel->materials,femmodel->parameters, control_type);
Index: /issm/trunk/src/c/solutions/solutions.h
===================================================================
--- /issm/trunk/src/c/solutions/solutions.h	(revision 5377)
+++ /issm/trunk/src/c/solutions/solutions.h	(revision 5378)
@@ -13,5 +13,6 @@
 
 /*cores: */
-void adjoint_core(FemModel* femmodel);
+void adjointdiagnostic_core(FemModel* femmodel);
+void adjointbalancedthickness_core(FemModel* femmodel);
 void gradient_core(FemModel* femmodel,int step=0, double search_scalar=0);
 void diagnostic_core(FemModel* femmodel);
@@ -49,4 +50,5 @@
 void SolutionConfiguration(int** panalyses,int* pnumanalyses, void (**psolutioncore)(FemModel*),int solutiontype);
 void CorePointerFromSolutionEnum(void (**psolutioncore)(FemModel*),int solutiontype);
+void AdjointCorePointerFromSolutionEnum(void (**padjointcore)(FemModel*),int solutiontype);
 
 #endif
