Index: /issm/trunk/src/c/DataSet/DataSet.cpp
===================================================================
--- /issm/trunk/src/c/DataSet/DataSet.cpp	(revision 4001)
+++ /issm/trunk/src/c/DataSet/DataSet.cpp	(revision 4002)
@@ -872,6 +872,6 @@
 }
 /*}}}*/
-/*FUNCTION DataSet::NumberOfDofs{{{1*/
-int   DataSet::NumberOfDofs(){
+/*FUNCTION DataSet::NumberOfDofs(int analysis_type){{{1*/
+int   DataSet::NumberOfDofs(int analysis_type){
 
 
@@ -889,9 +889,12 @@
 			node=(Node*)(*object);
 
-			/*Ok, this object is a node, ask it to plug values into partition: */
-			if (!node->IsClone()){
-
-				numdofs+=node->GetNumberOfDofs();
-
+			if (node->InAnalysis(analysis_type)){
+
+				/*Ok, this object is a node, ask it to plug values into partition: */
+				if (!node->IsClone()){
+
+					numdofs+=node->GetNumberOfDofs();
+
+				}
 			}
 		}
@@ -1040,5 +1043,5 @@
 /*}}}*/
 /*FUNCTION DataSet::SetupSpcs{{{1*/
-void   DataSet::SetupSpcs(DataSet* nodes,Vec yg){
+void   DataSet::SetupSpcs(DataSet* nodes,Vec yg,int analysis_type){
 
 	vector<Object*>::iterator object;
Index: /issm/trunk/src/c/DataSet/DataSet.h
===================================================================
--- /issm/trunk/src/c/DataSet/DataSet.h	(revision 4001)
+++ /issm/trunk/src/c/DataSet/DataSet.h	(revision 4002)
@@ -57,7 +57,7 @@
 		void  DistributeNumDofs(int** pnumdofspernode,int numberofnodes,int analysis_type,int sub_analysis_type);
 		void  FlagClones(int numberofnodes);
-		int   NumberOfDofs();
+		int   NumberOfDofs(int analysis_type);
 		int   NumberOfRgbs();
-		void  SetupSpcs(DataSet* nodes,Vec yg);
+		void  SetupSpcs(DataSet* nodes,Vec yg,int analysis_type);
 		void  SetupMpcs(Mat Rmg,DataSet* nodes);
 		void  FlagNodeSets(Vec pv_g, Vec pv_m, Vec pv_n, Vec pv_f, Vec pv_s);
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 4001)
+++ /issm/trunk/src/c/Makefile.am	(revision 4002)
@@ -300,4 +300,6 @@
 					./modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp
 					./modules/ModelProcessorx/NodesPartitioning.cpp
+					./modules/ModelProcessorx/SortDataSets.cpp\
+					./modules/ModelProcessorx/UpdateCounter.cpp\
 					./modules/ModelProcessorx/CreateDataSets.cpp\
 					./modules/ModelProcessorx/CreateParameters.cpp\
@@ -355,6 +357,8 @@
 					./modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp\
 					./modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp\
-					./modules/Dofx/Dofx.h\
-					./modules/Dofx/Dofx.cpp\
+					./modules/VerticesDofx/VerticesDofx.h\
+					./modules/VerticesDofx/VerticesDofx.cpp\
+					./modules/NodesDofx/NodesDofx.h\
+					./modules/NodesDofx/NodesDofx.cpp\
 					./modules/Dux/Dux.h\
 					./modules/Dux/Dux.cpp\
@@ -765,4 +769,6 @@
 					./modules/ModelProcessorx/NodesPartitioning.cpp
 					./modules/ModelProcessorx/Partitioning.cpp\
+					./modules/ModelProcessorx/SortDataSets.cpp\
+					./modules/ModelProcessorx/UpdateCounter.cpp\
 					./modules/ModelProcessorx/CreateDataSets.cpp\
 					./modules/ModelProcessorx/CreateParameters.cpp\
@@ -807,6 +813,8 @@
 					./modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp\
 					./modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp\
-					./modules/Dofx/Dofx.h\
-					./modules/Dofx/Dofx.cpp\
+					./modules/VerticesDofx/VerticesDofx.h\
+					./modules/VerticesDofx/VerticesDofx.cpp\
+					./modules/NodesDofx/NodesDofx.h\
+					./modules/NodesDofx/NodesDofx.cpp\
 					./modules/OutputResultsx/OutputResultsx.h\
 					./modules/OutputResultsx/OutputResultsx.cpp\
Index: /issm/trunk/src/c/modules/ModelProcessorx/CreateDataSets.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/CreateDataSets.cpp	(revision 4001)
+++ /issm/trunk/src/c/modules/ModelProcessorx/CreateDataSets.cpp	(revision 4002)
@@ -117,5 +117,11 @@
 	/*Generate objects that are not dependent on any analysis_type: */
 	CreateParameters(pparameters,iomodel,iomodel_handle);
-	CreateParametersControl(pparameters,iomodel,iomodel_handle);
-	CreateParametersQmu(pparameters,iomodel,iomodel_handle);
+
+	/*Sort datasets: */
+	SortDataSets(elements,nodes,vertices, loads, materials, constraints, parameters);
+
+	/*Update counters, because we have created more nodes, loads and constraints, and ids for objects created in next call to CreateDataSets
+	 * will need to start at the end of the updated counters: */
+	UpdateCounters(iomodel,pnodes,ploads,pconstraints);
+
 }
Index: /issm/trunk/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp	(revision 4001)
+++ /issm/trunk/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp	(revision 4002)
@@ -88,10 +88,4 @@
 	xfree((void**)&iomodel->thickness);
 
-	/*All our datasets are already order by ids. Set presort flag so that later on, when sorting is requested on these 
-	 * datasets, it will not be redone: */
-	elements->Presort();
-	vertices->Presort();
-	materials->Presort();
-
 	cleanup_and_return:
 	
Index: /issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 4001)
+++ /issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 4002)
@@ -21,8 +21,10 @@
 	char*    tag=NULL;
 	#ifdef _SERIAL_
