Index: /issm/trunk/src/c/DataSet/Inputs.cpp
===================================================================
--- /issm/trunk/src/c/DataSet/Inputs.cpp	(revision 4041)
+++ /issm/trunk/src/c/DataSet/Inputs.cpp	(revision 4042)
@@ -543,5 +543,5 @@
 		}
 	}
-	ISSMERROR("input with enum %i (%s) not found",enum_name,EnumAsString(enum_name));
+	return NULL;
 }
 /*}}}*/
Index: /issm/trunk/src/c/DataSet/Results.cpp
===================================================================
--- /issm/trunk/src/c/DataSet/Results.cpp	(revision 4041)
+++ /issm/trunk/src/c/DataSet/Results.cpp	(revision 4042)
@@ -62,5 +62,5 @@
 
 		/*Add result to new results*/
-		newresults->AddObject(resultout);
+		newresults->AddObject((Object*)resultout);
 	}
 
@@ -88,5 +88,5 @@
 
 		/*Add result to new results*/
-		newresults->AddObject(resultout);
+		newresults->AddObject((Object*)resultout);
 	}
 
@@ -114,5 +114,5 @@
 
 		/*Add result to new results*/
-		newresults->AddObject(resultout);
+		newresults->AddObject((Object*)resultout);
 	}
 
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 4041)
+++ /issm/trunk/src/c/Makefile.am	(revision 4042)
@@ -329,5 +329,5 @@
 					./modules/ModelProcessorx/SlopeCompute/UpdateElementsSlopeCompute.cpp\
 					./modules/ModelProcessorx/SlopeCompute/CreateNodesSlopeCompute.cpp \
-					./modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp \
+					./modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp\
 					./modules/ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp\
 					./modules/ModelProcessorx/Control/CreateParametersControl.cpp\
@@ -367,4 +367,8 @@
 					./modules/Dux/Dux.h\
 					./modules/Dux/Dux.cpp\
+					./modules/MinVelx/MinVelx.h\
+					./modules/MinVelx/MinVelx.cpp\
+					./modules/MaxVelx/MaxVelx.h\
+					./modules/MaxVelx/MaxVelx.cpp\
 					./modules/ControlConstrainx/ControlConstrainx.h\
 					./modules/ControlConstrainx/ControlConstrainx.cpp\
@@ -524,4 +528,5 @@
 					./objects/Bamg/GeometricalVertex.cpp\
 					./objects/Bamg/Geometry.h\
+					./objects/Bamg/Geometry.cpp\
 					./objects/Bamg/ListofIntersectionTriangles.cpp\
 					./objects/Bamg/ListofIntersectionTriangles.h\
@@ -541,4 +546,5 @@
 					./objects/Bamg/Triangle.h\
 					./objects/Bamg/Triangles.h\
+					./objects/Bamg/Triangles.cpp\
 					./objects/Bamg/MeshVertex.cpp\
 					./objects/Bamg/MeshVertex.h\
@@ -770,7 +776,6 @@
 					./EnumDefinitions/StringAsEnum.cpp\
 					./modules/ModelProcessorx/ModelProcessorx.h\
-					./modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp
-					./modules/ModelProcessorx/NodesPartitioning.cpp
-					./modules/ModelProcessorx/Partitioning.cpp\
+					./modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp\
+					./modules/ModelProcessorx/NodesPartitioning.cpp\
 					./modules/ModelProcessorx/SortDataSets.cpp\
 					./modules/ModelProcessorx/UpdateCounters.cpp\
@@ -781,52 +786,52 @@
 					./modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp\
 					./modules/ModelProcessorx/DiagnosticHoriz/UpdateElementsDiagnosticHoriz.cpp\
+					./modules/ModelProcessorx/DiagnosticHoriz/CreateNodesDiagnosticHoriz.cpp \
 					./modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp \
 					./modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp\
-					./modules/ModelProcessorx/DiagnosticHoriz/CreateNodesDiagnosticHoriz.cpp\
-					./modules/ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp\
+					./modules/ModelProcessorx/DiagnosticVert/UpdateElementsDiagnosticVert.cpp\
+					./modules/ModelProcessorx/DiagnosticVert/CreateNodesDiagnosticVert.cpp \
 					./modules/ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp \
 					./modules/ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp\
-					./modules/ModelProcessorx/DiagnosticVert/CreateNodesDiagnosticVert.cpp\
-					./modules/ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp\
+					./modules/ModelProcessorx/DiagnosticHutter/UpdateElementsDiagnosticHutter.cpp\
+					./modules/ModelProcessorx/DiagnosticHutter/CreateNodesDiagnosticHutter.cpp \
 					./modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp \
 					./modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp\
-					./modules/ModelProcessorx/DiagnosticHutter/CreateNodesDiagnosticHutter.cpp\
-					./modules/ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp\
+					./modules/ModelProcessorx/DiagnosticStokes/UpdateElementsDiagnosticStokes.cpp\
+					./modules/ModelProcessorx/DiagnosticStokes/CreateNodesDiagnosticStokes.cpp \
 					./modules/ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp \
 					./modules/ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp\
-					./modules/ModelProcessorx/DiagnosticStokes/CreateNodesDiagnosticStokes.cpp\
-					./modules/ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp\
-					./modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp \
+					./modules/ModelProcessorx/SlopeCompute/UpdateElementsSlopeCompute.cpp\
+					./modules/ModelProcessorx/SlopeCompute/CreateNodesSlopeCompute.cpp \
+					./modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp\
 					./modules/ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp\
-					./modules/ModelProcessorx/SlopeCompute/CreateNodesSlopeCompute.cpp\
 					./modules/ModelProcessorx/Control/CreateParametersControl.cpp\
-					./modules/ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp\
+					./modules/ModelProcessorx/Thermal/UpdateElementsThermal.cpp\
+					./modules/ModelProcessorx/Thermal/CreateNodesThermal.cpp\
 					./modules/ModelProcessorx/Thermal/CreateConstraintsThermal.cpp\
 					./modules/ModelProcessorx/Thermal/CreateLoadsThermal.cpp\
-					./modules/ModelProcessorx/Thermal/CreateNodesThermal.cpp\
-					./modules/ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp\
+					./modules/ModelProcessorx/Melting/UpdateElementsMelting.cpp\
+					./modules/ModelProcessorx/Melting/CreateNodesMelting.cpp\
 					./modules/ModelProcessorx/Melting/CreateConstraintsMelting.cpp\
 					./modules/ModelProcessorx/Melting/CreateLoadsMelting.cpp\
-					./modules/ModelProcessorx/Melting/CreateNodesMelting.cpp\
-					./modules/ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic/UpdateElementsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic/CreateNodesPrognostic.cpp\
 					./modules/ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp\
 					./modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp\
-					./modules/ModelProcessorx/Prognostic/CreateNodesPrognostic.cpp\
-					./modules/ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp\
+					./modules/ModelProcessorx/Prognostic2/UpdateElementsPrognostic2.cpp\
+					./modules/ModelProcessorx/Prognostic2/CreateNodesPrognostic2.cpp\
 					./modules/ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp\
 					./modules/ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp\
-					./modules/ModelProcessorx/Prognostic2/CreateNodesPrognostic2.cpp\
-					./modules/ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness/UpdateElementsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness/CreateNodesBalancedthickness.cpp\
 					./modules/ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp\
 					./modules/ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp\
-					./modules/ModelProcessorx/Balancedthickness/CreateNodesBalancedthickness.cpp\
-					./modules/ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/UpdateElementsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/CreateNodesBalancedthickness2.cpp\
 					./modules/ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp\
 					./modules/ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp\
-					./modules/ModelProcessorx/Balancedthickness2/CreateNodesBalancedthickness2.cpp\
-					./modules/ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/UpdateElementsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/CreateNodesBalancedvelocities.cpp\
 					./modules/ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp\
 					./modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp\
-					./modules/ModelProcessorx/Balancedvelocities/CreateNodesBalancedvelocities.cpp\
 					./modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp\
 					./modules/VerticesDofx/VerticesDofx.h\
@@ -838,4 +843,8 @@
 					./modules/Dux/Dux.h\
 					./modules/Dux/Dux.cpp\
+					./modules/MinVelx/MinVelx.h\
+					./modules/MinVelx/MinVelx.cpp\
+					./modules/MaxVelx/MaxVelx.h\
+					./modules/MaxVelx/MaxVelx.cpp\
 					./modules/ControlConstrainx/ControlConstrainx.h\
 					./modules/ControlConstrainx/ControlConstrainx.cpp\
