Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 25760)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 25761)
@@ -12,5 +12,5 @@
 #include "../InputUpdateFromConstantx/InputUpdateFromConstantx.h"
 #include "../InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.h"
-
+			
 void  InputUpdateFromDakotax(FemModel* femmodel,double* variables,char* *variables_descriptors,int numdakotavariables){ /*{{{*/
 
@@ -34,27 +34,27 @@
 
 	/*retrieve parameters: */
-	femmodel->parameters->FindParam(&variable_partitions,&variable_partitions_num,NULL,NULL,QmuVariablePartitionsEnum);
-	femmodel->parameters->FindParam(&variable_partitions_npart,NULL,NULL,QmuVariablePartitionsNpartEnum);
-	femmodel->parameters->FindParam(&variable_partitions_nt,NULL,NULL,QmuVariablePartitionsNtEnum);
-
-
-	/*Go through all dakota descriptors, ex: "rho_ice","thermal_conductivity","thickness1","thickness2", etc ..., and
-	 * for each descriptor, take the variable value and plug it into the inputs (more or less :)):
-	 * We also start with distributed and standard values , as they tend to be used to pluck data from a multi-modle ensemble (mme)
-	 * which can then be scaled. Doing the scaling first would be impractical, as the entire mme would have to be scaled,
+	femmodel->parameters->FindParam(&variable_partitions,&variable_partitions_num,NULL,NULL,QmuVariablePartitionsEnum); 
+	femmodel->parameters->FindParam(&variable_partitions_npart,NULL,NULL,QmuVariablePartitionsNpartEnum); 
+	femmodel->parameters->FindParam(&variable_partitions_nt,NULL,NULL,QmuVariablePartitionsNtEnum); 
+	
+
+	/*Go through all dakota descriptors, ex: "rho_ice","thermal_conductivity","thickness1","thickness2", etc ..., and 
+	 * for each descriptor, take the variable value and plug it into the inputs (more or less :)): 
+	 * We also start with distributed and standard values , as they tend to be used to pluck data from a multi-modle ensemble (mme) 
+	 * which can then be scaled. Doing the scaling first would be impractical, as the entire mme would have to be scaled, 
 	 * which is a waste of time:*/
 
 	variablecount=0;
-	for(i=0;i<numdakotavariables;i++){ //these are the dakota variables, for all partitions.
+	for(i=0;i<numdakotavariables;i++){ //these are the dakota variables, for all partitions. 
 
 		descriptor=variables_descriptors[i];
-
+	
 
 		/*From descriptor, figure out if the variable is scaled, indexed, distributed or just a simple variable: */
-		if (strncmp(descriptor,"scaled_",7)==0){
+		if (strncmp(descriptor,"scaled_",7)==0){ 
 			/*we are skipping these for now.*/
 			npart=variable_partitions_npart[variablecount];
 			nt=variable_partitions_nt[variablecount];
-
+				
 			/*increment i to skip the distributed values just collected: */
 			i+=npart*nt-1; //careful, the for loop will add 1.
@@ -66,13 +66,13 @@
 			/*we are skipping these for now.*/
 		}
-
+		
 		else if (strncmp(descriptor,"distributed_",12)==0){
 			if (VerboseQmu())_printf0_("   updating variable " << descriptor << "\n");
-
+			
 			/*recover partition vector: */
 			variable_partition=variable_partitions[variablecount];
 			npart=variable_partitions_npart[variablecount];
 
-			/*Variable is distributed. Determine root name of variable (ex: distributed_DragCoefficient_1 -> DragCoefficient).
+			/*Variable is distributed. Determine root name of variable (ex: distributed_DragCoefficient_1 -> DragCoefficient). 
 			 * Allocate distributed_values and fill the distributed_values with the next npart variables: */
 
@@ -86,11 +86,11 @@
 
 			//for (int j=0;j<npart;j++)_printf_(j << ":" << distributed_values[j] << "\n");
-
+			
 			//Call specialty code:
 			InputUpdateSpecialtyCode(femmodel,distributed_values,variable_partition,npart,root);
-
+			
 			/*increment i to skip the distributed values just collected: */
 			i+=npart-1; //careful, the for loop will add 1.
-
+			
 			/*Free allocations: */
 			xDelete<double>(parameter);
@@ -104,16 +104,16 @@
 		variablecount++;
 	}
-
+	
 	variablecount=0;
 	/*now deal with scaled variabes:*/
-	for(i=0;i<numdakotavariables;i++){ //these are the dakota variables, for all partitions.
+	for(i=0;i<numdakotavariables;i++){ //these are the dakota variables, for all partitions. 
 
 		descriptor=variables_descriptors[i];
-
+	
 		/*From descriptor, figure out if the variable is scaled, indexed, distributed or just a simple variable: */
 		if (strncmp(descriptor,"scaled_",7)==0){
-
+		
 			if (VerboseQmu())_printf0_("   updating variable " << descriptor << "\n");
-
+		
 			/*recover partition vector: */
 			variable_partition=variable_partitions[variablecount];
@@ -121,5 +121,5 @@
 			nt=variable_partitions_nt[variablecount];
 
-			/* Variable is scaled, determine its root name (ex: scaled_DragCoefficient_1 -> DragCoefficient). Allocate distributed_values and fill the
+			/* Variable is scaled, determine its root name (ex: scaled_DragCoefficient_1 -> DragCoefficient). Allocate distributed_values and fill the 
 			 * distributed_values with the next npart variables coming from Dakota: */
 			memcpy(root,strstr(descriptor,"_")+1,(strlen(strstr(descriptor,"_")+1)+1)*sizeof(char));
@@ -136,5 +136,5 @@
 			/*increment i to skip the distributed values just collected: */
 			i+=npart*nt-1; //careful, the for loop will add 1.
-
+			
 			/*Free allocations: */
 			xDelete<double>(parameter);
@@ -202,33 +202,44 @@
 	transientinput2 = femmodel->inputs->GetTransientInput(DummyEnum);
 
-	for(Object* & object : femmodel->elements->objects){
-		Tria*   element=xDynamicCast<Tria*>(object);
-
-		if((int)variable_partition[element->Sid()]==-1)id=0; //grab background field
-		else id=distributed_values[(int)variable_partition[element->Sid()]]-1; //grab partition field
-
-		/*recover the right field from the mme: */
-		transientinput = datasetinput->GetTransientInputByOffset(id); _assert_(transientinput);
-
-		/*copy values from the transientinput to the final transientinput2: */
-		for (int j=0;j<N;j++){
-			TriaInput* tria_input=transientinput->GetTriaInput(j);
-			element->InputServe(tria_input);
-			if(interpolationenum==P0Enum){
-				value=tria_input->element_values[0];
-				transientinput2->AddTriaTimeInput( j,1,&(element->lid),&value,P0Enum);
-			}
-			else if(interpolationenum==P1Enum){
-
-				/*Get values and lid list*/
-				const int   numvertices     = element->GetNumberOfVertices();
-				int        *vertexlids      = xNew<int>(numvertices);
-				int        *vertexsids      = xNew<int>(numvertices);
-
-				/*Recover vertices ids needed to initialize inputs*/
-				element->GetVerticesLidList(&vertexlids[0]);
-				element->GetVerticesSidList(&vertexsids[0]);
-				values=tria_input->element_values;
-				transientinput2->AddTriaTimeInput( j,numvertices,vertexlids,values,P1Enum);
+	for (int p=npart;p>=0;p--){
+		int pp=p; 
+		if (p==npart)pp=-1; /*so, the logic is, we want to do the -1 partition first, then 
+							 go from npart-1 to 0 in reverse order:*/
+		
+		for (int i=0;i<femmodel->elements->Size();i++){
+			int element_partition;
+
+			Tria*   element=xDynamicCast<Tria*>(femmodel->elements->GetObjectByOffset(i));
+			
+			element_partition= (int)variable_partition[element->Sid()];
+			if(element_partition!=pp)continue;
+
+			if(element_partition==-1)id=0; //grab background field
+			else id=distributed_values[element_partition]-1; //grab partition field
+
+			/*recover the right field from the mme: */
+			transientinput = datasetinput->GetTransientInputByOffset(id); _assert_(transientinput);
+
+			/*copy values from the transientinput to the final transientinput2: */
+			for (int j=0;j<N;j++){
+				TriaInput* tria_input=transientinput->GetTriaInput(j);
+				element->InputServe(tria_input);
+				if(interpolationenum==P0Enum){
+					value=tria_input->element_values[0];
+					transientinput2->AddTriaTimeInput( j,1,&(element->lid),&value,P0Enum); 
+				}
+				else if(interpolationenum==P1Enum){
+
+					/*Get values and lid list*/
+					const int   numvertices     = element->GetNumberOfVertices();
+					int        *vertexlids      = xNew<int>(numvertices);
+					int        *vertexsids      = xNew<int>(numvertices);
+
+					/*Recover vertices ids needed to initialize inputs*/
+					element->GetVerticesLidList(&vertexlids[0]);
+					element->GetVerticesSidList(&vertexsids[0]);
+					values=tria_input->element_values;
+					transientinput2->AddTriaTimeInput( j,numvertices,vertexlids,values,P1Enum); 
+				}
 			}
 		}
@@ -247,10 +258,10 @@
 
 	/*Go through elements, copy input name to dummy, and scale it using the distributed_values and the partition vector:*/
-	for(Object* & object : femmodel->elements->objects){
-		Element* element=xDynamicCast<Element*>(object);
+	for(int i=0;i<femmodel->elements->Size();i++){
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputScaleFromDakota(distributed_values,partition,npart,nt,name);
 	}
 
-	/*We created a dummy input, which was a scaled copy of the name input. Now wipe
+	/*We created a dummy input, which was a scaled copy of the name input. Now wipe 
 	 * out the name input with the new input:*/
 	femmodel->inputs->ChangeEnum(DummyEnum,name);