-		mxArray* pfield=NULL;
-		mxArray* pfield2=NULL;
+	mxArray* pfield=NULL;
+	mxArray* pfield2=NULL;
 	#endif
 
+	if(*pparameters)return; //do not create parameters twice!
+		
 	/*Initialize dataset: */
 	parameters = new Parameters(ParametersEnum);
@@ -103,8 +105,5 @@
 	}
 
-	/*All our datasets are already ordered by ids. Set presort flag so that later on, when sorting is requested on these 
-	 * datasets, it will not be redone: */
-	parameters->Presort();
-
+	
 	/*Free data: */
 	xfree((void**)&tag);
@@ -115,4 +114,9 @@
 	xfree((void**)&parameteroutput);
 
+
+	/*Before returning, create parameters in case we are running Qmu or control types runs: */
+	CreateParametersControl(&parameters,iomodel,iomodel_handle);
+	CreateParametersQmu(&parameters,iomodel,iomodel_handle);
+
 	/*Assign output pointer: */
 	*pparameters=parameters;
Index: /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp	(revision 4001)
+++ /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp	(revision 4002)
@@ -23,7 +23,10 @@
 	int     node1,node2;
 
-	/*Create constraints: */
-	constraints = new DataSet(ConstraintsEnum);
+	/*Recover pointer: */
+	constraints=*pconstraints;
 
+	/*Create constraints if they do not exist yet*/
+	if(!constraints) constraints = new DataSet(ConstraintsEnum);
+	
 	/*Now, is the flag macayaealpattyn on? otherwise, do nothing: */
 	if (!iomodel->ismacayealpattyn)goto cleanup_and_return;
@@ -33,5 +36,7 @@
 	IoModelFetchData(&iomodel->gridonhutter,NULL,NULL,iomodel_handle,"gridonhutter");
 
-	count=1; //matlab indexing
+	/*Initialize counter: */
+	count=0;
+	
 	/*Create spcs from x,y,z, as well as the spc values on those spcs: */
 	for (i=0;i<iomodel->numberofvertices;i++){
@@ -39,10 +44,10 @@
 
 			if ((int)iomodel->spcvelocity[6*i+0] | (int)iomodel->gridonhutter[i]) 
-				constraints->AddObject(new Spc(count,i+1,1,*(iomodel->spcvelocity+6*i+3)/iomodel->yts)); //add count'th spc, on node i+1, setting dof 1 to vx.
+				constraints->AddObject(new Spc(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,1,*(iomodel->spcvelocity+6*i+3)/iomodel->yts)); //add count'th spc, on node i+1, setting dof 1 to vx.
 
 			count++;
 			
 			if ((int)iomodel->spcvelocity[6*i+1] | (int)iomodel->gridonhutter[i]) 
-				constraints->AddObject(new Spc(count,i+1,2,*(iomodel->spcvelocity+6*i+4)/iomodel->yts)); //add count'th spc, on node i+1, setting dof 2 to vy
+				constraints->AddObject(new Spc(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,2,*(iomodel->spcvelocity+6*i+4)/iomodel->yts)); //add count'th spc, on node i+1, setting dof 2 to vy
 
 			count++;
@@ -54,5 +59,4 @@
 	xfree((void**)&iomodel->gridonhutter);
 
-	
 	/*penalty loads: */
 	IoModelFetchData(&iomodel->penalties,&iomodel->numpenalties,NULL,iomodel_handle,"penalties");
@@ -66,12 +70,12 @@
 	
 				/*We are pairing nodes along a vertical profile.*/
-				node1=(int)*(iomodel->penalties+iomodel->numlayers*i);
-				node2=(int)*(iomodel->penalties+iomodel->numlayers*i+j);
+				node1=(int)*(iomodel->penalties+iomodel->numlayers*i)+iomodel->nodecounter;
+				node2=(int)*(iomodel->penalties+iomodel->numlayers*i+j)+iomodel->nodecounter;
 
-				constraints->AddObject(new Rgb(count,node1,node2,1));  //add count'th Rgb on dof 1 between node1 and node2
+				constraints->AddObject(new Rgb(iomodel->constraintcounter+count+1,node1,node2,1));  //add count'th Rgb on dof 1 between node1 and node2
 				
 				count++;
 				
-				constraints->AddObject(new Rgb(count,node1,node2,2));  //add count'th Rgb on dof 1 between node1 and node2
+				constraints->AddObject(new Rgb(iomodel->constraintcounter+count+1,node1,node2,2));  //add count'th Rgb on dof 1 between node1 and node2
 
 			}
@@ -82,9 +86,6 @@
 	xfree((void**)&iomodel->penalties);
 
-	/*All our datasets are already order by ids. Set presort flag so that later on, when sorting is requested on these 
-	 * datasets, it will not be redone: */
-	constraints->Presort();
-	
 	cleanup_and_return:
+
 	/*Assign output pointer: */
 	*pconstraints=constraints;
Index: /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp	(revision 4001)
+++ /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp	(revision 4002)
@@ -20,8 +20,11 @@
 	int element;
 	int i;
-	int counter=1;
+	int count=0;
 