Index: /issm/trunk/src/c/modules/MaxVelx/MaxVelx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxVelx/MaxVelx.cpp	(revision 4042)
+++ /issm/trunk/src/c/modules/MaxVelx/MaxVelx.cpp	(revision 4042)
@@ -0,0 +1,47 @@
+/*!\file MaxVelx
+ * \brief: compute misfit between observations and model
+ */
+
+#include "./MaxVelx.h"
+
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../SurfaceAreax/SurfaceAreax.h"
+
+void MaxVelx( double* pmaxvel, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials,Parameters* parameters){
+	
+	int i;
+	double maxvel;
+	double node_maxvel;
+	bool   process_units=true;
+
+	/*First, configure elements:*/
+	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
+
+	/*Go through elements, and request velocity: */
+	for(i=0;i<elements->Size();i++){
+		Element* element=(Element*)elements->GetObjectByOffset(i);
+		element->MaxVel(&element_maxvel,process_units); //go pick up the maximum velocity in the inputs
+	
+		if(i==0)maxvel=element_maxvel; //initialize maxvel
+		else{
+			if(element_maxvel>maxvel)maxvel=element_maxvel;
+		}
+	}
+	/*A safeguard in case: */
+	if(elements->Size()==0){
+		maxvel=-INFINITY;
+	}
+
+	#ifdef _PARALLEL_
+	/*Figure out maximum across the cluster: */
+	MPI_Reduce (&maxvel,&node_maxvel,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
+	MPI_Bcast(&node_maxvel,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
+	maxvel=node_maxvel;
+	#endif
+
+	/*Assign output pointers:*/
+	*pmaxvel=maxvel;
+}
Index: /issm/trunk/src/c/modules/MaxVelx/MaxVelx.h
===================================================================
--- /issm/trunk/src/c/modules/MaxVelx/MaxVelx.h	(revision 4042)
+++ /issm/trunk/src/c/modules/MaxVelx/MaxVelx.h	(revision 4042)
@@ -0,0 +1,15 @@
+/*!\file:  MaxVelx.h
+ * \brief header file for inverse methods misfit computation
+ */ 
+
+#ifndef _MAXVELX_H
+#define _MAXVELX_H
+
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+
+/* local prototypes: */
+void MaxVelx( double* pmaxvel, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters);
+
+#endif  /* _MAXVELX_H */
+
Index: /issm/trunk/src/c/modules/MinVelx/MinVelx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MinVelx/MinVelx.cpp	(revision 4042)
+++ /issm/trunk/src/c/modules/MinVelx/MinVelx.cpp	(revision 4042)
@@ -0,0 +1,47 @@
+/*!\file MinVelx
+ * \brief: compute misfit between observations and model
+ */
+
+#include "./MinVelx.h"
+
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../SurfaceAreax/SurfaceAreax.h"
+
+void MinVelx( double* pminvel, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials,Parameters* parameters){
+	
+	int i;
+	double minvel;
+	double node_minvel;
+	bool   process_units=true;
+
+	/*First, configure elements:*/
+	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
+
+	/*Go through elements, and request velocity: */
+	for(i=0;i<elements->Size();i++){
+		Element* element=(Element*)elements->GetObjectByOffset(i);
+		element->MinVel(&element_minvel,process_units); //go pick up the minimum velocity in the inputs
+	
+		if(i==0)minvel=element_minvel; //initialize minvel
+		else{
+			if(element_minvel<minvel)minvel=element_minvel;
+		}
+	}
+	/*A safeguard in case: */
+	if(elements->Size()==0){
+		minvel=INFINITY;
+	}
+
+	#ifdef _PARALLEL_
+	/*Figure out minimum across the cluster: */
+	MPI_Reduce (&minvel,&node_minvel,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD );
+	MPI_Bcast(&node_minvel,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
+	minvel=node_minvel;
+	#endif
+
+	/*Assign output pointers:*/
+	*pminvel=minvel;
+}
Index: /issm/trunk/src/c/modules/MinVelx/MinVelx.h
===================================================================
--- /issm/trunk/src/c/modules/MinVelx/MinVelx.h	(revision 4042)
+++ /issm/trunk/src/c/modules/MinVelx/MinVelx.h	(revision 4042)
@@ -0,0 +1,15 @@
+/*!\file:  MinVelx.h
+ * \brief header file for inverse methods misfit computation
+ */ 
+
+#ifndef _MINVELX_H
+#define _MINVELX_H
+
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+
+/* local prototypes: */
+void MinVelx( double* pminvel, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters);
+
+#endif  /* _MINVELX_H */
+
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 4041)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 4042)
@@ -15,7 +15,12 @@
 #include "../../objects/objects.h"
 		
-void OutputResults(FemModel* femmodel, char* filename){
+void OutputResults(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters, char* filename){
+
+	int i;
+
+	Patch* patch=NULL;
 
 	int solutiontype;
+	int count;
 	int numrows;
 	int numvertices;
@@ -23,14 +28,17 @@
 	int max_numvertices;
 	int max_numnodes;
+	int element_numvertices;
+	int element_numrows;
+	int element_numnodes;
 
 	/*First, configure elements*/
-	femmodel->elements->Configure(elements,loads, nodes,vertices, materials,parameters);
+	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
 
 	//Recover solutiontype which will be output to disk: 
-	femmodel->parameters->FindParam(&solutiontype,SolutionTypeEnum);
+	parameters->FindParam(&solutiontype,SolutionTypeEnum);
 
 	//Process results to be output in the correct units
-	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=femmodel->elements->GetObjectByOffset(i);
+	for(i=0;i<elements->Size();i++){
+		Element* element=(Element*)elements->GetObjectByOffset(i);
 		element->ProcessResultsUnits();
 	}
@@ -58,6 +66,6 @@
 	numnodes=0;
 
-	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=femmodel->elements->GetObjectByOffset(i);
+	for(i=0;i<elements->Size();i++){
+		Element* element=(Element*)elements->GetObjectByOffset(i);
 		element->PatchSize(&element_numrows,&element_numvertices,&element_numnodes);
 
@@ -94,3 +102,6 @@
 	patch->WriteToDisk(solutiontype,filename);
 
+	/*Free ressources:*/
+	delete patch;
+
 }
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 4041)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 4042)
@@ -9,5 +9,5 @@
 
 /* local prototypes: */
-void OutputResults(FemModel* femmodel, char* filename);
+void OutputResults(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters, char* filename);
 
 #endif  /* _OUTPUTRESULTS_H */
Index: /issm/trunk/src/c/modules/Qmux/DakotaResponses.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/DakotaResponses.cpp	(revision 4041)
+++ /issm/trunk/src/c/modules/Qmux/DakotaResponses.cpp	(revision 4042)
@@ -17,15 +17,13 @@
 #include "../modules.h"
 
-void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,Model* model,Results* results,Results* processed_results,int analysis_type,int sub_analysis_type){
+void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,FemModel* femmodel){
 
-	int i,j;
-	int found=0;
+	int i;
+	extern int my_rank;
+	
+	/*intermediary: */
 	char* response_descriptor=NULL;
-	int numberofnodes;
-	extern int my_rank;
-
-	/*some data needed across the responses: */
-	model->FindParam(&numberofnodes,NumberOfNodesEnum);
-
+	double femmodel_response;
+			
 
 	for(i=0;i<numresponses;i++){
@@ -33,305 +31,51 @@
 		response_descriptor=responses_descriptors[i];
 
-		//'min_vx' 'max_vx' 'max_abs_vx' 'min_vy' 'max_vy' 'max_abs_vy' 'min_vel' 'max_vel, mass_flux'
+		/*Compute response for this response_descriptor:*/
 
 		if(strcmp(response_descriptor,"min_vel")==0){
-			double* vel=NULL;
-			double min_vel=0;
-		
-			found=processed_results->FindResult((void*)&vel,"vel");
-			if(!found)ISSMERROR(" could not find vel to compute min_vel");
-
-			min_vel=vel[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vel[j]<min_vel)min_vel=vel[j];
-			}
-
-			if(my_rank==0)responses[i]=min_vel;
-			
-			/*Free ressources:*/
-			xfree((void**)&vel);
-
-			
+			MinVelx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"max_vel")==0){
-			double* vel=NULL;
-			double max_vel=0;
-
-			found=processed_results->FindResult((void*)&vel,"vel");
-			if(!found)ISSMERROR(" could not find vel to compute max_vel");
-
-			max_vel=vel[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vel[j]>max_vel)max_vel=vel[j];
-			}
-			if(my_rank==0)responses[i]=max_vel;
-			
-			/*Free ressources:*/
-			xfree((void**)&vel);
-
+			MaxVelx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"min_vx")==0){
-			double* vx=NULL;
-			double min_vx=0;
-			
-			found=processed_results->FindResult((void*)&vx,"vx");
-			if(!found)ISSMERROR(" could not find vx to compute min_vx");
-
-			min_vx=vx[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vx[j]<min_vx)min_vx=vx[j];
-			}
-			if(my_rank==0)responses[i]=min_vx;
-			
-			/*Free ressources:*/
-			xfree((void**)&vx);
-
+			MinVxx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"max_vx")==0){
-			double* vx=NULL;
-			double max_vx=0;
-			
-			found=processed_results->FindResult((void*)&vx,"vx");
-			if(!found)ISSMERROR(" could not find vx to compute max_vx");
-
-			max_vx=vx[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vx[j]>max_vx)max_vx=vx[j];
-			}
-			if(my_rank==0)responses[i]=max_vx;
-			
-			/*Free ressources:*/
-			xfree((void**)&vx);
-
+			MaxVxx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"max_abs_vx")==0){
-			double* vx=NULL;
-			double max_abs_vx=0;
-			
-			found=processed_results->FindResult((void*)&vx,"vx");
-			if(!found)ISSMERROR(" could not find vx to compute max_abs_vx");
-
-			max_abs_vx=fabs(vx[0]);
-			for(j=1;j<numberofnodes;j++){
-				if (fabs(vx[j])>max_abs_vx)max_abs_vx=fabs(vx[j]);
-			}
-			if(my_rank==0)responses[i]=max_abs_vx;
-			
-			/*Free ressources:*/
-			xfree((void**)&vx);
-
+			MaxAbsVxx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"min_vy")==0){
-			double* vy=NULL;
-			double min_vy=0;
-			
-			found=processed_results->FindResult((void*)&vy,"vy");
-			if(!found)ISSMERROR(" could not find vy to compute min_vy");
-
-			min_vy=vy[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vy[j]<min_vy)min_vy=vy[j];
-			}
-			if(my_rank==0)responses[i]=min_vy;
-			
-			/*Free ressources:*/
-			xfree((void**)&vy);
-
+			MinVyx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"max_vy")==0){
-			double* vy=NULL;
-			double max_vy=0;
-			
-			found=processed_results->FindResult((void*)&vy,"vy");
-			if(!found)ISSMERROR(" could not find vy to compute max_vy");
-
-			max_vy=vy[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vy[j]>max_vy)max_vy=vy[j];
-			}
-			if(my_rank==0)responses[i]=max_vy;
-			
-			/*Free ressources:*/
-			xfree((void**)&vy);
-
+			MaxVyx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"max_abs_vy")==0){
-			double* vy=NULL;
-			double max_abs_vy=0;
-			
-			found=processed_results->FindResult((void*)&vy,"vy");
-			if(!found)ISSMERROR(" could not find vy to compute max_abs_vy");
-
-			max_abs_vy=fabs(vy[0]);
-			for(j=1;j<numberofnodes;j++){
-				if (fabs(vy[j])>max_abs_vy)max_abs_vy=fabs(vy[j]);
-			}
-			if(my_rank==0)responses[i]=max_abs_vy;
-			
-			/*Free ressources:*/
-			xfree((void**)&vy);
-
+			MaxAbsVyx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"min_vz")==0){
-			double* vz=NULL;
-			double min_vz=0;
-			
-			found=processed_results->FindResult((void*)&vz,"vz");
-			if(!found)ISSMERROR(" could not find vz to compute min_vz");
-
-			min_vz=vz[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vz[j]<min_vz)min_vz=vz[j];
-			}
-			if(my_rank==0)responses[i]=min_vz;
-			
-			/*Free ressources:*/
-			xfree((void**)&vz);
-
+			MinVzx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"max_vz")==0){
-			double* vz=NULL;
-			double max_vz=0;
-			
-			found=processed_results->FindResult((void*)&vz,"vz");
-			if(!found)ISSMERROR(" could not find vz to compute max_vz");
-
-			max_vz=vz[0];
-			for(j=1;j<numberofnodes;j++){
-				if (vz[j]>max_vz)max_vz=vz[j];
-			}
-			if(my_rank==0)responses[i]=max_vz;
-			
-			/*Free ressources:*/
-			xfree((void**)&vz);
-
+			MaxVzx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"max_abs_vz")==0){
-			double* vz=NULL;
-			double max_abs_vz=0;
-			
-			found=processed_results->FindResult((void*)&vz,"vz");
-			if(!found)ISSMERROR(" could not find vz to compute max_abs_vz");
-
-			max_abs_vz=fabs(vz[0]);
-			for(j=1;j<numberofnodes;j++){
-				if (fabs(vz[j])>max_abs_vz)max_abs_vz=fabs(vz[j]);
-			}
-			if(my_rank==0)responses[i]=max_abs_vz;
-			
-			/*Free ressources:*/
-			xfree((void**)&vz);
+			MaxAbsVzx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"misfit")==0){
-			
-			int isstokes,ismacayealpattyn,ishutter;
-			FemModel* femmodel=NULL;
-			double J=0;
-			int numberofdofspernode,numberofnodes;
-			Vec u_g=NULL;
-			double* u_g_double=NULL;
-			double* vx=NULL;
-			double* vy=NULL;
-			double* vz=NULL;
-			double* fit=NULL;
-
-			/*retrieve active fem model: */
-			model->FindParam(&isstokes,IsStokesEnum);
-			model->FindParam(&ismacayealpattyn,IsMacAyealPattynEnum);
-			model->FindParam(&ishutter,IsHutterEnum);
-
-			if(isstokes){
-				femmodel=model->GetFormulation(DiagnosticAnalysisEnum,StokesAnalysisEnum);
-			}
-			if(ismacayealpattyn){
-				femmodel=model->GetFormulation(DiagnosticAnalysisEnum,HorizAnalysisEnum);
-			}
-			if(ishutter){
-				femmodel=model->GetFormulation(DiagnosticAnalysisEnum,HutterAnalysisEnum);
-			}	
-
-
-			/*Recover some parameters: */
-			femmodel->parameters->FindParam(&numberofdofspernode,NumberOfDofsPerNodeEnum);
-			femmodel->parameters->FindParam(&numberofnodes,NumberOfNodesEnum);
-			femmodel->parameters->FindParam(&fit,NULL,NULL,FitEnum);
-
-			/*Recover velocity: */
-			found=results->FindResult(&u_g,"u_g");
-			VecToMPISerial(&u_g_double,u_g);
-			if(!found)ISSMERROR(" could not find velocity to compute misfit");
-
-			SplitSolutionVectorx(u_g,numberofnodes,numberofdofspernode,&vx,&vy,&vz);
-
-			/*Add to inputs: */
-			femmodel->elements->UpdateInputsFromVector(vx,VxEnum,VertexEnum);
-			femmodel->elements->UpdateInputsFromVector(vy,VyEnum,VertexEnum);
-			femmodel->elements->UpdateInputsFromVector(vz,VzEnum,VertexEnum);
-			femmodel->elements->UpdateInputsFromVector(&fit[0],FitEnum,ConstantEnum);
-
-			/*Compute misfit: */
-			Misfitx( &J, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,analysis_type,sub_analysis_type);
-			
-
-			if(my_rank==0)responses[i]=J;
-
-			/*Some cleanup: */
-			VecFree(&u_g);
-			xfree((void**)&u_g_double);
-			xfree((void**)&fit);
-
+			Misfitx( &femmodel_response, femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters);
 		}
 		else if(strcmp(response_descriptor,"mass_flux")==0){
-
-			int isstokes,ismacayealpattyn,ishutter;
-			Vec       ug=NULL;
-			double*   ug_serial=NULL;
-			double    mass_flux=0;
-			double*   segments=NULL;
-			int       num_segments;
-			DataSet*  elements=NULL;
-			DataSet*  nodes=NULL;
-			DataSet*  materials=NULL;
-			DataSet*  parameters=NULL;
-			FemModel* femmodel=NULL;
-			Param*    param=NULL;
-
-			/*retrieve velocities: */
-			found=results->FindResult(&ug,"u_g");
-			if(!found)ISSMERROR(" could not find velocity to compute mass_flux");
-			VecToMPISerial(&ug_serial,ug);
-		
-			/*retrieve active fem model: */
-			model->FindParam(&isstokes,IsStokesEnum);
-			model->FindParam(&ismacayealpattyn,IsMacAyealPattynEnum);
-			model->FindParam(&ishutter,IsHutterEnum);
-
-			if(isstokes){
-				femmodel=model->GetFormulation(DiagnosticAnalysisEnum,StokesAnalysisEnum);
-			}
-			if(ismacayealpattyn){
-				femmodel=model->GetFormulation(DiagnosticAnalysisEnum,HorizAnalysisEnum);
-			}
-			if(ishutter){
-				femmodel=model->GetFormulation(DiagnosticAnalysisEnum,HutterAnalysisEnum);
-			}
-
-			/*retrieve qmu_mass_flux_segments: */
-			femmodel->parameters->FindParam(&segments,&num_segments,QmuMassFluxSegmentsEnum);
-
-			/*call mass flux module: */
-			MassFluxx(&mass_flux,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,segments,num_segments,ug_serial);
-			
-			if(my_rank==0)responses[i]=mass_flux;
-			
-			/*Free ressources:*/
-			VecFree(&ug);
-			xfree((void**)&ug_serial);
-			xfree((void**)&segments);
+			MassFlux(&femmodel_response,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
 		}
 		else{
-			if(my_rank==0)printf("%s%s%s"," response descriptor : ",response_descriptor," not supported yet!");
 			ISSMERROR("%s%s%s"," response descriptor : ",response_descriptor," not supported yet!");
 		}
+			
+		/*send response back to Dakota only on cpu 0: */
+		if(my_rank==0)responses[i]=femmodel_response;
 	}
 
