Index: /issm/trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 23480)
+++ /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 23481)
@@ -183,5 +183,8 @@
 	if(nodes)delete nodes;
 	if(vertices)delete vertices;
-	if(constraints)delete constraints;
+	if(this->constraints_list && this->nummodels){
+		for(int i=0;i<this->nummodels;i++) delete this->constraints_list[i];
+		xDelete<Constraints*>(constraints_list);
+	}
 	if(loads)delete loads;
 	if(materials)delete materials;
@@ -202,4 +205,19 @@
 
 /*Object management*/
+int FemModel::AnalysisIndex(int analysis_enum){/*{{{*/
+
+	int found=-1;
+	_assert_(this->analysis_type_list); 
+	for(int i=0;i<this->nummodels;i++){
+		if(this->analysis_type_list[i]==analysis_enum){
+			found=i;
+			break;
+		}
+	}
+	if(found!=-1) return found;
+	else _error_("Could not find index of analysis " << EnumToStringx(analysis_enum) << " in list of FemModel analyses");
+
+
+}/*}}}*/
 void FemModel::CheckPoint(void){/*{{{*/
 
@@ -300,4 +318,7 @@
 	xMemCpy<int>(output->analysis_type_list,this->analysis_type_list,this->nummodels);
 
+	/*Analysis dependent arrays*/
+	output->constraints_list=xNew<Constraints*>(this->nummodels);
+
 	output->profiler=static_cast<Profiler*>(this->profiler->copy());
 
@@ -305,5 +326,4 @@
 	output->materials=static_cast<Materials*>(this->materials->Copy());
 	output->parameters=static_cast<Parameters*>(this->parameters->Copy());
-	output->constraints=static_cast<Constraints*>(this->constraints->Copy());
 	output->results=static_cast<Results*>(this->results->Copy());
 
@@ -319,8 +339,9 @@
 	/*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
 	for(i=0;i<nummodels;i++){
+		output->constraints_list[i] = static_cast<Constraints*>(this->constraints_list[i]->Copy());
 		analysis_type=output->analysis_type_list[i];
 		output->SetCurrentConfiguration(analysis_type);
 		if(i==0) VerticesDofx(output->vertices,output->parameters); //only call once, we only have one set of vertices
-		SpcNodesx(output->nodes,output->constraints,output->parameters,analysis_type);
+		SpcNodesx(output->nodes,output->constraints_list[i],output->parameters,analysis_type);
 		NodesDofx(output->nodes,output->parameters,analysis_type);
 		ConfigureObjectsx(output->elements,output->loads,output->nodes,output->vertices,output->materials,output->parameters);
@@ -398,5 +419,5 @@
 
 	/*create datasets for all analyses*/
-	ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,iomodel,toolkitsoptionsfid,rootpath,this->solution_type,this->nummodels,this->analysis_type_list);
+	ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints_list,&this->loads,&this->parameters,iomodel,toolkitsoptionsfid,rootpath,this->solution_type,this->nummodels,this->analysis_type_list);
 
 	/*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
@@ -418,5 +439,5 @@
 
 		if(VerboseMProcessor()) _printf0_("      resolving node constraints\n");
-		SpcNodesx(nodes,constraints,parameters,analysis_type_list[i]);
+		SpcNodesx(nodes,this->constraints,parameters,analysis_type_list[i]);
 
 		if(VerboseMProcessor()) _printf0_("      creating nodal degrees of freedom\n");
@@ -436,5 +457,8 @@
 		delete this->materials;
 		delete this->parameters;
-		delete this->constraints;
+		if(this->constraints_list && this->nummodels){
+			for(i=0;i<this->nummodels;i++) delete this->constraints_list[i];
+			xDelete<Constraints*>(constraints_list);
+		}
 		delete this->results;
 		delete this->nodes;
@@ -446,5 +470,4 @@
 		this->materials   = new Materials();
 		this->parameters  = new Parameters();
-		this->constraints = new Constraints();
 		this->results     = new Results();
 		this->nodes       = new Nodes();
@@ -463,9 +486,17 @@
 	this->materials->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	this->parameters->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
-	this->constraints->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	this->results->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	this->nodes->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	this->vertices->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	this->elements->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+
+	if(marshall_direction==MARSHALLING_BACKWARD){
+		this->constraints_list = xNew<Constraints*>(this->nummodels);
+		for(i=0;i<nummodels;i++) this->constraints_list[i] = new Constraints();
+	}
+
+	for(i=0;i<nummodels;i++){
+		this->constraints_list[i]->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+	}
 
 	if(marshall_direction==MARSHALLING_BACKWARD){
@@ -480,5 +511,5 @@
 			SetCurrentConfiguration(analysis_type);
 			if(i==0) VerticesDofx(this->vertices,this->parameters); //only call once, we only have one set of vertices
-			SpcNodesx(this->nodes,this->constraints,this->parameters,analysis_type);
+			SpcNodesx(this->nodes,this->constraints_list[i],this->parameters,analysis_type);
 			NodesDofx(this->nodes,this->parameters,analysis_type);
 			ConfigureObjectsx(this->elements,this->loads,this->nodes,this->vertices,this->materials,this->parameters);
@@ -489,5 +520,4 @@
 		SetCurrentConfiguration(analysis_type);
 	}
-
 }
 /*}}}*/