-	/*Create loads: */
-	loads   = new DataSet(LoadsEnum);
+	/*Recover pointer: */
+	loads=*ploads;
+
+	/*Create loads if they do not exist yet*/
+	if(!loads) loads = new DataSet(LoadsEnum);
 
 	/*Now, is the flag macayaealpattyn on? otherwise, do nothing: */
@@ -34,4 +37,7 @@
 	IoModelFetchData(&iomodel->thickness,NULL,NULL,iomodel_handle,"thickness");
 	IoModelFetchData(&iomodel->bed,NULL,NULL,iomodel_handle,"bed");
+
+	/*Initialize counter: */
+	count=0;
 
 	/*First load data:*/
@@ -50,6 +56,6 @@
 
 		/*Create and  add load: */
-		loads->AddObject(new Icefront(counter,i,iomodel));
-		counter++;
+		loads->AddObject(new Icefront(iomodel->loadcounter+count+1,i,iomodel));
+		count++;
 
 	}
@@ -73,6 +79,6 @@
 			if(iomodel->my_elements[(int)*(iomodel->riftinfo+RIFTINFOSIZE*i+2)]){
 
-				loads->AddObject(new Riftfront(counter,i,iomodel));
-				counter++;
+				loads->AddObject(new Riftfront(iomodel->loadcounter+count+1,i,iomodel));
+				count++;
 			}
 		}
@@ -88,8 +94,4 @@
 	cleanup_and_return:
 
-	/*All our datasets are already order by ids. Set presort flag so that later on, when sorting is requested on these 
-	 * datasets, it will not be redone: */
-	loads->Presort();
-
 	/*Assign output pointer: */
 	*ploads=loads;
Index: /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateNodesDiagnosticHoriz.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateNodesDiagnosticHoriz.cpp	(revision 4001)
+++ /issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateNodesDiagnosticHoriz.cpp	(revision 4002)
@@ -17,5 +17,4 @@
 	/*Intermediary*/
 	int i;
-	int totalnodes;
 	bool continuous_galerkin=true;
 
@@ -23,12 +22,12 @@
 	DataSet*    nodes = NULL;
 
-	/*First create nodes*/
-	nodes = new DataSet(NodesEnum);
+	/*Recover pointer: */
+	nodes=*pnodes;
+
+	/*Create nodes if they do not exist yet*/
+	if(!nodes) nodes = new DataSet(NodesEnum);
 	
 	/*Now, is the flag macayaealpattyn on? otherwise, do nothing: */
 	if (!iomodel->ismacayealpattyn)goto cleanup_and_return;
-
-	/*Recover number of nodes already created in other analyses: */
-	totalnodes=iomodel->nodecounter;
 
 	/*Continuous Galerkin partition of nodes: */
@@ -51,12 +50,9 @@
 			
 			/*Add node to nodes dataset: */
-			nodes->AddObject(new Node(totalnodes+i+1,i,iomodel,DiagnosticHorizAnalysisEnum));
+			nodes->AddObject(new Node(iomodel->nodecounter+i+1,i,iomodel,DiagnosticHorizAnalysisEnum));
 		}
 	}
 
-	/*Increase nodecounter for other analyses to start their node indexing correctly: */
-	totalnodes+=iomodel->numberofvertices;
-	iomodel->nodecounter=totalnodes;
-
+	
 	/*Clean fetched data: */
 	xfree((void**)&iomodel->gridonbed);
@@ -68,10 +64,5 @@
 	xfree((void**)&iomodel->uppernodes);
 
-	/*All our datasets are already order by ids. Set presort flag so that later on, when sorting is requested on these 
-	 * datasets, it will not be redone: */
-	nodes->Presort();
-
 	/*Assign output pointer: */
 	*pnodes=nodes;
-
 }
Index: /issm/trunk/src/c/modules/ModelProcessorx/ModelProcessorx.h
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/ModelProcessorx.h	(revision 4001)
+++ /issm/trunk/src/c/modules/ModelProcessorx/ModelProcessorx.h	(revision 4002)
@@ -101,3 +101,9 @@
 void    CreateNumberNodeToElementConnectivity(IoModel* iomodel);
 
+/*Diverse: */
+void    SortDataSets(DataSet** pelements,DataSet** pnodes,DataSet** pvertices, DataSet** ploads, DataSet** pmaterials, DataSet** pconstraints, Parameters** pparameters);
+void    UpdateCounter(IoModel* iomodel,DataSet** pnodes,DataSet** ploads, DataSet** pconstraints);
+
+
+
 #endif