Index: /issm/trunk/src/c/modules/Qmux/Qmux.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/Qmux.cpp	(revision 4041)
+++ /issm/trunk/src/c/modules/Qmux/Qmux.cpp	(revision 4042)
@@ -51,7 +51,7 @@
 
 #ifdef _SERIAL_
-void Qmux(mxArray* model,int analysis_type,int sub_analysis_type,char* dakota_input_file,char* dakota_output_file,char* dakota_error_file){
+void Qmux(mxArray* femmodel,char* dakota_input_file,char* dakota_output_file,char* dakota_error_file){
 #else
-void Qmux(Model* model,int analysis_type,int sub_analysis_type){
+void Qmux(FemModel* femmodel){
 #endif
 
@@ -111,5 +111,5 @@
 
 			// Serial case: plug in derived Interface object without an analysisComm
-			interface.assign_rep(new SIM::DakotaPlugin(problem_db,(void*)model,analysis_type,sub_analysis_type), false);
+			interface.assign_rep(new SIM::DakotaPlugin(problem_db,(void*)femmodel), false);
 		}
 	
@@ -120,5 +120,5 @@
 		#ifdef _PARALLEL_
 		//Warn other cpus that we are done running the dakota iterator, by setting the counter to -1:
-		SpawnCore(NULL,0, NULL,NULL,0,model,analysis_type,sub_analysis_type,-1);
+		SpawnCore(NULL,0, NULL,NULL,0,femmodel,-1);
 		#endif
 
@@ -128,5 +128,5 @@
 
 		for(;;){
-			if(!SpawnCore(NULL,0, NULL,NULL,0,model,analysis_type,sub_analysis_type,0))break; //counter came in at -1 on cpu0, bail out.
+			if(!SpawnCore(NULL,0, NULL,NULL,0,femmodel,0))break; //counter came in at -1 on cpu0, bail out.
 		}
 	}
Index: /issm/trunk/src/c/modules/Qmux/Qmux.h
===================================================================
--- /issm/trunk/src/c/modules/Qmux/Qmux.h	(revision 4041)
+++ /issm/trunk/src/c/modules/Qmux/Qmux.h	(revision 4042)
@@ -10,12 +10,12 @@
 
 /* local prototypes: */
-int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* model,int analysis_type,int sub_analysis_type,int counter);
+int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* femmodel,int analysis_type,int sub_analysis_type,int counter);
 #ifdef _SERIAL_