@@ -559,5 +589,5 @@
 		}
 	}
-	if(found!=-1) analysis_counter=found;
+	if(found!=-1) this->analysis_counter=found;
 	else _error_("Could not find alias for analysis_type " << EnumToStringx(configuration_type) << " in list of FemModel analyses");
 
@@ -570,4 +600,5 @@
 	this->elements->SetCurrentConfiguration(elements,loads, nodes,vertices, materials,parameters);
 	this->loads->SetCurrentConfiguration(elements, loads, nodes,vertices, materials,parameters);
+	this->constraints = this->constraints_list[this->analysis_counter];
 
 	/*take care of toolkits options, that depend on this analysis type (present only after model processor)*/
@@ -2488,4 +2519,6 @@
 	parameters->FindParam(&time,TimeEnum);
 
+	int index=AnalysisIndex(analysis_type);
+
 	/*start module: */
 	if(VerboseModule()) _printf0_("   Updating constraints and active domain of analysis " << EnumToStringx(analysis_type)  << " for time: " << time << "\n");
@@ -2596,6 +2629,6 @@
 	/*Creating nodes and constraints*/
 	/*Just SSA (2D) and P1 in this version*/
-	Nodes* new_nodes					= new Nodes();
-	Constraints* new_constraints	= new Constraints();
+	Nodes* new_nodes = new Nodes();
+	Constraints** new_constraints_list = xNew<Constraints*>(this->nummodels);
 
 	int nodecounter		=0;
@@ -2603,4 +2636,6 @@
 	for(int i=0;i<this->nummodels;i++){//create nodes for each analysis in analysis_type_list
 
+		new_constraints_list[i] = new Constraints();
+
 		int analysis_enum = this->analysis_type_list[i];
 
@@ -2609,11 +2644,13 @@
 
 		this->CreateNodes(newnumberofvertices,my_vertices,nodecounter,analysis_enum,new_nodes);
-		this->CreateConstraints(new_vertices,nodecounter,constraintcounter,analysis_enum,new_constraints);
-		this->UpdateElements(newnumberofelements,newelementslist,my_elements,nodecounter,i,new_elements);
+		this->CreateConstraints(new_vertices,nodecounter,constraintcounter,analysis_enum,new_constraints_list[i]);
+		//this->UpdateElements(newnumberofelements,newelementslist,my_elements,nodecounter,i,new_elements);
 
 		if(new_nodes->Size()) nodecounter=new_nodes->MaximumId();
-		constraintcounter = new_constraints->NumberOfConstraints();
+		constraintcounter = new_constraints_list[i]->NumberOfConstraints();
 		/*Make sure nodecounter is at least 0 (if no node exists, maxid will be -1*/
 		_assert_(nodecounter>=0);
+
+		new_constraints_list[i]->Presort();
 	}
 