Index: /issm/trunk/src/c/modules/ModelProcessorx/SortDataSets.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/SortDataSets.cpp	(revision 4002)
+++ /issm/trunk/src/c/modules/ModelProcessorx/SortDataSets.cpp	(revision 4002)
@@ -0,0 +1,31 @@
+/*!\file: SortDataSets.cpp
+ * \brief sort datasets created in CreateDataSets
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "./ModelProcessorx.h"
+
+
+void SortDataSets(DataSet** pelements,DataSet** pnodes,DataSet** pvertices, DataSet** ploads, DataSet** pmaterials, DataSet** pconstraints, Parameters** pparameters){
+
+	/*All our datasets are already ordered by ids. Set presort flag so that later on, when sorting is requested on these 
+	 * datasets, it will not be redone: */
+
+	if(*pelements)*pelements->Presort();
+	if(*pnodes)*pnodes->Presort();
+	if(*pvertices)*pvertices->Presort();
+	if(*pmaterials)*pmaterials->Presort();
+	if(*ploads)*ploads->Presort();
+	if(*pconstraints)*pconstraints->Presort();
+	if(*pparameters)*pparameters->Presort();
+
+}
Index: /issm/trunk/src/c/modules/ModelProcessorx/UpdateCounters.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/UpdateCounters.cpp	(revision 4002)
+++ /issm/trunk/src/c/modules/ModelProcessorx/UpdateCounters.cpp	(revision 4002)
@@ -0,0 +1,38 @@
+/*!\file: UpdateCounter.cpp
+ * \brief update counters after adding objects to a dataset.
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "./ModelProcessorx.h"
+
+void    UpdateCounter(IoModel* iomodel,DataSet** pnodes,DataSet** ploads, DataSet** pconstraints){
+
+	DataSet* nodes=NULL;
+	DataSet* loads=NULL;
+	DataSet* constraints=NULL;
+
+	/*recover pointers: */
+	nodes=*pnodes;
+	loads=*ploads;
+	cosntraints=*pconstraints;
+
+
+	if(nodes)iomodel->nodecounter=nodes->Size();
+	else iomodel->nodecounter=0;
+
+	if(loads)iomodel->loadcounter=loads->Size();
+	else iomodel->loadcounter=0;
+	
+	if(constraints)iomodel->constraintcounter=constraints->Size();
+	else iomodel->constraintcounter=0;
+
+}
Index: /issm/trunk/src/c/modules/NodesDofx/NodesDofx.cpp
===================================================================
--- /issm/trunk/src/c/modules/NodesDofx/NodesDofx.cpp	(revision 4002)
+++ /issm/trunk/src/c/modules/NodesDofx/NodesDofx.cpp	(revision 4002)
@@ -0,0 +1,40 @@
+/*!\file NodesDofx
+ * \brief: establish degrees of freedom for all nodes
+ */
+
+#include "./NodesDofx.h"
+
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+
+void NodesDofx( DataSet* nodes, Parameters* parameters) {
+
+	int noerr=1;
+	int i;
+
+	int  found=0;
+	
+	/*intermediary: */
+	int  numberofnodes;
+	int  numberofdofspernode;
+
+	/*First, recover number of vertices and nodes from parameters: */
+	found=parameters->FindParam(&numberofnodes,NumberOfNodesEnum);
+	if(!found)ISSMERROR(" could not find numberofnodes in parameters");
+
+	/*Recover number of dofs per node: */
+	found=parameters->FindParam(&numberofdofspernode,NumberOfDofsPerNodeEnum);
+	if(!found)ISSMERROR(" could not find numberofdofspernode in parameters");
+
+	/*Ensure that only for each cpu, the partition border nodes only will be taken into account once 
+	 * across the cluster. To do so, we flag all the clone nodes: */
+	nodes->FlagClones(numberofnodes);
+
+	/*Go through all nodes, and build degree of freedom lists. Each node gets a fixed number of dofs. When 
+	 *a  node has already been distributed dofs on one cpu, all other cpus with the same node cannot distribute it 
+	 *anymore. Use clone field to be sure of that: */
+	nodes->DistributeDofs(numberofnodes,numberofdofspernode);
+
+}
Index: /issm/trunk/src/c/modules/NodesDofx/NodesDofx.h
===================================================================
--- /issm/trunk/src/c/modules/NodesDofx/NodesDofx.h	(revision 4002)
+++ /issm/trunk/src/c/modules/NodesDofx/NodesDofx.h	(revision 4002)
@@ -0,0 +1,15 @@
+/*!\file:  NodesDofx.h
+ * \brief header file for degree of freedoms distribution routines.
+ */ 
+
+#ifndef _NODESDOFX_H
+#define _NODESDOFX_H
+
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+
+/* local prototypes: */
+void NodesDofx( DofVec** partition, DofVec** ptpartition,DataSet* elements,DataSet* nodesin, DataSet* verticesin, Parameters* parameters);
+
+#endif  /* _NODESDOFX_H */
+
Index: /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp
===================================================================
--- /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp	(revision 4001)
+++ /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp	(revision 4002)
@@ -10,5 +10,5 @@
 #include "../../EnumDefinitions/EnumDefinitions.h"
 