-void Qmux(mxArray* model,int analysis_type,int sub_analysis_type,char* dakota_input_file,char* dakota_output_file,char* dakota_error_file);
-void SpawnCoreSerial(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, mxArray* model,int analysis_type,int sub_analysis_type,int counter);
+void Qmux(mxArray* femmodel,int analysis_type,int sub_analysis_type,char* dakota_input_file,char* dakota_output_file,char* dakota_error_file);
+void SpawnCoreSerial(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, mxArray* femmodel,int analysis_type,int sub_analysis_type,int counter);
 #else
-void Qmux(Model* model,int analysis_type,int sub_analysis_type);
-void SpawnCoreParallel(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, Model* model,int analysis_type,int sub_analysis_type,int counter);
-void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,Model* model, DataSet* results,DataSet* processed_results,int analysis_type,int sub_analysis_type);
+void Qmux(FemModel* femmodel,int analysis_type,int sub_analysis_type);
+void SpawnCoreParallel(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, FemModel* femmodel,int analysis_type,int sub_analysis_type,int counter);
+void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,FemModel* femmodel,int analysis_type,int sub_analysis_type);
 #endif
 
Index: /issm/trunk/src/c/modules/Qmux/SpawnCore.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/SpawnCore.cpp	(revision 4041)
+++ /issm/trunk/src/c/modules/Qmux/SpawnCore.cpp	(revision 4042)
@@ -17,14 +17,14 @@
 #include "../../include/include.h"
 
-int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* model,int analysis_type,int sub_analysis_type,int counter){
+int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* femmodel,int counter){
 
 	/*Branch into a serial SpawnCore and a parallel SpawnCore: */
 	#ifdef _SERIAL_
-	SpawnCoreSerial(responses, numresponses, variables, variables_descriptors,numvariables, (mxArray*)model, analysis_type,sub_analysis_type,counter);
+	SpawnCoreSerial(responses, numresponses, variables, variables_descriptors,numvariables, (mxArray*)femmodel, counter);
 	#else
 	/*Call SpawnCoreParallel unless counter=-1 on cpu0, in which case, bail out and return 0: */
 	MPI_Bcast(&counter,1,MPI_INT,0,MPI_COMM_WORLD); if(counter==-1)return 0;
 	
-	SpawnCoreParallel(responses, numresponses, variables, variables_descriptors,numvariables, (Model*)model, analysis_type,sub_analysis_type,counter);
+	SpawnCoreParallel(responses, numresponses, variables, variables_descriptors,numvariables, (FemModel*)femmodel);
 	#endif
 
Index: /issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp	(revision 4041)
+++ /issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp	(revision 4042)
@@ -34,22 +34,19 @@
 #include "../../solutions/solutions.h"
 
-void SpawnCoreParallel(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, Model* model,int analysis_type,int sub_analysis_type,int counter){
+void SpawnCoreParallel(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, FemModel* femmodel,int counter){
 
 	int i;
+	extern int my_rank;
 	
-	/*output from core solutions: */
-	Results* results=NULL;
-	Results* processed_results=NULL;
+	char   **responses_descriptors     = NULL;
+	int      num_responses_descriptors;
+	char    *string                    = NULL;
+	int      string_length;
+	double  *qmu_part                  = NULL;
+	int      qmu_npart;
+	int      verbose                   = 0;
+	int      dummy;
+	int      solution_type;
 
-	char** responses_descriptors=NULL;
-	int    num_responses_descriptors;
-	char*  string=NULL;
-	int    string_length;
-	double* qmu_part=NULL;
-	int     qmu_npart;
-	int     verbose=0;
-	int     dummy;
-
-	extern int my_rank;
 	
 	
@@ -58,12 +55,10 @@
 	
 	/*some parameters needed: */
-	model->FindParam(&verbose,VerboseEnum);
+	femmodel->parameters->FindParam(&verbose,VerboseEnum);
+	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
 		
-	/*First off, recover the response descriptors for the response functions: */
-	model->GetFormulation(DiagnosticAnalysisEnum,HorizAnalysisEnum)->parameters->FindParam(&responses_descriptors,&num_responses_descriptors,ResponseDescriptorsEnum);
-
 	/*Recover partitioning for dakota: */
-	model->FindParam(&qmu_npart,QmuNPartEnum);
-	model->FindParam(&qmu_part,&dummy,QmuPartEnum);
+	femmodel->FindParam(&qmu_npart,QmuNPartEnum);
+	femmodel->FindParam(&qmu_part,&dummy,QmuPartEnum);
 
 	/*broadcast variables: only cpu 0 has correct values*/
@@ -92,43 +87,40 @@
 	_printf_("qmu iteration: %i\n",counter);
 
-	/*Modify core inputs in objects contained in model, to reflect the dakota variables inputs: */
-	model->UpdateFromDakota(variables,variables_descriptors,numvariables,model->GetFormulation(DiagnosticAnalysisEnum,HorizAnalysisEnum)->parameters,qmu_part,qmu_npart); //diagnostic horiz model is the one holding the parameters for Dakota.
+	/*Modify core inputs in objects contained in femmodel, to reflect the dakota variables inputs: */
+	UpdateFromDakota(variables,variables_descriptors,numvariables,femmodel,qmu_part,qmu_npart);
 
 	/*Run the analysis core solution sequence: */
-	if(analysis_type==DiagnosticAnalysisEnum){
+	if(solution_type==DiagnosticAnalysisEnum){
 			
 		if(verbose)_printf_("Starting diagnostic core\n");
 
-		results=diagnostic_core(model);
+		diagnostic_core(femmodel);
 
 	}
-	else if(analysis_type==ThermalAnalysisEnum){
+	else if(solution_type==ThermalAnalysisEnum){
 		
 		if(verbose)_printf_("Starting thermal core\n");
-		results=thermal_core(model);
+		thermal_core(femmodel);
 
 	}
-	else if(analysis_type==PrognosticAnalysisEnum){
+	else if(solution_type==PrognosticAnalysisEnum){
 
 		if(verbose)_printf_("Starting prognostic core\n");
-		results=prognostic_core(model);
+		prognostic_core(femmodel);
 
 	}
-	else if(analysis_type==TransientAnalysisEnum){
+	else if(solution_type==TransientAnalysisEnum){
 
 		if(verbose)_printf_("Starting transient core\n");
-		results=transient_core(model);
+		transient_core(femmodel);
 
 	}
-	else ISSMERROR("%s%i%s%i%s"," analysis_type ",analysis_type," and sub_analysis_type ",sub_analysis_type," not supported yet!");
+	else ISSMERROR("%s%s%s"," solution_type: ",EnumAsString(solution_type),", not supported yet!");
 	
 	/*compute responses on cpu 0: dummy for now! */
 	if(verbose)_printf_("compute dakota responses:\n");
-	DakotaResponses(responses,responses_descriptors,numresponses,model,results,processed_results,analysis_type,sub_analysis_type);
+	DakotaResponses(responses,responses_descriptors,numresponses,femmodel,results,processed_results);
 
 	/*Free ressources:*/
-	delete results;
-	delete processed_results;
-
 	//variables only on cpu != 0
 	if(my_rank!=0){
@@ -148,4 +140,6 @@
 	xfree((void**)&responses_descriptors);
 	xfree((void**)&qmu_part);
+
+
 }
 
Index: /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp
===================================================================
--- /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp	(revision 4041)
+++ /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp	(revision 4042)
@@ -17,5 +17,5 @@
 
 	/*output: */
-	Vec* yg=NULL;
+	Vec yg=NULL;
 
 	/*First, recover number of dofs from nodes: */
@@ -31,5 +31,5 @@
 
 		/*Specify numentries: */
-		VecGetSize(yg->vector,&gsize);
+		VecGetSize(yg,&gsize);
 	}
 
Index: /issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp
===================================================================
--- /issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp	(revision 4041)
+++ /issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp	(revision 4042)
@@ -9,5 +9,5 @@
 #include "../../EnumDefinitions/EnumDefinitions.h"
 
-void UpdateInputsFromSolutionx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,Vec solution, int analysis_type, int sub_analysis_type,int step=0){
+void UpdateInputsFromSolutionx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,Vec solution, int analysis_type, int sub_analysis_type){
 
 	double* serial_solution=NULL;
@@ -17,5 +17,5 @@
 
 	/*Call overloaded form of UpdateInputsFromSolutionx: */
-	UpdateInputsFromSolutionx( elements, nodes,  vertices,  loads,  materials,  parameters,serial_solution, analysis_type, sub_analysis_type,step);
+	UpdateInputsFromSolutionx( elements, nodes,  vertices,  loads,  materials,  parameters,serial_solution, analysis_type, sub_analysis_type);
 
 	/*Free ressources:*/
@@ -44,41 +44,2 @@
 
 }
-
-/*Same routines, with additional timestep argument: */
-void UpdateInputsFromSolutionx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,Vec solution, int analysis_type, int sub_analysis_type,int timestep){
-	
-	
-	double* serial_solution=NULL;
-
-	/*Serialize solution, so that elements can index into it on every CPU: */
-	VecToMPISerial(&serial_solution,solution);
-
-	/*Call overloaded form of UpdateInputsFromSolutionx: */
-	UpdateInputsFromSolutionx( elements, nodes,  vertices,  loads,  materials,  parameters,serial_solution, analysis_type, sub_analysis_type,int timestep);
-
-	/*Free ressources:*/
-	xfree((void**)&serial_solution);
-
-}
-
-
-
-void UpdateInputsFromSolutionx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,double* solution, int analysis_type, int sub_analysis_type,int timestep){
-
-	/*Intermediary*/
-	int i;
-	Element* element=NULL;
-
-	/*First, get elements and loads configured: */
-	elements->  Configure(elements,loads, nodes,vertices, materials,parameters);
-	loads->     Configure(elements,loads, nodes,vertices, materials,parameters);
-	nodes->     Configure(elements,loads, nodes,vertices, materials,parameters);
-	parameters->Configure(elements,loads, nodes,vertices, materials,parameters);
-	
-	/*Elements drive the update: */
-	for (i=0;i<elements->Size();i++){
-		element=(Element*)elements->GetObjectByOffset(i);
-		element->UpdateInputsFromSolution(solution,analysis_type,sub_analysis_type,timestep);
-	}
-
-}
Index: /issm/trunk/src/c/modules/modules.h
===================================================================
--- /issm/trunk/src/c/modules/modules.h	(revision 4041)
+++ /issm/trunk/src/c/modules/modules.h	(revision 4042)
@@ -66,3 +66,5 @@
 #include "./GetSolutionFromInputsx/GetSolutionFromInputsx.h"
 #include "./OutputResultsx/OutputResultsx.h"
+#include "./MinVelx/MinVelx.h"
+#include "./MaxVelx/MaxVelx.h"
 #endif
Index: /issm/trunk/src/c/objects/DakotaPlugin.cpp
===================================================================
--- /issm/trunk/src/c/objects/DakotaPlugin.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/DakotaPlugin.cpp	(revision 4042)
@@ -44,10 +44,8 @@
 
 //constructor
-DakotaPlugin::DakotaPlugin(const Dakota::ProblemDescDB& problem_db,void* in_model, int in_analysis_type, int in_sub_analysis_type):Dakota::DirectApplicInterface(problem_db){
+DakotaPlugin::DakotaPlugin(const Dakota::ProblemDescDB& problem_db,void* in_femmodel):Dakota::DirectApplicInterface(problem_db){
 
 
-	model=in_model;
-	analysis_type=in_analysis_type;
-	sub_analysis_type=in_sub_analysis_type;
+	femmodel=in_femmodel;
 	counter=0;
 }
@@ -89,5 +87,5 @@
 
 	/*run core solution: */
-	SpawnCore(responses,numFns, variables,variable_descriptors,numACV,model,analysis_type,sub_analysis_type,counter);
+	SpawnCore(responses,numFns, variables,variable_descriptors,numACV,model,counter);
 
 	/*populate responses: */
Index: /issm/trunk/src/c/objects/DakotaPlugin.h
===================================================================
--- /issm/trunk/src/c/objects/DakotaPlugin.h	(revision 4041)
+++ /issm/trunk/src/c/objects/DakotaPlugin.h	(revision 4042)
@@ -24,12 +24,10 @@
 public:
 
-	DakotaPlugin(const Dakota::ProblemDescDB& problem_db,void* model, int analysis_type, int sub_analysis_type);
+	DakotaPlugin(const Dakota::ProblemDescDB& problem_db,void* model);
 	~DakotaPlugin();
 
 	/*these fields are used by core solutions: */
-	void* model;
+	void* femmodel;
 
-	int analysis_type;
-	int sub_analysis_type;
 	int counter;
 
Index: /issm/trunk/src/c/objects/Elements/Beam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Beam.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Beam.cpp	(revision 4042)
@@ -626,25 +626,5 @@
 void  Beam::PatchSize(int* pnumrows, int* pnumvertices,int* pnumnodes){
 
-	int     i;
-	
-	/*output: */
-	int     numrows     = 0;
-	int     numvertices = 0;
-	int     numnodes    = 0;
-
-	/*Go through all the results objects, and update the counters: */
-	for (i=0;i<this->results->Size();i++){
-		Result* result=(Result*)this->results->GetObjectByOffset(i);
-		/*first, we have one more result: */
-		numrows++;
-		/*now, how many vertices and how many nodal values for this result? :*/
-		numvertices=2; //this is a beam element, with 2 vertices
-		numnodes=result->NumberOfNodalValues(); //ask result object.
-	}
-
-	/*Assign output pointers:*/
-	*pnumrows=numrows;
-	*pnumvertices=numvertices;
-	*pnumnodes=numnodes;
+	ISSMERROR(" not supported yet!");
 	
 }
@@ -653,28 +633,81 @@
 void  Beam::PatchFill(int* pcount, Patch* patch){
 
-	int i;
-	int count;
-	int vertices_ids[2];
-
-
-	/*recover pointer: */
-	count=*pcount;
-		
-	/*will be needed later: */
-	for(i=0;i<2;i++) vertices_ids[i]=nodes[i]->GetVertexId(); //vertices id start at column 3 of the patch.
-
-	for(i=0;i<this->results->Size();i++){
-		Result* result=(Result*)this->results->GetObjectByOffset(i);
-
-		/*For this result,fill the information in the Patch object (element id + vertices ids), and then hand 
-		 *it to the result object, to fill the rest: */
-		patch->fillelementinfo(count,this->id,vertices_ids,2);
-		result->PatchFill(count,patch);
-
-		/*increment counter: */
-		count++;
+	ISSMERROR(" not supported yet!");
+}
+/*}}}*/
+/*FUNCTION Beam::MinVel(double* pminvel, bool process_units);{{{1*/
+void  Beam::MinVel(double* pminvel, bool process_units){
+
+	const int numgrids=2;
+	double  gaussgrids[numgrids][2]={{0,1},{1,0}};
+	double  vx_values[numgrids];
+	double  vy_values[numgrids];
+	double  vz_values[numgrids];
+	double  vel_values[numgrids];
+	double  minvel;
+
+	/*retrieve dim parameter: */
+	parameters->FindParam(&dim,DimEnum);
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValues(&vx_values[0],&gaussgrids[0][0],numgrids,VxEnum);
+	inputs->GetParameterValues(&vy_values[0],&gaussgrids[0][0],numgrids,VyEnum);
+	if(dim==3) inputs->GetParameterValues(&vz_values[0],&gaussgrids[0][0],numgrids,VzEnum);
+
+	/*now, compute minimum of velocity :*/
+	if(dim==2){
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2));
+	}
+	else{
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2)+pow(vz_values[i],2));
+	}
+
+	/*now, compute minimum:*/
+	minvel=vel_values[0];
+	for(i=1;i<numgrids;i++){
+		if (vel_values[i]<minvel)minvel=vel_values[i];
 	}
 
 	/*Assign output pointers:*/
-	*pcount=count;
-}
+	*pminvel=minvel;
+
+}
+/*}}}*/
+/*FUNCTION Beam::MaxVel(double* pmaxvel, bool process_units);{{{1*/
+void  Beam::MaxVel(double* pmaxvel, bool process_units){
+
+	const int numgrids=2;
+	double  gaussgrids[numgrids][2]={{0,1},{1,0}};
+	double  vx_values[numgrids];
+	double  vy_values[numgrids];
+	double  vz_values[numgrids];
+	double  vel_values[numgrids];
+	double  maxvel;
+
+	/*retrieve dim parameter: */
+	parameters->FindParam(&dim,DimEnum);
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValues(&vx_values[0],&gaussgrids[0][0],numgrids,VxEnum);
+	inputs->GetParameterValues(&vy_values[0],&gaussgrids[0][0],numgrids,VyEnum);
+	if(dim==3) inputs->GetParameterValues(&vz_values[0],&gaussgrids[0][0],numgrids,VzEnum);
+
+	/*now, compute maximum of velocity :*/
+	if(dim==2){
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2));
+	}
+	else{
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2)+pow(vz_values[i],2));
+	}
+
+	/*now, compute maximum:*/
+	maxvel=vel_values[0];
+	for(i=1;i<numgrids;i++){
+		if (vel_values[i]>maxvel)maxvel=vel_values[i];
+	}
+
+	/*Assign output pointers:*/
+	*pmaxvel=maxvel;
+
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Beam.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Beam.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Beam.h	(revision 4042)
@@ -83,5 +83,6 @@
 		void  PatchSize(int* pnumrows, int* pnumvertices,int* pnumnodes);
 		void  PatchFill(int* pcount, Patch* patch);