@@ -2623,5 +2660,4 @@
 	this->loads->Presort();
 	new_materials->Presort();
-	new_constraints->Presort();
 
 	/*reset hooks for elements, loads and nodes: */
@@ -2634,5 +2670,5 @@
 	for(int i=0;i<this->nummodels;i++){
 		analysis_type=this->analysis_type_list[i];
-		//SetCurrentConfiguration(analysis_type);
+		SetCurrentConfiguration(analysis_type);
 
 		this->analysis_counter=i;
@@ -2656,5 +2692,5 @@
 			VerticesDofx(new_vertices,this->parameters); //only call once, we only have one set of vertices
 		}
-		SpcNodesx(new_nodes,new_constraints,this->parameters,analysis_type);
+		SpcNodesx(new_nodes,new_constraints_list[i],this->parameters,analysis_type);
 		NodesDofx(new_nodes,this->parameters,analysis_type);
 	}
@@ -2667,6 +2703,11 @@
 	delete this->elements;		this->elements		= new_elements;
 	delete this->nodes;			this->nodes			= new_nodes;
-	delete this->constraints;	this->constraints	= new_constraints;
 	delete this->materials;		this->materials	= new_materials;
+
+	if(this->constraints_list && this->nummodels){
+		for(int i=0;i<this->nummodels;i++) delete this->constraints_list[i];
+		xDelete<Constraints*>(this->constraints_list);
+	}
+	this->constraints_list = new_constraints_list;
 
 	GetMaskOfIceVerticesLSMx0(this);
@@ -3393,4 +3434,5 @@
 	/*OTHERS CONSTRAINTS MUST BE IMPLEMENTED*/
 	if(analysis_enum!=StressbalanceAnalysisEnum) return;
+	int analysis_index = AnalysisIndex(analysis_enum);
 
 	int numberofnodes_analysistype= this->nodes->NumberOfNodes(analysis_enum);
@@ -3426,7 +3468,7 @@
 
 	/*Get spcvx and spcvy of old mesh*/