-void SpcNodesx(Vec* pyg, DataSet* nodes,DataSet* constraints){
+void SpcNodesx(Vec* pyg, DataSet* nodes,DataSet* constraints,analysis_type){
 
 	int i;
@@ -20,5 +20,5 @@
 
 	/*First, recover number of dofs from nodes: */
-	numberofdofs=nodes->NumberOfDofs();
+	numberofdofs=nodes->NumberOfDofs(analysis_type);
 
 	if(numberofdofs){
Index: /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.h
===================================================================
--- /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.h	(revision 4001)
+++ /issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.h	(revision 4002)
@@ -11,5 +11,5 @@
 
 /* local prototypes: */
-void SpcNodesx(Vec* pyg, DataSet* nodesin,DataSet* constraints);
+void SpcNodesx(Vec* pyg, DataSet* nodesin,DataSet* constraints,int analysis_type);
 
 #endif  /* _SPCNODESX_H */
Index: /issm/trunk/src/c/modules/VerticesDofx/VerticesDofx.cpp
===================================================================
--- /issm/trunk/src/c/modules/VerticesDofx/VerticesDofx.cpp	(revision 4002)
+++ /issm/trunk/src/c/modules/VerticesDofx/VerticesDofx.cpp	(revision 4002)
@@ -0,0 +1,62 @@
+/*!\file VerticesDofx
+ * \brief: establish degrees of freedom for all vertices, and return partitioning vector. Do only once.
+ */
+
+#include "./VerticesDofx.h"
+
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+
+void VerticesDofx( DofVec** ppartition, DofVec** ptpartition, DataSet* vertices, Parameters* parameters) {
+
+	int i;
+
+	int  found=0;
+	extern int num_procs;
+	extern int my_rank;
+	
+	/*intermediary: */
+	int  numberofvertices;
+
+	/*output: */
+	DofVec* partition=NULL;
+	DofVec* tpartition=NULL;
+
+	if(*ppartition)return;
+
+	/*Initialize dofvecs: */
+	partition=new  DofVec("partition");
+	tpartition=new DofVec("tpartition");
+
+	/*First, recover number of vertices and nodes from parameters: */
+	found=parameters->FindParam(&numberofvertices,NumberOfVerticesEnum);
+	if(!found)ISSMERROR(" could not find numberofvertices in parameters");
+	
+	/*Ensure that only for each cpu, the partition border vertices only will be taken into account once 
+	 * across the cluster. To do so, we flag all the clone vertices: */
+	vertices->FlagClones(numberofvertices);
+
+	/*Go through all vertices and distribute 1 dof at a time. When a  vertex has already been distributed his dof on a cpu, 
+	 * all other cpus with the same vertex cannot distribute it anymore. Use clone field to be sure of that: */
+	vertices->DistributeDofs(numberofvertices,1); //only 1 dof per vertex.
+
+	/*Now that dofs have been distributed, create partitioning vector and its transpose: */
+	vertices->CreatePartitioningVector(&partition->vector,numberofvertices);
+
+	/*Transpose partition into tpartition: */
+	VecTranspose(&tpartition->vector,partition->vector);
+
+	/*Now, setup numdof and numentries for dofvec: */
+	partition->numdofs=1;
+	VecGetSize(partition->vector,&partition->numentries);
+
+	tpartition->numdofs=1;
+	VecGetSize(tpartition->vector,&tpartition->numentries);
+
+	/*Assign output pointers: */
+	*ppartition=partition;
+	*ptpartition=tpartition;
+	
+}
Index: /issm/trunk/src/c/modules/VerticesDofx/VerticesDofx.h
===================================================================
--- /issm/trunk/src/c/modules/VerticesDofx/VerticesDofx.h	(revision 4002)
+++ /issm/trunk/src/c/modules/VerticesDofx/VerticesDofx.h	(revision 4002)
@@ -0,0 +1,15 @@
+/*!\file:  VerticesDofx.h
+ * \brief header file for degree of freedoms distribution routines.
+ */ 
+
+#ifndef _VERTICESDOFX_H
+#define _VERTICESDOFX_H
+
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+
+/* local prototypes: */
+void VerticesDofx( DofVec** partition, DofVec** ptpartition,DataSet* vertices, Parameters* parameters);
+
+#endif  /* _VERTICESDOFX_H */
+
Index: /issm/trunk/src/c/modules/modules.h
===================================================================
--- /issm/trunk/src/c/modules/modules.h	(revision 4001)
+++ /issm/trunk/src/c/modules/modules.h	(revision 4002)
@@ -8,5 +8,6 @@
 /*Modules: */
 #include "./ModelProcessorx/ModelProcessorx.h"
-#include "./Dofx/Dofx.h"
+#include "./NodesDofx/NodesDofx.h"
+#include "./VerticesDofx/VerticesDofx.h"
 #include "./Dux/Dux.h"
 #include "./SpcNodesx/SpcNodesx.h"
Index: /issm/trunk/src/c/objects/FemModel.cpp
===================================================================
--- /issm/trunk/src/c/objects/FemModel.cpp	(revision 4001)
+++ /issm/trunk/src/c/objects/FemModel.cpp	(revision 4002)
@@ -124,8 +124,9 @@
 
 	_printf_("   create degrees of freedom: \n");
-	Dofx( &partition,&tpartition,elements,nodes, vertices,parameters);
+	VerticesDofx( &partition,&tpartition,vertices,parameters);
+	NodesDofx( nodes,parameters);
 	
 	_printf_("   create single point constraints: \n");
-	SpcNodesx( &yg[analysis_counter], nodes,constraints); 
+	SpcNodesx( &yg[analysis_counter], nodes,constraints,analysis_type); 
 	
 	_printf_("   create rigid body constraints:\n");
Index: /issm/trunk/src/c/objects/IoModel.cpp
===================================================================
--- /issm/trunk/src/c/objects/IoModel.cpp	(revision 4001)
+++ /issm/trunk/src/c/objects/IoModel.cpp	(revision 4002)
@@ -381,4 +381,6 @@
 	this->numbernodetoelementconnectivity=NULL;
 	this->nodecounter=0;
+	this->loadcounter=0;
+	this->constraintcounter=0;
 }
 /*}}}*/
Index: /issm/trunk/src/c/objects/IoModel.h
===================================================================
--- /issm/trunk/src/c/objects/IoModel.h	(revision 4001)
+++ /issm/trunk/src/c/objects/IoModel.h	(revision 4002)
@@ -187,4 +187,6 @@
 		int*    numbernodetoelementconnectivity;
 		int     nodecounter; //keep track of how many nodes are being created in each analysis type
+		int     loadcounter; //keep track of how many loads are being created in each analysis type
+		int     constraintcounter; //keep track of how many constraints are being created in each analysis type
 		/*}}}*/
 		/*Methods: {{{1*/
Index: /issm/trunk/src/c/objects/Node.cpp
===================================================================
--- /issm/trunk/src/c/objects/Node.cpp	(revision 4001)
+++ /issm/trunk/src/c/objects/Node.cpp	(revision 4002)
@@ -420,4 +420,9 @@
 }
 /*}}}*/
+/*FUNCTION Node::InAnalysis(int analysis_type){{{1*/
+bool Node::InAnalysis(int in_analysis_type){
+	if (in_analysis_type=this->analysis_type)return true;
+	else return false;
+}
 /*}}}*/
 /*Object numerics: {{{1*/
Index: /issm/trunk/src/c/objects/Node.h
===================================================================
--- /issm/trunk/src/c/objects/Node.h	(revision 4001)
+++ /issm/trunk/src/c/objects/Node.h	(revision 4002)
@@ -59,6 +59,6 @@
 		void  UpdateInputsFromConstant(int constant, int name);
 		void  UpdateInputsFromConstant(bool constant, int name);
-
 		void  UpdateInputsFromSolution(double* solution, int analysis_type, int sub_analysis_type){ISSMERROR("Not implemented yet!");}
+		bool  InAnalysis(int analysis_type);
 
 		/*}}}*/
Index: /issm/trunk/src/m/classes/@model/model.m
===================================================================
--- /issm/trunk/src/m/classes/@model/model.m	(revision 4001)
+++ /issm/trunk/src/m/classes/@model/model.m	(revision 4002)
@@ -102,5 +102,4 @@
 	md.minh=0;
 	md.firn_layer=NaN;
-	md.dof=NaN;
 
 	%Extraction
Index: /issm/trunk/src/m/solutions/jpl/CreateFemModel.m
===================================================================
--- /issm/trunk/src/m/solutions/jpl/CreateFemModel.m	(revision 4001)
+++ /issm/trunk/src/m/solutions/jpl/CreateFemModel.m	(revision 4002)
@@ -6,32 +6,36 @@
 %-----------------------------------------------------------------------
 
-function  m=CreateFEMModel(md)
+function  m=CreateFEMModel(md,analyses)
 	
 	displaystring(md.verbose,'\n   reading data from model %s...',md.name);
-	[m.elements,m.nodes,m.vertices,m.constraints,m.loads,m.materials,m.parameters]=ModelProcessor(md);
+	[m.elements,m.nodes,m.vertices,m.constraints,m.loads,m.materials,m.parameters]=ModelProcessor(md,analyses);
 
-	displaystring(md.verbose,'%s','   generating degrees of freedom...');
-	[m.nodes,m.vertices,m.part,m.tpart]=Dof(m.elements,m.nodes,m.vertices, m.parameters);
+	for i=1:length(analyses),
 
-	displaystring(md.verbose,'%s','   generating single point constraints...');
-	[m.nodes,m.yg]=SpcNodes(m.nodes,m.constraints);
+		displaystring(md.verbose,'%s','   generating degrees of freedom...');
+		if ~isfield(m,'part') [m.vertices,m.part,m.tpart]=VerticesDof(vertices, m.parameters);
+		[m.nodes]=NodesDof(m.nodes,m.parameters);
 
-	displaystring(md.verbose,'%s','   generating rigid body constraints...');
-	[m.Rmg,m.nodes]=MpcNodes(m.nodes,m.constraints);
+		displaystring(md.verbose,'%s','   generating single point constraints...');
+		[m.nodes,m.yg]=SpcNodes(m.nodes,m.constraints);
 
-	displaystring(md.verbose,'%s','   generating node sets...');
-	m.nodesets=BuildNodeSets(m.nodes);
+		displaystring(md.verbose,'%s','   generating rigid body constraints...');
+		[m.Rmg,m.nodes]=MpcNodes(m.nodes,m.constraints);
 
-	displaystring(md.verbose,'%s','   reducing single point constraints vector...');
-	m.ys=Reducevectorgtos(m.yg.vector,m.nodesets);
-	
-	displaystring(md.verbose,'%s','   normalizing rigid body constraints matrix...');
-	m.Gmn = NormalizeConstraints(m.Rmg,m.nodesets);
+		displaystring(md.verbose,'%s','   generating node sets...');
+		m.nodesets=BuildNodeSets(m.nodes);
 
-	displaystring(md.verbose,'%s','   configuring element and loads...');
-	[m.elements,m.loads,m.nodes,m.parameters] = ConfigureObjects( m.elements, m.loads, m.nodes, m.vertices,m.materials,m.parameters);
+		displaystring(md.verbose,'%s','   reducing single point constraints vector...');
+		m.ys=Reducevectorgtos(m.yg.vector,m.nodesets);
+		
+		displaystring(md.verbose,'%s','   normalizing rigid body constraints matrix...');
+		m.Gmn = NormalizeConstraints(m.Rmg,m.nodesets);
 
-	displaystring(md.verbose,'%s','   processing parameters...');
-	m.parameters= ProcessParams(m.parameters,m.part.vector);
+		displaystring(md.verbose,'%s','   configuring element and loads...');
+		[m.elements,m.loads,m.nodes,m.parameters] = ConfigureObjects( m.elements, m.loads, m.nodes, m.vertices,m.materials,m.parameters);
+
+		displaystring(md.verbose,'%s','   processing parameters...');
+		m.parameters= ProcessParams(m.parameters,m.part.vector);
+	end
 
 end
Index: /issm/trunk/src/m/solutions/jpl/diagnostic.m
===================================================================
--- /issm/trunk/src/m/solutions/jpl/diagnostic.m	(revision 4001)
+++ /issm/trunk/src/m/solutions/jpl/diagnostic.m	(revision 4002)
@@ -8,45 +8,25 @@
 	t1=clock;
 
-	%Build all models requested for diagnostic simulation
-	models.analysis_type=DiagnosticAnalysisEnum; %needed for processresults
+	analyses=[DiagnosticHorizAnalysisEnum,DiagnosticVertAnalysisEnum,DiagnosticStokesAnalysisEnum,DiagnosticHutterAnalysisEnum,SlopecomputeAnalysisEnum];
 
-	displaystring(md.verbose,'%s',['reading diagnostic horiz model data']);
-	md.analysis_type=DiagnosticAnalysisEnum; md.sub_analysis_type=HorizAnalysisEnum; models.dh=CreateFemModel(md);
-
-	displaystring(md.verbose,'\n%s',['reading diagnostic vert model data']);
-	md.analysis_type=DiagnosticAnalysisEnum; md.sub_analysis_type=VertAnalysisEnum; models.dv=CreateFemModel(md);
-	
-	displaystring(md.verbose,'\n%s',['reading diagnostic stokes model data']);
-	md.analysis_type=DiagnosticAnalysisEnum; md.sub_analysis_type=StokesAnalysisEnum; models.ds=CreateFemModel(md);
-	
-	displaystring(md.verbose,'\n%s',['reading diagnostic hutter model data']);
-	md.analysis_type=DiagnosticAnalysisEnum; md.sub_analysis_type=HutterAnalysisEnum; models.dhu=CreateFemModel(md);
-	
-	displaystring(md.verbose,'\n%s',['reading surface and bed slope computation model data']);
-	md.analysis_type=SlopecomputeAnalysisEnum; md.sub_analysis_type=NoneAnalysisEnum; models.sl=CreateFemModel(md);
-	
-	% figure out number of dof: just for information purposes.
-	md.dof=modelsize(models);
+	displaystring(md.verbose,'%s',['create fem model']);
+	femmodel=CreateFemModel(md,analyses);
 
 	%compute solution
-	if ~models.dh.parameters.QmuAnalysis,
-		if md.control_analysis,
+	if ~femmodel.parameters.QmuAnalysis,
+		if femodel.parameters.control_analysis,
+			
 			%launch core of control solution.
-			results=control_core(models);
+			md.results.DiagnosticAnalysis=control_core(femmodel);
 
-			%process results
-			if ~isstruct(md.results), md.results=struct(); end
-			md.results.DiagnosticAnalysis=processresults(models,results);
 		else,
+			
 			%launch core of diagnostic solution.
-			results=diagnostic_core(models);
+			md.results.DiagnosticAnalysis=diagnostic_core(femmodel);
 
-			%process results
-			if ~isstruct(md.results), md.results=struct(); end
-			md.results.DiagnosticAnalysis=processresults(models,results);
 		end
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(models,models.dh.parameters);
+		Qmu(femmodel);
 	end
 
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 4001)
+++ /issm/trunk/src/mex/Makefile.am	(revision 4002)
@@ -18,5 +18,6 @@
 				CostFunction \
 				DepthAverageInput\