-
+		void  MinVel(double* pminvel, bool process_units);
+		void  MaxVel(double* pmaxvel, bool process_units);
 		/*}}}*/
 		/*not implemented: {{{1*/
Index: /issm/trunk/src/c/objects/Elements/Element.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Element.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Element.h	(revision 4042)
@@ -53,4 +53,6 @@
 		virtual void   InputToResult(int enum_type,int step,double time)=0;
 		virtual void   ProcessResultsUnits(void)=0;
+		virtual void   MinVel(double* pminvel, bool process_units)=0;
+		virtual void   MaxVel(double* pmaxvel, bool process_units)=0;
 
 		/*Implementation: */
Index: /issm/trunk/src/c/objects/Elements/Penta.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 4042)
@@ -504,5 +504,4 @@
 	Parameters *beam_parameters = NULL;
 	Inputs     *beam_inputs     = NULL;
-	Results     *beam_results     = NULL;
 
 	indices[0]=g0;
@@ -511,10 +510,8 @@
 	beam_parameters=this->parameters;
 	beam_inputs=(Inputs*)this->inputs->SpawnBeamInputs(indices);
-	beam_results=(Results*)this->results->SpawnBeamResults(indices);
 
 	beam=new Beam();
 	beam->id=this->id;
 	beam->inputs=beam_inputs;
-	beam->results=beam_results;
 	beam->parameters=beam_parameters;
 
@@ -535,14 +532,11 @@
 	Parameters *sing_parameters = NULL;
 	Inputs     *sing_inputs     = NULL;
-	Results     *sing_results     = NULL;
 
 	sing_parameters=this->parameters;
 	sing_inputs=(Inputs*)this->inputs->SpawnSingInputs(index);
-	sing_results=(Results*)this->results->SpawnSingResults(index);
 
 	sing=new Sing();
 	sing->id=this->id;
 	sing->inputs=sing_inputs;
-	sing->results=sing_results;
 	sing->parameters=sing_parameters;
 