-	for(int i=0;i<this->constraints->Size();i++){
-
-		Constraint* constraint=(Constraint*)constraints->GetObjectByOffset(i);
+	for(int i=0;i<this->constraints_list[analysis_index]->Size();i++){
+
+		Constraint* constraint=(Constraint*)this->constraints_list[analysis_index]->GetObjectByOffset(i);
 		if(!constraint->InAnalysis(analysis_enum)) _error_("AMR create constraints for "<<EnumToStringx(analysis_enum)<<" not supported yet!\n");
 
Index: /issm/trunk-jpl/src/c/classes/FemModel.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.h	(revision 23480)
+++ /issm/trunk-jpl/src/c/classes/FemModel.h	(revision 23481)
@@ -41,5 +41,4 @@
 		Profiler*    profiler;             //keep time, cpu and mem statistics while we are running.
 
-		Constraints *constraints;          //one set of constraints. each constraint knows which analysis_type it handles
 		Elements    *elements;             //elements (one set for all analyses)
 		Loads       *loads;                //one set of constraints. each constraint knows which analysis_type it handles
@@ -50,4 +49,8 @@
 		Vertices    *vertices;             //one set of vertices
 
+		/*Analysis dependent datasets*/
+		Constraints  *constraints;
+		Constraints **constraints_list;
+
 		//FIXME: do we want only one class and have virtual functions? or keep 2 classes, at least rename AdaptiveMeshRefinement -> AmrNeopz
 		#if defined(_HAVE_NEOPZ_) && !defined(_HAVE_AD_)
@@ -65,4 +68,5 @@
 
 		/*Methods:*/
+		int  AnalysisIndex(int);
 		void CheckPoint(void);
 		void CleanUp(void);
Index: /issm/trunk-jpl/src/c/cores/ResetBoundaryConditions.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/ResetBoundaryConditions.cpp	(revision 23480)
+++ /issm/trunk-jpl/src/c/cores/ResetBoundaryConditions.cpp	(revision 23481)
@@ -13,7 +13,9 @@
 
 	if(VerboseSolution()) _printf0_("   updating boundary conditions...\n");
+	_assert_(femmodel->analysis_type_list[femmodel->analysis_counter]==analysis_type); 
 
 	/*set current analysis: */
 	femmodel->SetCurrentConfiguration(analysis_type);
+	int index = femmodel->AnalysisIndex(analysis_type);
 
 	/*retrieve boundary conditions from element inputs :*/
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/ModelProcessorx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/ModelProcessorx.cpp	(revision 23480)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/ModelProcessorx.cpp	(revision 23481)
@@ -13,5 +13,5 @@
 #include "./ModelProcessorx.h"
 
-void ModelProcessorx(Elements** pelements, Nodes** pnodes, Vertices** pvertices, Materials** pmaterials, Constraints** pconstraints, Loads** ploads, Parameters** pparameters,IoModel* iomodel,FILE* toolkitfile, char* rootpath,const int solution_enum,const int nummodels,const int* analysis_enum_list){
+void ModelProcessorx(Elements** pelements, Nodes** pnodes, Vertices** pvertices, Materials** pmaterials, Constraints*** pconstraints, Loads** ploads, Parameters** pparameters,IoModel* iomodel,FILE* toolkitfile, char* rootpath,const int solution_enum,const int nummodels,const int* analysis_enum_list){
 
 	/*Set Verbosity once for all*/
@@ -28,7 +28,9 @@
 	Vertices    *vertices    = new Vertices();
 	Materials   *materials   = new Materials();
-	Constraints *constraints = new Constraints();
 	Loads       *loads       = new Loads();
 	Parameters  *parameters  = new Parameters();
+
+	Constraints **constraints = xNew<Constraints*>(nummodels);
+	for(int i=0;i<nummodels;i++) constraints[i] = new Constraints();
 
 
@@ -53,5 +55,5 @@
 		analysis->UpdateParameters(parameters,iomodel,solution_enum,analysis_enum);
 		analysis->CreateNodes(nodes,iomodel);
-		analysis->CreateConstraints(constraints,iomodel);
+		analysis->CreateConstraints(constraints[i],iomodel);
 		analysis->CreateLoads(loads,iomodel);
 		analysis->UpdateElements(elements,iomodel,i,analysis_enum);
@@ -63,8 +65,11 @@
 		if(nodes->Size()) iomodel->nodecounter = nodes->MaximumId();
 		iomodel->loadcounter       = loads->NumberOfLoads();
-		iomodel->constraintcounter = constraints->NumberOfConstraints();
+		iomodel->constraintcounter = constraints[i]->NumberOfConstraints();
 
 		/*Make sure nodecounter is at least 0 (if no node exists, maxid will be -1*/
 		_assert_(iomodel->nodecounter>=0);
+
+		/*Tell constraints that Ids are already sorted*/
+		constraints[i]->Presort();
 	}
 
@@ -91,5 +96,4 @@
 	loads->Presort();
 	materials->Presort();
-	constraints->Presort();
 
 	/*Assign output pointers:*/
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/ModelProcessorx.h
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/ModelProcessorx.h	(revision 23480)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/ModelProcessorx.h	(revision 23481)
@@ -9,5 +9,5 @@
 #include "../../analyses/analyses.h"
 
-void ModelProcessorx(Elements** pelements, Nodes** pnodes, Vertices** pvertices, Materials** pmaterials, Constraints** pconstraints, Loads** ploads, Parameters** pparameters,IoModel* iomodel,FILE* toolkitfile, char* rootpath,const int solution_type,const int nummodels,const int* analysis_type_listh);
+void ModelProcessorx(Elements** pelements, Nodes** pnodes, Vertices** pvertices, Materials** pmaterials, Constraints*** pconstraints, Loads** ploads, Parameters** pparameters,IoModel* iomodel,FILE* toolkitfile, char* rootpath,const int solution_type,const int nummodels,const int* analysis_type_listh);
 
 /*Creation of fem datasets: general drivers*/
