Index: ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.h
===================================================================
--- ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.h	(revision 18658)
+++ ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.h	(revision 18659)
@@ -47,9 +47,10 @@
 		static void DrainWaterfractionIcecolumn(Element* element);
 		static void DrainWaterfraction(Element* element, IssmDouble* pdrainrate_element);
 		static void UpdateBasalConstraints(FemModel* femmodel);
-		static void UpdateBasalConstraints(Element* element);
-		static void UpdateBasalConstraintsTransient(Element* element);
-		static void UpdateBasalConstraintsSteadystate(Element* element);
+		static void ApplyBasalConstraints(IssmDouble* serial_spc,Element* element);
+		static void GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element);
+		static void GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element);
+		static void GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element);
 		static int GetThermalBasalCondition(Element* element, IssmDouble enthalpy, IssmDouble enthalpy_up, IssmDouble pressure, IssmDouble pressure_up, IssmDouble watercolumn, IssmDouble meltingrate);
 		static IssmDouble GetWetIceConductivity(Element* element, IssmDouble enthalpy, IssmDouble pressure);
 
Index: ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp	(revision 18658)
+++ ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp	(revision 18659)
@@ -1188,14 +1188,35 @@
 	xDelete<IssmDouble>(deltawaterfractions);
 }/*}}}*/
 void EnthalpyAnalysis::UpdateBasalConstraints(FemModel* femmodel){/*{{{*/
+
 	/*Update basal dirichlet BCs for enthalpy: */
+	Vector<IssmDouble>* spc           = NULL;
+	IssmDouble*         serial_spc    = NULL;
+
+	spc=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes(EnthalpyAnalysisEnum));
+	/*First create a vector to figure out what elements should be constrained*/
 	for(int i=0;i<femmodel->elements->Size();i++){
 		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
-		UpdateBasalConstraints(element);
+		GetBasalConstraints(spc,element);
 	}
+
+	/*Assemble and serialize*/
+	spc->Assemble();
+	serial_spc=spc->ToMPISerial();
+	delete spc;
+
+	/*Then update basal constraints nodes accordingly*/
+	for(int i=0;i<femmodel->elements->Size();i++){
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		ApplyBasalConstraints(serial_spc,element);
+	}
+
 	femmodel->UpdateConstraintsx();
+
+	/*Delete*/
+	xDelete<IssmDouble>(serial_spc);
 }/*}}}*/