@@ -612,5 +606,5 @@
 	/*If we don't find it, no big deal, just don't do the transfer. Otherwise, build a new Result 
 	 * object out of the input, with the additional step and time information: */
-	this->results->AddObject(input->SpawnResult(step,time));
+	this->results->AddObject((Object*)input->SpawnResult(step,time));
 
 }
@@ -622,5 +616,5 @@
 
 	for(i=0;i<this->results->Size();i++){
-		Result* result=this->results->GetObjectByOffset(i);
+		Result* result=(Result*)this->results->GetObjectByOffset(i);
 		result->ProcessUnits(this->parameters);
 	}
@@ -3387,4 +3381,5 @@
 
 	Penta* penta=NULL;
+	Input* this_input=NULL;
 
 	/*recover parameters: */
@@ -3399,4 +3394,6 @@
 
 		penta=this;
+		this_input=this->inputs->GetInput(enum_type);
+		if(!this_input)ISSMERROR("%s%s"," could not find input with enum:",EnumAsString(enum_type));
 
 		for(;;){
@@ -3406,5 +3403,5 @@
 
 			/*Add input of the basal element*/
-			penta->inputs->AddInput(this->inputs->GetInput(enum_type));
+			penta->inputs->AddInput(this_input);
 
 			/*Stop if we have reached the surface*/
@@ -4953,2 +4950,78 @@
 	*pcount=count;
 }
+/*FUNCTION Penta::MinVel(double* pminvel, bool process_units);{{{1*/
+void  Penta::MinVel(double* pminvel, bool process_units){
+
+	const int numgrids=6;
+	double  gaussgrids[numgrids][4]={{1,0,0,-1},{0,1,0,-1},{0,0,1,-1},{1,0,0,1},{0,1,0,1},{0,0,1,1}};
+	double  vx_values[numgrids];
+	double  vy_values[numgrids];
+	double  vz_values[numgrids];
+	double  vel_values[numgrids];
+	double  minvel;
+
+	/*retrieve dim parameter: */
+	parameters->FindParam(&dim,DimEnum);
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValues(&vx_values[0],&gaussgrids[0][0],numgrids,VxEnum);
+	inputs->GetParameterValues(&vy_values[0],&gaussgrids[0][0],numgrids,VyEnum);
+	if(dim==3) inputs->GetParameterValues(&vz_values[0],&gaussgrids[0][0],numgrids,VzEnum);
+
+	/*now, compute minimum of velocity :*/
+	if(dim==2){
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2));
+	}
+	else{
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2)+pow(vz_values[i],2));
+	}
+
+	/*now, compute minimum:*/
+	minvel=vel_values[0];
+	for(i=1;i<numgrids;i++){
+		if (vel_values[i]<minvel)minvel=vel_values[i];
+	}
+
+	/*Assign output pointers:*/
+	*pminvel=minvel;
+
+}
+/*}}}*/
+/*FUNCTION Penta::MaxVel(double* pmaxvel, bool process_units);{{{1*/
+void  Penta::MaxVel(double* pmaxvel, bool process_units){
+
+	const int numgrids=6;
+	double  gaussgrids[numgrids][4]={{1,0,0,-1},{0,1,0,-1},{0,0,1,-1},{1,0,0,1},{0,1,0,1},{0,0,1,1}};
+	double  vx_values[numgrids];
+	double  vy_values[numgrids];
+	double  vz_values[numgrids];
+	double  vel_values[numgrids];
+	double  maxvel;
+
+	/*retrieve dim parameter: */
+	parameters->FindParam(&dim,DimEnum);
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValues(&vx_values[0],&gaussgrids[0][0],numgrids,VxEnum);
+	inputs->GetParameterValues(&vy_values[0],&gaussgrids[0][0],numgrids,VyEnum);
+	if(dim==3) inputs->GetParameterValues(&vz_values[0],&gaussgrids[0][0],numgrids,VzEnum);
+
+	/*now, compute maximum of velocity :*/
+	if(dim==2){
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2));
+	}
+	else{
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2)+pow(vz_values[i],2));
+	}
+
+	/*now, compute maximum:*/
+	maxvel=vel_values[0];
+	for(i=1;i<numgrids;i++){
+		if (vel_values[i]>maxvel)maxvel=vel_values[i];
+	}
+
+	/*Assign output pointers:*/
+	*pmaxvel=maxvel;
+
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Penta.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Penta.h	(revision 4042)
@@ -152,4 +152,6 @@
 		void  PatchSize(int* pnumrows, int* pnumvertices,int* pnumnodes);
 		void  PatchFill(int* pcount, Patch* patch);
+		void  MinVel(double* pminvel, bool process_units);
+		void  MaxVel(double* pmaxvel, bool process_units);
 
 		/*updates: */
Index: /issm/trunk/src/c/objects/Elements/Sing.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Sing.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Sing.cpp	(revision 4042)
@@ -450,25 +450,5 @@
 void  Sing::PatchSize(int* pnumrows, int* pnumvertices,int* pnumnodes){
 
-	int     i;
-	
-	/*output: */
-	int     numrows     = 0;
-	int     numvertices = 0;
-	int     numnodes    = 0;
-
-	/*Go through all the results objects, and update the counters: */
-	for (i=0;i<this->results->Size();i++){
-		Result* result=(Result*)this->results->GetObjectByOffset(i);
-		/*first, we have one more result: */
-		numrows++;
-		/*now, how many vertices and how many nodal values for this result? :*/
-		numvertices=1; //this is a sing element, with 1 vertex
-		numnodes=result->NumberOfNodalValues(); //ask result object.
-	}
-
-	/*Assign output pointers:*/
-	*pnumrows=numrows;
-	*pnumvertices=numvertices;
-	*pnumnodes=numnodes;
+	ISSMERROR(" not supported yet!");
 	
 }
@@ -476,29 +456,58 @@
 /*FUNCTION Sing::PatchFill(int* pcount, Patch* patch){{{1*/
 void  Sing::PatchFill(int* pcount, Patch* patch){
-
-	int i;
-	int count;
-	int vertices_ids[1];
-
-
-	/*recover pointer: */
-	count=*pcount;
-		
-	/*will be needed later: */
-	for(i=0;i<1;i++) vertices_ids[i]=nodes[i]->GetVertexId(); //vertices id start at column 3 of the patch.
-
-	for(i=0;i<this->results->Size();i++){
-		Result* result=(Result*)this->results->GetObjectByOffset(i);
-
-		/*For this result,fill the information in the Patch object (element id + vertices ids), and then hand 
-		 *it to the result object, to fill the rest: */
-		patch->fillelementinfo(count,this->id,vertices_ids,1);
-		result->PatchFill(count,patch);
-
-		/*increment counter: */
-		count++;
+	
+	ISSMERROR(" not supported yet!");
+}
+/*}}}*/
+/*FUNCTION Sing::MinVel(double* pminvel, bool process_units);{{{1*/
+void  Sing::MinVel(double* pminvel, bool process_units){
+
+	double  vx;
+	double  vy;
+	double  vz;
+	double  minvel;
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValue(&vx,VxEnum);
+	inputs->GetParameterValue(&vy,VyEnum);
+	if(dim==3)inputs->GetParameterValue(&vz,VzEnum);
+
+	/*now, compute minimum of velocity :*/
+	if(dim==2){
+		minvel=sqrt(pow(vx,2)+pow(vy,2));
+	}
+	else{
+		minvel=sqrt(pow(vx,2)+pow(vy,2)+pow(vz,2));
 	}
 
 	/*Assign output pointers:*/
-	*pcount=count;
-}
+	*pminvel=minvel;
+
+}
+/*}}}*/
+/*FUNCTION Sing::MaxVel(double* pmaxvel, bool process_units);{{{1*/
+void  Sing::MaxVel(double* pmaxvel, bool process_units){
+
+	double  vx;
+	double  vy;
+	double  vz;
+	double  maxvel;
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValue(&vx,VxEnum);
+	inputs->GetParameterValue(&vy,VyEnum);
+	if(dim==3)inputs->GetParameterValue(&vz,VzEnum);
+
+	/*now, compute maximum of velocity :*/
+	if(dim==2){
+		maxvel=sqrt(pow(vx,2)+pow(vy,2));
+	}
+	else{
+		maxvel=sqrt(pow(vx,2)+pow(vy,2)+pow(vz,2));
+	}
+
+	/*Assign output pointers:*/
+	*pmaxvel=maxvel;
+
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Sing.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Sing.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Sing.h	(revision 4042)
@@ -82,4 +82,6 @@
 		void  PatchSize(int* pnumrows, int* pnumvertices,int* pnumnodes);
 		void  PatchFill(int* pcount, Patch* patch);
+		void  MinVel(double* pminvel, bool process_units);
+		void  MaxVel(double* pmaxvel, bool process_units);
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Tria.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 4042)
@@ -438,5 +438,4 @@
 	Parameters *beam_parameters = NULL;
 	Inputs     *beam_inputs     = NULL;
-	Results     *beam_results     = NULL;
 
 	indices[0]=g0;
@@ -445,10 +444,8 @@
 	beam_parameters=this->parameters;
 	beam_inputs=(Inputs*)this->inputs->SpawnBeamInputs(indices);
-	beam_results=(Results*)this->results->SpawnBeamResults(indices);
 
 	beam=new Beam();
 	beam->id=this->id;
 	beam->inputs=beam_inputs;
-	beam->results=beam_results;
 	beam->parameters=beam_parameters;
 
@@ -470,14 +467,11 @@
 	Parameters *sing_parameters = NULL;
 	Inputs     *sing_inputs     = NULL;
-	Results     *sing_results     = NULL;
 
 	sing_parameters=this->parameters;
 	sing_inputs=(Inputs*)this->inputs->SpawnSingInputs(index);
-	sing_results=(Results*)this->results->SpawnSingResults(index);
 
 	sing=new Sing();
 	sing->id=this->id;
 	sing->inputs=sing_inputs;
