Index: /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp
===================================================================
--- /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 10376)
+++ /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 10377)
@@ -13,7 +13,8 @@
 void GroundinglineMigrationx(Elements* elements,Nodes* nodes, Vertices* vertices,Loads* loads,Materials* materials, Parameters* parameters){
 
-	int      i, migration_style;
+	int      i, migration_style,analysis_type;
 	double*  vertices_potentially_ungrounding = NULL;
 	double*  vertices_ungrounding             = NULL;
+	double*  old_floatingice                  = NULL;
 	Element* element                          = NULL;
 	
@@ -22,4 +23,6 @@
 	/*retrieve parameters: */
 	parameters->FindParam(&migration_style,GroundinglineMigrationEnum);
+	parameters->FindParam(&analysis_type,AnalysisTypeEnum);
+
 	if(migration_style==NoneEnum) return;
 	if(migration_style!=AgressiveMigrationEnum && migration_style!=SoftMigrationEnum) _error_("%s not supported yet!",EnumToStringx(migration_style));
@@ -33,14 +36,11 @@
 	}
 
+	/*Create vector with vertices initially floating*/
+	old_floatingice=CreateNodesOnIceShelf(nodes,analysis_type);
+
 	/*Migrate grounding line : */
 	for(i=0;i<elements->Size();i++){
 		element=(Element*)elements->GetObjectByOffset(i);
-		element->MigrateGroundingLine(vertices_ungrounding);
-	}
-
-	/*Synchronise mask: */
-	for(i=0;i<elements->Size();i++){
-		element=(Element*)elements->GetObjectByOffset(i);
-		element->ShelfSync();
+		element->MigrateGroundingLine(old_floatingice,vertices_ungrounding);
 	}
 
@@ -48,4 +48,5 @@
 	xfree((void**)&vertices_potentially_ungrounding);
 	xfree((void**)&vertices_ungrounding);
+	xfree((void**)&old_floatingice);
 }
 /*FUNCTION PotentialSheetUngrounding {{{1*/
@@ -67,9 +68,7 @@
 	}
 
-	/*Assemble vector: */
+	/*Assemble vector and serialize */
 	VecAssemblyBegin(vec_vertices_potentially_ungrounding);
 	VecAssemblyEnd(vec_vertices_potentially_ungrounding);
-
-	/*Serialize vector: */
 	VecToMPISerial(&vertices_potentially_ungrounding,vec_vertices_potentially_ungrounding);
 
@@ -162,2 +161,35 @@
 }
 /*}}}*/
+/*FUNCTION CreateNodesOnIceShelf {{{1*/
+double* CreateNodesOnIceShelf(Nodes* nodes,int configuration_type){ 
+
+	int     i,numnods;
+	double* nodes_on_floatingice  = NULL;
+	Vec     vec_nodes_on_iceshelf = NULL;
+	Node*   node                  = NULL;
+
+	/*First, initialize nodes_on_iceshelf, which will track which nodes have changed status: */
+	numnods=nodes->NumberOfNodes(configuration_type);
+	vec_nodes_on_iceshelf=NewVec(numnods);
+
+	/*Loop through nodes, and fill vec_nodes_on_iceshelf: */
+	for(i=0;i<nodes->Size();i++){
+		node=(Node*)nodes->GetObjectByOffset(i);
+		if(node->InAnalysis(configuration_type)){
+			if(node->IsFloating()){
+				VecSetValue(vec_nodes_on_iceshelf,node->Sid(),1.0,INSERT_VALUES);
+			}
+		}
+	}
+
+	/*Assemble vector: */
+	VecAssemblyBegin(vec_nodes_on_iceshelf);
+	VecAssemblyEnd(vec_nodes_on_iceshelf);
+	VecToMPISerial(&nodes_on_floatingice,vec_nodes_on_iceshelf);
+
+	/*Free ressources*/
+	VecFree(&vec_nodes_on_iceshelf);
+
+	return nodes_on_floatingice;
+}
+/*%}}}*/
Index: /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.h
===================================================================
--- /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.h	(revision 10376)
+++ /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.h	(revision 10377)
@@ -15,3 +15,4 @@
 double*    PotentialSheetUngrounding(Elements* elements,Vertices* vertices,Parameters* parameters);
 double*    PropagateFloatingiceToGrounded(Elements* elements,Nodes* nodes,Vertices* vertices,Parameters* parameters,double* vertices_potentially_ungrounding);
+double*    CreateNodesOnIceShelf(Nodes* nodes,int configuration_type);
 #endif  /* _GROUNDINGLINEMIGRATIONX_H */