-void EnthalpyAnalysis::UpdateBasalConstraints(Element* element){/*{{{*/
+void EnthalpyAnalysis::ApplyBasalConstraints(IssmDouble* serial_spc,Element* element){/*{{{*/
 
 	/* Check if ice in element */
 	if(!element->IsIceInElement()) return;
@@ -1205,6 +1226,52 @@
 
 	/*Intermediary*/
 	bool        isdynamicbasalspc;
+	int         numindices;
+	int        *indices = NULL;
+	Node*       node = NULL;
+	IssmDouble	pressure;
+
+	/*Check wether dynamic basal boundary conditions are activated */
+	element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
+	if(!isdynamicbasalspc) return;
+
+	/*Get parameters and inputs: */
+	Input* pressure_input		 = element->GetInput(PressureEnum);							 _assert_(pressure_input);
+
+	/*Fetch indices of basal & surface nodes for this finite element*/
+	Penta *penta =  (Penta *) element; // TODO: add Basal-/SurfaceNodeIndices to element.h, and change this to Element*
+	penta->BasalNodeIndices(&numindices,&indices,element->GetElementType());
+
+	GaussPenta* gauss=new GaussPenta();
+	for(int i=0;i<numindices;i++){
+		gauss->GaussNode(element->GetElementType(),indices[i]);
+
+		pressure_input->GetInputValue(&pressure,gauss);
+
+		/*apply or release spc*/
+		node=element->GetNode(indices[i]);
+		if(serial_spc[node->Sid()]==1.){
+			pressure_input->GetInputValue(&pressure, gauss);
+			node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
+		}
+		else			
+			node->DofInFSet(0);
+	}
+
+	/*Free ressources:*/
+	xDelete<int>(indices);
+	delete gauss;
+}/*}}}*/
+void EnthalpyAnalysis::GetBasalConstraints(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
+
+	/* Check if ice in element */
+	if(!element->IsIceInElement()) return;
+
+	/* Only update Constraints at the base of grounded ice*/
+	if(!(element->IsOnBase()) || element->IsFloating()) return;
+
+	/*Intermediary*/
+	bool        isdynamicbasalspc;
 	IssmDouble	dt;
 
 	/*Check wether dynamic basal boundary conditions are activated */
@@ -1213,13 +1280,13 @@
 
 	element->FindParam(&dt,TimesteppingTimeStepEnum);
 	if(dt==0.){
-		UpdateBasalConstraintsSteadystate(element);
+		GetBasalConstraintsSteadystate(vec_spc,element);
 	}
 	else{
-		UpdateBasalConstraintsTransient(element);
+		GetBasalConstraintsTransient(vec_spc,element);
 	}
 }/*}}}*/
-void EnthalpyAnalysis::UpdateBasalConstraintsTransient(Element* element){/*{{{*/
+void EnthalpyAnalysis::GetBasalConstraintsTransient(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
 
 	/* Check if ice in element */
 	if(!element->IsIceInElement()) return;
@@ -1228,16 +1295,10 @@
 	if(!(element->IsOnBase()) || element->IsFloating()) return;
 
 	/*Intermediary*/
-	bool        isdynamicbasalspc,setspc;
 	int         numindices, numindicesup, state;
 	int        *indices = NULL, *indicesup = NULL;
-	Node*       node = NULL;
 	IssmDouble	enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
 
-	/*Check wether dynamic basal boundary conditions are activated */
-	element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
-	if(!isdynamicbasalspc) return;
-
 	/*Get parameters and inputs: */
 	Input* enthalpy_input       = element->GetInput(EnthalpyEnum);                    _assert_(enthalpy_input); //TODO: check EnthalpyPicard?
 	Input* pressure_input		 = element->GetInput(PressureEnum);							 _assert_(pressure_input);
@@ -1265,37 +1326,31 @@
 
 		state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
 
-		setspc=false;
 		switch (state) {
 			case 0:
 				// cold, dry base: apply basal surface forcing
+				vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
 				break;
 			case 1:
 				// cold, wet base: keep at pressure melting point 
-				setspc=true;
+				vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
 				break;
 			case 2:
 				// temperate, thin refreezing base: release spc
+				vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
 				break;
 			case 3:
 				// temperate, thin melting base: set spc
-				setspc=true;
+				vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
 				break;
 			case 4:
 				// temperate, thick melting base: set grad H*n=0
+				vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
 				break;
 			default:
 				_printf0_("	unknown thermal basal state found!");
 		}
 
-		/*apply or release spc*/
-		node=element->GetNode(indices[i]);
-		if(setspc){
-			pressure_input->GetInputValue(&pressure, gauss);
-			node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
-		}
-		else			
-			node->DofInFSet(0);
 	}
 
 	/*Free ressources:*/
@@ -1304,7 +1359,7 @@
 	delete gauss;
 	delete gaussup;
 }/*}}}*/
-void EnthalpyAnalysis::UpdateBasalConstraintsSteadystate(Element* element){/*{{{*/
+void EnthalpyAnalysis::GetBasalConstraintsSteadystate(Vector<IssmDouble>* vec_spc,Element* element){/*{{{*/
 
 	/* Check if ice in element */
 	if(!element->IsIceInElement()) return;
@@ -1313,16 +1368,10 @@
 	if(!(element->IsOnBase()) || element->IsFloating()) return;
 
 	/*Intermediary*/
-	bool        isdynamicbasalspc,setspc;
 	int         numindices, numindicesup, state;
 	int        *indices = NULL, *indicesup = NULL;
-	Node*       node = NULL;
 	IssmDouble	enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate;
 
-	/*Check wether dynamic basal boundary conditions are activated */
-	element->FindParam(&isdynamicbasalspc,ThermalIsdynamicbasalspcEnum);
-	if(!isdynamicbasalspc) return;
-
 	/*Get parameters and inputs: */
 	Input* enthalpy_input		 = element->GetInput(EnthalpyPicardEnum);					 _assert_(enthalpy_input);
 	Input* pressure_input		 = element->GetInput(PressureEnum);							 _assert_(pressure_input);
@@ -1348,38 +1397,30 @@
 		meltingrate_input->GetInputValue(&meltingrate,gauss);
 
 		state=GetThermalBasalCondition(element, enthalpy, enthalpyup, pressure, pressureup, watercolumn, meltingrate);
-		setspc=false;
 		switch (state) {
 			case 0:
 				// cold, dry base: apply basal surface forcing
+				vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
 				break;
 			case 1:
 				// cold, wet base: keep at pressure melting point 
-				setspc=true;
+				vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
 				break;
 			case 2:
 				// temperate, thin refreezing base: release spc
+				vec_spc->SetValue(element->nodes[i]->Sid(),0.,INS_VAL);
 				break;
 			case 3:
 				// temperate, thin melting base: set spc
-				setspc=true;
+				vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
 				break;
 			case 4:
 				// temperate, thick melting base: s
-				setspc=true;
+				vec_spc->SetValue(element->nodes[i]->Sid(),1.,INS_VAL);
 				break;
 			default:
 				_printf0_("	unknown thermal basal state found!");
 		}
-
-		/*apply or release spc*/
-		node=element->GetNode(indices[i]);
-		if(setspc){
-			pressure_input->GetInputValue(&pressure, gauss);
-			node->ApplyConstraint(0,PureIceEnthalpy(element,pressure));
-		}
-		else			
-			node->DofInFSet(0);
 	}
 
 	/*Free ressources:*/