-	sing->results=sing_results;
 	sing->parameters=sing_parameters;
 
@@ -508,5 +502,5 @@
 	/*If we don't find it, no big deal, just don't do the transfer. Otherwise, build a new Result 
 	 * object out of the input, with the additional step and time information: */
-	this->results->AddObject(input->SpawnResult(step,time));
+	this->results->AddObject((Object*)input->SpawnResult(step,time));
 
 }
@@ -518,5 +512,5 @@
 
 	for(i=0;i<this->results->Size();i++){
-		Result* result=this->results->GetObjectByOffset(i);
+		Result* result=(Result*)this->results->GetObjectByOffset(i);
 		result->ProcessUnits(this->parameters);
 	}
@@ -4987,4 +4981,5 @@
 	/*copy input of enum_type*/
 	oldinput=this->inputs->GetInput(enum_type);
+	if(!oldinput)ISSMERROR("%s%s"," could not find old input with enum: ",EnumAsString(enum_type));
 	newinput=(Input*)oldinput->copy();
 
@@ -5065,2 +5060,78 @@
 	*prow=row;
 }
+/*FUNCTION Tria::MinVel(double* pminvel, bool process_units);{{{1*/
+void  Tria::MinVel(double* pminvel, bool process_units){
+
+	const int numgrids=3;
+	double  gaussgrids[numgrids][3]={{1,0,0},{0,1,0},{0,0,1}};
+	double  vx_values[numgrids];
+	double  vy_values[numgrids];
+	double  vz_values[numgrids];
+	double  vel_values[numgrids];
+	double  minvel;
+
+	/*retrieve dim parameter: */
+	parameters->FindParam(&dim,DimEnum);
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValues(&vx_values[0],&gaussgrids[0][0],numgrids,VxEnum);
+	inputs->GetParameterValues(&vy_values[0],&gaussgrids[0][0],numgrids,VyEnum);
+	if(dim==3) inputs->GetParameterValues(&vz_values[0],&gaussgrids[0][0],numgrids,VzEnum);
+
+	/*now, compute minimum of velocity :*/
+	if(dim==2){
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2));
+	}
+	else{
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2)+pow(vz_values[i],2));
+	}
+
+	/*now, compute minimum:*/
+	minvel=vel_values[0];
+	for(i=1;i<numgrids;i++){
+		if (vel_values[i]<minvel)minvel=vel_values[i];
+	}
+
+	/*Assign output pointers:*/
+	*pminvel=minvel;
+
+}
+/*}}}*/
+/*FUNCTION Tria::MaxVel(double* pmaxvel, bool process_units);{{{1*/
+void  Tria::MaxVel(double* pmaxvel, bool process_units){
+
+	const int numgrids=3;
+	double  gaussgrids[numgrids][3]={{1,0,0},{0,1,0},{0,0,1}};
+	double  vx_values[numgrids];
+	double  vy_values[numgrids];
+	double  vz_values[numgrids];
+	double  vel_values[numgrids];
+	double  maxvel;
+
+	/*retrieve dim parameter: */
+	parameters->FindParam(&dim,DimEnum);
+
+	/*retrive velocity values at nodes */
+	inputs->GetParameterValues(&vx_values[0],&gaussgrids[0][0],numgrids,VxEnum);
+	inputs->GetParameterValues(&vy_values[0],&gaussgrids[0][0],numgrids,VyEnum);
+	if(dim==3) inputs->GetParameterValues(&vz_values[0],&gaussgrids[0][0],numgrids,VzEnum);
+
+	/*now, compute maximum of velocity :*/
+	if(dim==2){
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2));
+	}
+	else{
+		for(i=0;i<numgrids;i++)vel_values=sqrt(pow(vx_values[i],2)+pow(vy_values[i],2)+pow(vz_values[i],2));
+	}
+
+	/*now, compute maximum:*/
+	maxvel=vel_values[0];
+	for(i=1;i<numgrids;i++){
+		if (vel_values[i]>maxvel)maxvel=vel_values[i];
+	}
+
+	/*Assign output pointers:*/
+	*pmaxvel=maxvel;
+
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Tria.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Elements/Tria.h	(revision 4042)
@@ -128,4 +128,6 @@
 		void  PatchSize(int* pnumrows, int* pnumvertices,int* pnumnodes);
 		void  PatchFill(int* pcount, Patch* patch);
+		void  MinVel(double* pminvel, bool process_units);
+		void  MaxVel(double* pmaxvel, bool process_units);
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/BeamVertexInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/BeamVertexInput.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/BeamVertexInput.cpp	(revision 4042)
@@ -227,2 +227,25 @@
 }
 /*}}}*/
+/*FUNCTION BeamVertexInput::SquareMin(double* psquaremin, bool process_units){{{1*/
+void BeamVertexInput::SquareMin(double* psquaremin, bool process_units,Parameters* parameters){
+
+	int i;
+	const int numnodes=2;
+	double valuescopy[numnodes];
+	double squaremin;
+
+	/*First,  copy values, to process units if requested: */
+	for(i=0;i<numnodes;i++)valuescopy[i]=this->values[i];
+
+	/*Process units if requested: */
+	if(process)NodalValuesUnitConversion(&valuescopy[0],numnodes,enum_type,parameters);
+
+	/*Now, figure out minimum of valuescopy: */
+	squaremin=pow(valuescopy[0],2);
+	for(i=1;i<numnodes;i++){
+		if(pow(valuescopy[i],2)<squaremin)squaremin=pow(valuescopy[i],2);
+	}
+	/*Assign output pointers:*/
+	*psquaremin=squaremin;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/BeamVertexInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/BeamVertexInput.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/BeamVertexInput.h	(revision 4042)
@@ -73,4 +73,5 @@
 		void GetVyStrainRate3dPattyn(double* epsilonvy,double* xyz_list, double* gauss){ISSMERROR("not implemented yet");};
 		void ChangeEnum(int newenumtype);
+		void SquareMin(double* psquaremin, bool process_units,Parameters* parameters);
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Inputs/BoolInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/BoolInput.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/BoolInput.cpp	(revision 4042)
@@ -177,5 +177,5 @@
 Result* BoolInput::SpawnResult(int step, double time){
 
-	return new BoolResult(this->enum_type,this->value,step,time);
+	ISSMERROR(" not supported yet!");
 
 }
@@ -217,2 +217,8 @@
 }
 /*}}}*/
+/*FUNCTION BoolInput::SquareMin(double* psquaremin, bool process_units){{{1*/
+void BoolInput::SquareMin(double* psquaremin, bool process_units,Parameters* parameters){
+	/*square of a bool is the bool itself: */
+	*psquaremin=value;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/BoolInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/BoolInput.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/BoolInput.h	(revision 4042)
@@ -73,4 +73,5 @@
 		void GetVyStrainRate3dPattyn(double* epsilonvy,double* xyz_list, double* gauss){ISSMERROR("not implemented yet");};
 		void ChangeEnum(int newenumtype);
+		void SquareMin(double* psquaremin, bool process_units,Parameters* parameters);
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Inputs/DoubleInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/DoubleInput.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/DoubleInput.cpp	(revision 4042)
@@ -227,2 +227,9 @@
 }
 /*}}}*/
+/*FUNCTION DoubleInput::SquareMin(double* psquaremin, bool process_units){{{1*/
+void DoubleInput::SquareMin(double* psquaremin, bool process_units,Parameters* parameters){
+
+	/*square min of a double is the square of the double itself: */
+	*psquaremin=pow(value,2);
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/DoubleInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/DoubleInput.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/DoubleInput.h	(revision 4042)
@@ -74,4 +74,5 @@
 		void GetVyStrainRate3dPattyn(double* epsilonvy,double* xyz_list, double* gauss){ISSMERROR("not implemented yet");};
 		void ChangeEnum(int newenumtype);
+		void SquareMin(double* psquaremin, bool process_units,Parameters* parameters);
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Inputs/Input.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/Input.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/Input.h	(revision 4042)
@@ -50,6 +50,5 @@
 		virtual Input* SpawnTriaInput(int* indices)=0;
 		virtual Result* SpawnResult(int step, double time)=0;
-
-
+		virtual void   SquareMin(double* psquaremin, bool process_units,Parameters* parameters)=0;
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Inputs/IntInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/IntInput.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/IntInput.cpp	(revision 4042)
@@ -173,6 +173,6 @@
 /*FUNCTION IntInput::SpawnResult{{{1*/
 Result* IntInput::SpawnResult(int step, double time){
-
-	return new IntResult(this->enum_type,this->value,step,time);
+	
+	ISSMERROR(" not supported yet!");
 
 }
@@ -214,2 +214,9 @@
 }
 /*}}}*/
+/*FUNCTION IntInput::SquareMin(double* psquaremin, bool process_units){{{1*/
+void IntInput::SquareMin(double* psquaremin, bool process_units,Parameters* parameters){
+
+	/*square min of an integer is the square of the integer itself: */
+	*psquaremin=pow(value,2);
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/IntInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/IntInput.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/IntInput.h	(revision 4042)
@@ -73,4 +73,5 @@
 		void GetVyStrainRate3dPattyn(double* epsilonvy,double* xyz_list, double* gauss){ISSMERROR("not implemented yet");};
 		void ChangeEnum(int newenumtype);
+		void SquareMin(double* psquaremin, bool process_units,Parameters* parameters);
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Inputs/PentaVertexInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/PentaVertexInput.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/PentaVertexInput.cpp	(revision 4042)
@@ -876,2 +876,25 @@
 }
 /*}}}*/