Index: /issm/trunk/src/c/objects/Elements/Element.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Element.h	(revision 10376)
+++ /issm/trunk/src/c/objects/Elements/Element.h	(revision 10377)
@@ -65,6 +65,5 @@
 		virtual int*   GetHorizontalNeighboorSids(void)=0;
 		virtual double TimeAdapt()=0;
-		virtual void   MigrateGroundingLine(double* sheet_ungrounding)=0;
-		virtual void   ShelfSync()=0;
+		virtual void   MigrateGroundingLine(double* old_floating_ice,double* sheet_ungrounding)=0;
 		virtual void   PotentialSheetUngrounding(Vec potential_sheet_ungrounding)=0;
 		virtual int    UpdatePotentialSheetUngrounding(double* potential_sheet_ungrounding,Vec vec_nodes_on_iceshelf,double* nodes_on_iceshelf)=0;
Index: /issm/trunk/src/c/objects/Elements/Penta.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 10376)
+++ /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 10377)
@@ -304,9 +304,4 @@
 void  Penta::AverageOntoPartition(Vec partition_contributions,Vec partition_areas,double* vertex_response,double* qmu_part){
 	_error_("Not supported yet!");
-}
-/*}}}*/
-/*FUNCTION Penta::ShelfSync{{{1*/
-void  Penta::ShelfSync(void){
-	_error_("not supported yet!");
 }
 /*}}}*/
@@ -2042,5 +2037,5 @@
 }/*}}}*/
 /*FUNCTION Penta::MigrateGroundingLine{{{1*/
-void  Penta::MigrateGroundingLine(double* sheet_ungrounding){
+void  Penta::MigrateGroundingLine(double* old_floating_ice,double* sheet_ungrounding){
 	_error_("not supported yet!");
 }
Index: /issm/trunk/src/c/objects/Elements/Penta.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.h	(revision 10376)
+++ /issm/trunk/src/c/objects/Elements/Penta.h	(revision 10377)
@@ -103,7 +103,6 @@
 		
 		void   InputToResult(int enum_type,int step,double time);
-		void   MigrateGroundingLine(double* sheet_ungrounding);
+		void   MigrateGroundingLine(double* old_floating_ice,double* sheet_ungrounding);
 		void   PotentialSheetUngrounding(Vec potential_sheet_ungrounding);
-		void   ShelfSync();
 		void   RequestedOutput(int output_enum,int step,double time);
 		void   ListResultsEnums(int** results_enums,int* num_results);
Index: /issm/trunk/src/c/objects/Elements/Tria.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 10376)
+++ /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 10377)
@@ -1923,14 +1923,16 @@
 }/*}}}*/
 /*FUNCTION Tria::MigrateGroundingLine{{{1*/
-void  Tria::MigrateGroundingLine(double* sheet_ungrounding){
+void  Tria::MigrateGroundingLine(double* old_floating_ice,double* sheet_ungrounding){
 
 	int     i,migration_style,unground;
 	bool    elementonshelf = false;
-	double  bed_hydro;
+	double  bed_hydro,yts,gl_melting_rate;
 	double  rho_water,rho_ice,density;
+	double  melting[NUMVERTICES];
 	double  h[NUMVERTICES],s[NUMVERTICES],b[NUMVERTICES],ba[NUMVERTICES];
 
 	/*Recover info at the vertices: */
 	parameters->FindParam(&migration_style,GroundinglineMigrationEnum);
+	parameters->FindParam(&yts,ConstantsYtsEnum);
 	GetInputListOnVertices(&h[0],ThicknessEnum);
 	GetInputListOnVertices(&s[0],SurfaceEnum);
@@ -1944,8 +1946,10 @@
 	for(i=0;i<NUMVERTICES;i++){
 		/*Ice shelf: if bed below bathymetry, impose it at the bathymetry and update surface, elso do nothing */
-		if (nodes[i]->IsFloating()){
+		if(old_floating_ice[nodes[i]->Sid()]){
 			if(b[i]<=ba[i]){ 
 				b[i]=ba[i];
 				s[i]=b[i]+h[i];
+				nodes[i]->inputs->AddInput(new BoolInput(MaskVertexonfloatingiceEnum,false));
+				nodes[i]->inputs->AddInput(new BoolInput(MaskVertexongroundediceEnum,true));
 			}
 		}
@@ -1959,12 +1963,33 @@
 					s[i]=(1-density)*h[i];
 					b[i]=-density*h[i];
+					nodes[i]->inputs->AddInput(new BoolInput(MaskVertexonfloatingiceEnum,true));
+					nodes[i]->inputs->AddInput(new BoolInput(MaskVertexongroundediceEnum,false));
 				}
 				else if(migration_style==SoftMigrationEnum && sheet_ungrounding[nodes[i]->Sid()]){
 					s[i]=(1-density)*h[i];
 					b[i]=-density*h[i];
+					nodes[i]->inputs->AddInput(new BoolInput(MaskVertexonfloatingiceEnum,true));
+					nodes[i]->inputs->AddInput(new BoolInput(MaskVertexongroundediceEnum,false));
 				}
 			}
 		}
 	}