-				Dof\
+				NodesDof\
+				VerticesDof\
 				Du\
 				Echo\
@@ -127,6 +128,9 @@
 			  DepthAverageInput/DepthAverageInput.h
 
-Dof_SOURCES = Dof/Dof.cpp\
-			  Dof/Dof.h
+NodesDof_SOURCES = NodesDof/NodesDof.cpp\
+			  NodesDof/NodesDof.h
+
+VerticesDof_SOURCES = VerticesDof/VerticesDof.cpp\
+			  VerticesDof/VerticesDof.h
 
 Du_SOURCES = Du/Du.cpp\
Index: /issm/trunk/src/mex/ModelProcessor/ModelProcessor.cpp
===================================================================
--- /issm/trunk/src/mex/ModelProcessor/ModelProcessor.cpp	(revision 4001)
+++ /issm/trunk/src/mex/ModelProcessor/ModelProcessor.cpp	(revision 4002)
@@ -8,6 +8,9 @@
 void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){ 
 
-	/*diverse: */
-	int   noerr=1;
+	int i;
+
+	/*inputs: */
+	double* analyses=NULL;
+	int     numanalyses;
 
 	/* output datasets: */
@@ -31,8 +34,12 @@
 	/*Fill iomodel with matlab workspace data: */
 	iomodel=new IoModel(MODEL); //this routine goes through the entire MODEL matlab class, and starts filling the corresponding "c" code model object.
+	FetchData(&analyses,&numanalyses,ANALYSES);
 
-	/*Create elements, nodes and materials: */
-	CreateDataSets(&elements,&nodes,&vertices,&materials,&constraints, &loads, &parameters, iomodel,MODEL);
+	/*Create datasets, and update for each analysis type: */
+	for(i=0;i<numanalyses;i++){
+		CreateDataSets(&elements,&nodes,&vertices,&materials,&constraints, &loads, &parameters, iomodel,MODEL,(int)analyses[i],numanalyses,i);
+	}
 	
+
 	/*Write output data: */
 	WriteData(ELEMENTS,elements);
@@ -54,4 +61,5 @@
 	delete materials;
 	delete parameters;
+	delete analyses;
 
 	/*end module: */
@@ -61,6 +69,6 @@
 void ModelProcessorUsage(void) {
 	_printf_("\n");
-	_printf_("   usage: [elements,grids,constraints,loads,materials,parameters,part,tpart]=ModelProcessor(model)\n");
-	_printf_("   where: model is an instance of the matlab @model class.\n");
+	_printf_("   usage: [elements,grids,constraints,loads,materials,parameters,part,tpart]=ModelProcessor(model,analyses)\n");
+	_printf_("   where: model is an instance of the matlab @model class and analyses is a list of analysis types being performed.\n");
 	_printf_("\n");
 }
Index: /issm/trunk/src/mex/ModelProcessor/ModelProcessor.h
===================================================================
--- /issm/trunk/src/mex/ModelProcessor/ModelProcessor.h	(revision 4001)
+++ /issm/trunk/src/mex/ModelProcessor/ModelProcessor.h	(revision 4002)
@@ -24,4 +24,5 @@
 /* serial input macros: */
 #define MODEL (mxArray*)prhs[0]
+#define ANALYSES (mxArray*)prhs[1]
 
 /* serial output macros: */
@@ -38,5 +39,5 @@
 #define NLHS  7
 #undef NRHS
-#define NRHS  1
+#define NRHS  2
 
 #endif  /* _MEXMODELPROCESSOR_H */
Index: /issm/trunk/src/mex/NodesDof/NodesDof.cpp
===================================================================
--- /issm/trunk/src/mex/NodesDof/NodesDof.cpp	(revision 4002)
+++ /issm/trunk/src/mex/NodesDof/NodesDof.cpp	(revision 4002)
@@ -0,0 +1,41 @@
+/*\file NodesDof.c
+ *\brief: build degrees of freedom for every grid.
+ */
+
+#include "./NodesDof.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*input datasets: */
+	DataSet* vertices=NULL;
+	Parameters* params=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&NodesDofUsage);
+
+	/*Input datasets: */
+	FetchData(&nodes,NODESIN);
+	FetchData((DataSet**)&params,PARAMS);
+
+	/*!Generate internal degree of freedom numbers: */
+	NodesDofx(nodes, params); 
+
+	/*write output datasets: */
+	WriteData(NODES,nodes);
+
+	/*Free ressources: */
+	delete nodes;
+	delete params;
+	/*end module: */
+	MODULEEND();
+}
+
+void NodesDofUsage(void)
+{
+	_printf_("\n");
+	_printf_("   usage: [nodes] = %s(nodes,params);\n",__FUNCT__);
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/NodesDof/NodesDof.h
===================================================================
--- /issm/trunk/src/mex/NodesDof/NodesDof.h	(revision 4002)
+++ /issm/trunk/src/mex/NodesDof/NodesDof.h	(revision 4002)
@@ -0,0 +1,35 @@
+
+/*
+	NodesDof.h
+*/
+
+
+#ifndef _NODESDOF_H
+#define _NODESDOF_H
+
+/* local prototypes: */
+void NodesDofUsage(void);
+
+#include "../../c/modules/modules.h"
+#include "../../c/DataSet/DataSet.h"
+#include "../../c/shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "NodesDof"
+
+/* serial input macros: */
+#define NODESIN (mxArray*)prhs[0]
+#define PARAMS (mxArray*)prhs[1]
+
+/* serial output macros: */
+#define NODES (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  2
+
+
+#endif  /* _NODESDOF_H */
+
Index: /issm/trunk/src/mex/VerticesDof/VerticesDof.cpp
===================================================================
--- /issm/trunk/src/mex/VerticesDof/VerticesDof.cpp	(revision 4002)
+++ /issm/trunk/src/mex/VerticesDof/VerticesDof.cpp	(revision 4002)
@@ -0,0 +1,57 @@
+/*\file VerticesDof.c
+ *\brief: build degrees of freedom for every vertex.
+ */
+
+#include "./VerticesDof.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*diverse: */
+	int   noerr=1;
+
+	/*input datasets: */
+	DataSet* vertices=NULL;
+	Parameters* params=NULL;
+
+	/* output datasets: */
+	VerticesDofVec* partition=NULL;
+	VerticesDofVec* tpartition=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&VerticesDofUsage);
+
+	/*Input datasets: */
+	FetchData(&vertices,VERTICESIN);
+	FetchData((DataSet**)&params,PARAMS);
+
+	/*!Generate internal degree of freedom numbers: */
+	VerticesDofx(&partition, &tpartition, vertices, params); 
+
+	/*partition and tpartition should be incremented by 1: */
+	VecShift(partition->vector,1.0); //matlab indexing starts at 1.
+	VecShift(tpartition->vector,1.0);
+
+	/*write output datasets: */
+	WriteData(VERTICES,vertices);
+	WriteData(PARTITION,partition);
+	WriteData(TPARTITION,tpartition);
+
+	/*Free ressources: */
+	delete vertices;
+	delete params;
+	delete partition;
+	delete tpartition;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void VerticesDofUsage(void)
+{
+	_printf_("\n");
+	_printf_("   usage: [vertices,part,tpart] = %s(vertices,params);\n",__FUNCT__);
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/VerticesDof/VerticesDof.h
===================================================================
--- /issm/trunk/src/mex/VerticesDof/VerticesDof.h	(revision 4002)
+++ /issm/trunk/src/mex/VerticesDof/VerticesDof.h	(revision 4002)
@@ -0,0 +1,37 @@
+
+/*
+	VerticesDof.h
+*/
+
+
+#ifndef _VERTICESDOF_H
+#define _VERTICESDOF_H
+
+/* local prototypes: */
+void VerticesDofUsage(void);
+
+#include "../../c/modules/modules.h"
+#include "../../c/DataSet/DataSet.h"
+#include "../../c/shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "VerticesDof"
+
+/* serial input macros: */
+#define VERTICESIN (mxArray*)prhs[0]
+#define PARAMS (mxArray*)prhs[1]
+
+/* serial output macros: */
+#define VERTICES (mxArray**)&plhs[0]
+#define PARTITION (mxArray**)&plhs[1]
+#define TPARTITION (mxArray**)&plhs[2]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  3
+#undef NRHS
+#define NRHS  2
+
+
+#endif  /* _VERTICESDOF_H */
+