+/*FUNCTION PentaVertexInput::SquareMin(double* psquaremin, bool process_units){{{1*/
+void PentaVertexInput::SquareMin(double* psquaremin, bool process_units,Parameters* parameters){
+
+	int i;
+	const int numnodes=6;
+	double valuescopy[numnodes];
+	double squaremin;
+
+	/*First,  copy values, to process units if requested: */
+	for(i=0;i<numnodes;i++)valuescopy[i]=this->values[i];
+
+	/*Process units if requested: */
+	if(process)NodalValuesUnitConversion(&valuescopy[0],numnodes,enum_type,parameters);
+
+	/*Now, figure out minimum of valuescopy: */
+	squaremin=pow(valuescopy[0],2);
+	for(i=1;i<numnodes;i++){
+		if(pow(valuescopy[i],2)<squaremin)squaremin=pow(valuescopy[i],2);
+	}
+	/*Assign output pointers:*/
+	*psquaremin=squaremin;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/PentaVertexInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/PentaVertexInput.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/PentaVertexInput.h	(revision 4042)
@@ -82,4 +82,5 @@
 		void GetBPattyn(double* B, double* xyz_list, double* gauss_coord);
 		void GetBStokes(double* B, double* xyz_list, double* gauss_coord);
+		void SquareMin(double* psquaremin, bool process_units,Parameters* parameters);
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Inputs/SingVertexInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/SingVertexInput.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/SingVertexInput.cpp	(revision 4042)
@@ -205,2 +205,21 @@
 }
 /*}}}*/
+/*FUNCTION SingVertexInput::SquareMin(double* psquaremin, bool process_units){{{1*/
+void SingVertexInput::SquareMin(double* psquaremin, bool process_units,Parameters* parameters){
+
+	double valuecopy;
+	double squaremin;
+
+	/*First,  copy value, to process units if requested: */
+	valuecopy=value;
+
+	/*Process units if requested: */
+	if(process)NodalValuesUnitConversion(&valuecopy,1,enum_type,parameters);
+
+	/*Now, return square of value, because it is the minimum: */
+	squaremin=pow(valuecopy,2);
+	
+	/*Assign output pointers:*/
+	*psquaremin=squaremin;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/SingVertexInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/SingVertexInput.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/SingVertexInput.h	(revision 4042)
@@ -72,4 +72,5 @@
 		void GetVyStrainRate3dPattyn(double* epsilonvy,double* xyz_list, double* gauss){ISSMERROR("not implemented yet");};
 		void ChangeEnum(int newenumtype);
+		void SquareMin(double* psquaremin, bool process_units,Parameters* parameters);
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Inputs/TriaVertexInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/TriaVertexInput.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/TriaVertexInput.cpp	(revision 4042)
@@ -450,2 +450,25 @@
 }
 /*}}}*/
+/*FUNCTION TriaVertexInput::SquareMin(double* psquaremin, bool process_units){{{1*/
+void TriaVertexInput::SquareMin(double* psquaremin, bool process_units,Parameters* parameters){
+
+	int i;
+	const int numnodes=3;
+	double valuescopy[numnodes];
+	double squaremin;
+
+	/*First,  copy values, to process units if requested: */
+	for(i=0;i<numnodes;i++)valuescopy[i]=this->values[i];
+
+	/*Process units if requested: */
+	if(process)NodalValuesUnitConversion(&valuescopy[0],numnodes,enum_type,parameters);
+
+	/*Now, figure out minimum of valuescopy: */
+	squaremin=pow(valuescopy[0],2);
+	for(i=1;i<numnodes;i++){
+		if(pow(valuescopy[i],2)<squaremin)squaremin=pow(valuescopy[i],2);
+	}
+	/*Assign output pointers:*/
+	*psquaremin=squaremin;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/TriaVertexInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/TriaVertexInput.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Inputs/TriaVertexInput.h	(revision 4042)
@@ -79,4 +79,5 @@
 		void GetJacobian(double* J, double* xyz_list,double* gauss);
 		void GetJacobianInvert(double*  Jinv, double* xyz_list,double* gauss);
+		void SquareMin(double* psquaremin, bool process_units,Parameters* parameters);
 		/*}}}*/
 
Index: /issm/trunk/src/c/objects/Patch.cpp
===================================================================
--- /issm/trunk/src/c/objects/Patch.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Patch.cpp	(revision 4042)
@@ -59,6 +59,6 @@
 }
 /*}}}*/
-/*FUNCTION Patch::fillelementinfo(int row, int element_id, int vertices_ids, int num_vertices);{{{1*/
-void Patch::fillelementinfo(int count, int element_id, int vertices_ids, int num_vertices){
+/*FUNCTION Patch::fillelementinfo(int row, int element_id, int* vertices_ids, int num_vertices);{{{1*/
+void Patch::fillelementinfo(int count, int element_id, int* vertices_ids, int num_vertices){
 
 	int i;
Index: /issm/trunk/src/c/objects/Patch.h
===================================================================
--- /issm/trunk/src/c/objects/Patch.h	(revision 4041)
+++ /issm/trunk/src/c/objects/Patch.h	(revision 4042)
@@ -40,5 +40,5 @@
 		Patch(int numrows, int maxvertices, int maxnodes);
 		~Patch();
-		void fillelementinfo(int row, int element_id, int vertices_ids, int num_vertices);
+		void fillelementinfo(int row, int element_id, int* vertices_ids, int num_vertices);
 		void fillresultinfo(int row,int enum_type,int step, double time, int interpolation, double* nodal_values, int num_nodes);
 		void MPI_Gather(void);
Index: /issm/trunk/src/c/objects/Results/BeamVertexResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/Results/BeamVertexResult.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Results/BeamVertexResult.cpp	(revision 4042)
@@ -141,5 +141,5 @@
 /*Result functions*/
 /*FUNCTION BeamVertexResult::ProcessUnits(Parameters* parameters){{{1*/
-Result* BeamVertexResult::ProcessUnits(Parameters* parameters){
+void BeamVertexResult::ProcessUnits(Parameters* parameters){
 	
 	NodalValuesUnitConversion(this->values,2,this->enum_type,parameters);
Index: /issm/trunk/src/c/objects/Results/PentaVertexResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/Results/PentaVertexResult.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Results/PentaVertexResult.cpp	(revision 4042)
@@ -206,5 +206,5 @@
 /*}}}*/
 /*FUNCTION PentaVertexResult::ProcessUnits(Parameters* parameters){{{1*/
-Result* PentaVertexResult::ProcessUnits(Parameters* parameters){
+void PentaVertexResult::ProcessUnits(Parameters* parameters){
 	
 	NodalValuesUnitConversion(this->values,6,this->enum_type,parameters);
Index: /issm/trunk/src/c/objects/Results/SingVertexResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/Results/SingVertexResult.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Results/SingVertexResult.cpp	(revision 4042)
@@ -141,7 +141,7 @@
 /*Result functions*/
 /*FUNCTION SingVertexResult::ProcessUnits(Parameters* parameters){{{1*/
-Result* SingVertexResult::ProcessUnits(Parameters* parameters){
+void SingVertexResult::ProcessUnits(Parameters* parameters){
 	
-	NodalValuesUnitConversion(this->value,1,this->enum_type,parameters);
+	NodalValuesUnitConversion(&this->value,1,this->enum_type,parameters);
 
 }
@@ -158,5 +158,5 @@
 	  * of the patch object: enum_type step time element_id interpolation vertices_ids nodal_values
 	  * Here, we will supply the enum_type, step, time, interpolation and nodal_values: */
-	patch->fillresultinfo(row,this->enum_type,this->step,this->time,P0Enum,this->value,1);
+	patch->fillresultinfo(row,this->enum_type,this->step,this->time,P0Enum,&this->value,1);
 
 }
Index: /issm/trunk/src/c/objects/Results/TriaVertexResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/Results/TriaVertexResult.cpp	(revision 4041)
+++ /issm/trunk/src/c/objects/Results/TriaVertexResult.cpp	(revision 4042)
@@ -195,5 +195,5 @@
 /*}}}*/
 /*FUNCTION TriaVertexResult::ProcessUnits(Parameters* parameters){{{1*/
-Result* TriaVertexResult::ProcessUnits(Parameters* parameters){
+void TriaVertexResult::ProcessUnits(Parameters* parameters){
 	
 	NodalValuesUnitConversion(this->values,3,this->enum_type,parameters);
Index: /issm/trunk/src/c/objects/objects.h
===================================================================
--- /issm/trunk/src/c/objects/objects.h	(revision 4041)
+++ /issm/trunk/src/c/objects/objects.h	(revision 4042)
@@ -57,4 +57,5 @@
 #include "./Results/SingVertexResult.h"
 #include "./Results/BeamVertexResult.h"
+#include "./Results/NodalValuesUnitConversion.h"
 
 /*Materials: */
Index: /issm/trunk/src/c/solutions/diagnostic.cpp
===================================================================
--- /issm/trunk/src/c/solutions/diagnostic.cpp	(revision 4041)
+++ /issm/trunk/src/c/solutions/diagnostic.cpp	(revision 4042)
@@ -94,5 +94,5 @@
 
 		_printf_("write results to disk:\n");
-		OutputResults(femmodel,outputfilename);
+		OutputResults(femmodel->elements, femmodel->loads, femmodel->nodes, femmodel->vertices, femmodel->materials, femmodel->parameters, outputfilename);
 	}
 	else{
Index: /issm/trunk/src/c/solutions/thermal.cpp
===================================================================
--- /issm/trunk/src/c/solutions/thermal.cpp	(revision 4041)
+++ /issm/trunk/src/c/solutions/thermal.cpp	(revision 4042)
@@ -85,5 +85,5 @@
 		
 		_printf_("write results to disk:\n");
-		OutputResults(femmodel,outputfilename);
+		OutputResults(femmodel->elements, femmodel->loads, femmodel->nodes, femmodel->vertices, femmodel->materials, femmodel->parameters, outputfilename);
 
 	}