+
+	/*If at least one vertex is now floating, the element is now floating*/
+	for(i=0;i<NUMVERTICES;i++){
+		if(nodes[i]->IsFloating()){
+			elementonshelf=true;
+			break;
+		}
+	}
+	
+   /*Add basal melting rate if element just ungrounded*/
+	if(!this->IsFloating() && elementonshelf==true){
+		for(i=0;i<NUMVERTICES;i++)melting[i]=gl_melting_rate/yts;
+		this->inputs->AddInput(new TriaVertexInput(BasalforcingsMeltingRateEnum,&melting[0]));
+	} 
+
+	/*Update inputs*/
+   this->inputs->AddInput(new BoolInput(MaskElementonfloatingiceEnum,elementonshelf));
 
 	/*Update inputs*/    
@@ -2108,57 +2133,4 @@
 	else this->nodes=NULL;
 
-}
-/*}}}*/
-/*FUNCTION Tria::ShelfSync{{{1*/
-void  Tria::ShelfSync(void){
-
-	int     i;
-	bool    elementonshelf = false;
-	double  bed_hydro,gl_melting_rate;
-	double  yts,rho_water,rho_ice,density;
-	double  melting[NUMVERTICES];
-	double  h[NUMVERTICES],s[NUMVERTICES],b[NUMVERTICES],ba[NUMVERTICES];
-
-	/*recover parameters: */
-	parameters->FindParam(&yts,ConstantsYtsEnum);
-	parameters->FindParam(&gl_melting_rate,GroundinglineMeltingRateEnum);
-	rho_water=matpar->GetRhoWater();
-	rho_ice=matpar->GetRhoIce();
-	density=rho_ice/rho_water;
-
-	/*Recover info at the vertices: */
-	GetInputListOnVertices(&h[0],ThicknessEnum);
-	GetInputListOnVertices(&s[0],SurfaceEnum);
-	GetInputListOnVertices(&b[0],BedEnum);
-	GetInputListOnVertices(&ba[0],BathymetryEnum);
-
-	/*go through vertices, and update inputs, considering them to be TriaVertex type: */
-	for(i=0;i<NUMVERTICES;i++){
-		if(b[i]==ba[i]){
-			nodes[i]->inputs->AddInput(new BoolInput(MaskVertexonfloatingiceEnum,false));
-			nodes[i]->inputs->AddInput(new BoolInput(MaskVertexongroundediceEnum,true));
-		}
-		else{
-			nodes[i]->inputs->AddInput(new BoolInput(MaskVertexonfloatingiceEnum,true));
-			nodes[i]->inputs->AddInput(new BoolInput(MaskVertexongroundediceEnum,false));
-		}
-	}
-
-	/*If at least one vertex is now floating, the element is an iceshelf*/
-	for(i=0;i<NUMVERTICES;i++){
-		if(nodes[i]->IsFloating()){
-			elementonshelf=true;
-			break;
-		}
-	}
-	
-   /*Add basal melting rate if element just ungrounded*/
-	if(!this->IsFloating() && elementonshelf==true){
-		for(i=0;i<NUMVERTICES;i++)melting[i]=gl_melting_rate/yts;
-		this->inputs->AddInput(new TriaVertexInput(BasalforcingsMeltingRateEnum,&melting[0]));
-	} 
-
-	/*Update inputs*/
-   this->inputs->AddInput(new BoolInput(MaskElementonfloatingiceEnum,elementonshelf));
 }
 /*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Tria.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.h	(revision 10376)
+++ /issm/trunk/src/c/objects/Elements/Tria.h	(revision 10377)
@@ -102,6 +102,5 @@
 		void   DeleteResults(void);
 		void   MaterialUpdateFromTemperature(void){_error_("not implemented yet");};
-		void   MigrateGroundingLine(double* sheet_ungrounding);
-		void   ShelfSync();
+		void   MigrateGroundingLine(double* oldfloating,double* sheet_ungrounding);
 		void   PotentialSheetUngrounding(Vec potential_sheet_ungrounding);
 		void   RequestedOutput(int output_enum,int step,double time);
