Index: ../trunk-jpl/src/c/analyses/Balancethickness2Analysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/Balancethickness2Analysis.cpp	(revision 18649)
+++ ../trunk-jpl/src/c/analyses/Balancethickness2Analysis.cpp	(revision 18650)
@@ -81,10 +81,10 @@
 	element->GetVerticesCoordinates(&xyz_list);
 	Input* omega_input = element->GetInput(BalancethicknessOmegaEnum); _assert_(omega_input);
 	Input* D0_input    = element->GetInput(BalancethicknessD0Enum);
-	//if(!D0_input){
+	if(!D0_input){
 		this->CreateD0(element);
 		D0_input = element->GetInput(BalancethicknessD0Enum); _assert_(D0_input);
-	//}
+	}
 
 	/* Start  looping on the number of gaussian points: */
 	Gauss* gauss=element->NewGauss(2);
Index: ../trunk-jpl/src/c/cores/controlm1qn3_core.cpp
===================================================================
--- ../trunk-jpl/src/c/cores/controlm1qn3_core.cpp	(revision 18649)
+++ ../trunk-jpl/src/c/cores/controlm1qn3_core.cpp	(revision 18650)
@@ -112,7 +112,17 @@
 		default: _printf0_("   Unknown end condition\n");
 	}
 
-	/*Get solution*/
+	/*Constrain solution vector*/
+	IssmDouble  *XL = NULL;
+	IssmDouble  *XU = NULL;
+	GetVectorFromControlInputsx(&XL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"lowerbound");
+	GetVectorFromControlInputsx(&XU,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"upperbound");
+	if(num_controls!=1) _error_("not supported yet");
+	for(long i=0;i<n;i++){
+		X[i] = X[i]*scaling_factors[0];
+		if(X[i]>XU[i]) X[i]=XU[i];
+		if(X[i]<XL[i]) X[i]=XL[i];
+	}
 	SetControlInputsFromVectorx(femmodel,X);
 	ControlInputSetGradientx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,G);
 	femmodel->OutputControlsx(&femmodel->results);
@@ -129,6 +139,8 @@
 	xDelete<double>(G);
 	xDelete<double>(X);
 	xDelete<double>(dz);
+	xDelete<double>(XU);
+	xDelete<double>(XL);
 }
 
 /*Cost function definition*/
