Index: issm/trunk/src/c/objects/Elements/Element.h
===================================================================
--- issm/trunk/src/c/objects/Elements/Element.h	(revision 7318)
+++ issm/trunk/src/c/objects/Elements/Element.h	(revision 7319)
@@ -83,4 +83,6 @@
 		virtual int*   GetHorizontalNeighboorSids(void)=0;
 		virtual double TimeAdapt()=0;
+		virtual void   AgressiveMigration()=0;
+		virtual void   AgressiveShelfSync()=0;
 		virtual void   MigrateGroundingLine()=0;
 		virtual int    UpdateShelfStatus(Vec new_shelf_nodes)=0;
Index: issm/trunk/src/c/objects/Elements/Penta.cpp
===================================================================
--- issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 7318)
+++ issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 7319)
@@ -302,4 +302,14 @@
 void  Penta::AverageOntoPartition(Vec partition_contributions,Vec partition_areas,double* vertex_response,double* qmu_part){
 	_error_("Not supported yet!");
+}
+/*}}}*/
+/*FUNCTION Penta::AgressiveMigration{{{1*/
+void  Penta::AgressiveMigration(void){
+	_error_("not supported yet!");
+}
+/*}}}*/
+/*FUNCTION Penta::AgressiveShelfSync{{{1*/
+void  Penta::AgressiveShelfSync(void){
+	_error_("not supported yet!");
 }
 /*}}}*/
Index: issm/trunk/src/c/objects/Elements/Penta.h
===================================================================
--- issm/trunk/src/c/objects/Elements/Penta.h	(revision 7318)
+++ issm/trunk/src/c/objects/Elements/Penta.h	(revision 7319)
@@ -109,4 +109,6 @@
 		void   MaxVy(double* pmaxvy, bool process_units);
 		void   MaxVz(double* pmaxvz, bool process_units);
+		void   AgressiveMigration();
+		void   AgressiveShelfSync();
 		void   MigrateGroundingLine();
 		void   MinVel(double* pminvel, bool process_units);
Index: issm/trunk/src/c/objects/Elements/Tria.cpp
===================================================================
--- issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 7318)
+++ issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 7319)
@@ -276,4 +276,115 @@
 
 /*Other*/
+/*FUNCTION Tria::AgressiveMigration{{{1*/
+void  Tria::AgressiveMigration(void){
+
+
+	double *values         = NULL;
+	double  h[3],s[3],b[3],ba[3];
+	double  bed_hydro;
+	double  rho_water,rho_ice,density;
+	int     i;
+	bool    elementonshelf = false;
+
+	/*Recover info at the vertices: */
+	Input* surface_input =inputs->GetInput(SurfaceEnum); _assert_(surface_input);
+	Input* bed_input     =inputs->GetInput(BedEnum);     _assert_(bed_input);
+	if((surface_input->Enum()!=TriaVertexInputEnum) | (bed_input->Enum()!=TriaVertexInputEnum))_error_(" not supported yet for bed and surface interpolations not P1!");
+
+	GetParameterListOnVertices(&h[0],ThicknessEnum);
+	GetParameterListOnVertices(&s[0],SurfaceEnum);
+	GetParameterListOnVertices(&b[0],BedEnum);
+	GetParameterListOnVertices(&ba[0],BathymetryEnum);
+
+	/*material parameters: */
+	rho_water=matpar->GetRhoWater();
+	rho_ice=matpar->GetRhoIce();
+	density=rho_ice/rho_water;
+
+	/*go through vertices, and update inputs, considering them to be TriaVertex type: */
+	for(i=0;i<3;i++){
+		if (nodes[i]->IsOnShelf()){
+			/*This node is on the shelf. See if its bed is going under the bathymetry: */
+			if(b[i]<=ba[i]){ //<= because Neff being 0 when b=ba, drag will be 0 anyway.
+				/*The ice shelf is getting grounded, the thickness is the same, so just update the bed to stick to the bathymetry and elevate the surface accordingly: */
+				b[i]=ba[i];
+				s[i]=b[i]+h[i];
+			}
+			else{
+				/*do nothing, we are still floating.*/
+			}
+		}
+		else{
+			/*This node is on the sheet, near the grounding line. See if wants to unground. To 
+			 * do so, we compute the hydrostatic bed, and if it is > bathymetry, then we unground: */
+			bed_hydro=-density*h[i];
+			if (bed_hydro>ba[i]){
+				/*We are now floating, bed and surface are determined from hydrostatic equilibrium: */
+				s[i]=(1-density)*h[i];
+				b[i]=-density*h[i];
+			}
+			else{
+				/*do nothing, we are still grounded.*/
+			}
+		}
+	}
+
+	/*Surface and bed are updated. Update inputs:*/
+	surface_input->GetValuesPtr(&values,NULL); for(i=0;i<3;i++)values[i]=s[i];
+	bed_input->GetValuesPtr(&values,NULL);     for(i=0;i<3;i++)values[i]=b[i];
+
+	}
+/*}}}*/
+/*FUNCTION Tria::AgressiveShelfSync{{{1*/
+void  Tria::AgressiveShelfSync(void){
+
+
+	double *values         = NULL;
+	double  h[3],s[3],b[3],ba[3];
+	double  bed_hydro;
+	double  rho_water,rho_ice,density;
+	int     i;
+	bool    elementonshelf = false;
+
+	/*Recover info at the vertices: */
+	Input* surface_input =inputs->GetInput(SurfaceEnum); _assert_(surface_input);
+	Input* bed_input     =inputs->GetInput(BedEnum);     _assert_(bed_input);
+	if((surface_input->Enum()!=TriaVertexInputEnum) | (bed_input->Enum()!=TriaVertexInputEnum))_error_(" not supported yet for bed and surface interpolations not P1!");
+
+	GetParameterListOnVertices(&h[0],ThicknessEnum);
+	GetParameterListOnVertices(&s[0],SurfaceEnum);
+	GetParameterListOnVertices(&b[0],BedEnum);
+	GetParameterListOnVertices(&ba[0],BathymetryEnum);
+
+	/*material parameters: */
+	rho_water=matpar->GetRhoWater();
+	rho_ice=matpar->GetRhoIce();
+	density=rho_ice/rho_water;
+
+	/*go through vertices, and update inputs, considering them to be TriaVertex type: */
+	for(i=0;i<3;i++){
+		if(b[i]==ba[i]){
+				
+			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceShelfEnum,false));
+			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceSheetEnum,true));
+		}
+		else{
+			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceShelfEnum,true));
+			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceSheetEnum,false));
+
+		}
+	}
+
+	/*Now, update  shelf status of element. An element can only be on shelf if all its nodes are on shelf: */
+	elementonshelf=false;
+	for(i=0;i<3;i++){
+		if(nodes[i]->IsOnShelf()){
+			elementonshelf=true;
+			break;
+		}
+	}
+    this->inputs->AddInput(new BoolInput(ElementOnIceShelfEnum,elementonshelf));
+}
+/*}}}*/
 /*FUNCTION Tria::AverageOntoPartition {{{1*/
 void  Tria::AverageOntoPartition(Vec partition_contributions,Vec partition_areas,double* vertex_response,double* qmu_part){
@@ -3599,5 +3710,5 @@
 		this->inputs->AddInput(new TriaVertexInput(BedEnum,nodeinputs));
 	}
-	if(iomodel->gl_migration){
+	if(iomodel->gl_migration!=NoneEnum){
 		for(i=0;i<3;i++)nodeinputs[i]=iomodel->bathymetry[tria_vertex_ids[i]-1];
 		this->inputs->AddInput(new TriaVertexInput(BathymetryEnum,nodeinputs));
@@ -4422,5 +4533,8 @@
 	GetParameterListOnVertices(&b[0],BedEnum);
 	GetParameterListOnVertices(&ba[0],BathymetryEnum);
-	for(i=0;i<3;i++)isonshelf[i]=nodes[i]->IsOnShelf();
+	for(i=0;i<3;i++){
+		isonshelf[i]=nodes[i]->IsOnShelf();
+		if((nodes[i]->Sid()+1)==36)printf("MigrateGroundingLine: El %i Node %i shelf status %i\n",this->Id(),nodes[i]->Sid()+1,isonshelf[i]);
+	}
 
 	/*material parameters: */
@@ -4437,8 +4551,9 @@
 				b[i]=ba[i];
 				s[i]=b[i]+h[i];
-				//printf("Node id %i is starting to ground\n",nodes[i]->Id());
+				if((nodes[i]->Sid()+1)==36)printf("MigrateGroundingLine: El %i Node %i grounding %g %g %g\n",this->Id(),nodes[i]->Sid()+1,b[i],ba[i],s[i]);
 			}
 			else{
 				/*do nothing, we are still floating.*/
+				if((nodes[i]->Sid()+1)==36)printf("MigrateGroundingLine: El %i Node %i still floating %g %g %g\n",this->Id(),nodes[i]->Sid()+1,b[i],ba[i],s[i]);
 			}
 		}
@@ -4451,8 +4566,10 @@
 				s[i]=(1-density)*h[i];
 				b[i]=-density*h[i];
-				//printf("Node id %i is starting to float\n",nodes[i]->Id());
+				printf("%i\n",nodes[i]->Sid()+1);
+				if((nodes[i]->Sid()+1)==36)printf("MigrateGroundingLine: El %i Node %i floating %g %g %g\n",this->Id(),nodes[i]->Sid()+1,b[i],ba[i],s[i]);
 			}
 			else{
 				/*do nothing, we are still grounded.*/
+				if((nodes[i]->Sid()+1)==36)printf("MigrateGroundingLine: El %i Node %i still grounded %g %g %g\n",this->Id(),nodes[i]->Sid()+1,b[i],ba[i],s[i]);
 			}
 		}
@@ -4462,5 +4579,9 @@
 	surface_input->GetValuesPtr(&values,NULL); for(i=0;i<3;i++)values[i]=s[i];
 	bed_input->GetValuesPtr(&values,NULL);     for(i=0;i<3;i++)values[i]=b[i];
-
+	
+	for(i=0;i<3;i++){
+		isonshelf[i]=nodes[i]->IsOnShelf();
+		if((nodes[i]->Sid()+1)==36)printf("MigrateGroundingLine: El %i Node %i second shelf status %i\n",this->Id(),nodes[i]->Sid()+1,isonshelf[i]);
+	}
 }
 /*}}}*/
@@ -5344,5 +5465,5 @@
 	bool    elementonshelf = false;
 	int     flipped=0;
-	bool    shelfstatus[3];
+	int     shelfstatus[3];
 
 
@@ -5364,5 +5485,6 @@
 	/*Initialize current status of nodes: */
 	for(i=0;i<3;i++){
-		shelfstatus[i]=nodes[i]->inputs->GetInput(NodeOnIceShelfEnum);
+		shelfstatus[i]=nodes[i]->IsOnShelf();
+		if((nodes[i]->Sid()+1)==36) printf("UpdateShelfStatus: El %i Node %i shelf status %i\n",this->Id(),nodes[i]->Sid()+1,shelfstatus[i]);
 	}
 	
@@ -5370,9 +5492,11 @@
 	flipped=0;
 	for(i=0;i<3;i++){
-		if(b[i]<=ba[i]){
+		if(b[i]<=ba[i]){ //the = will lead to oscillations.
 			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceShelfEnum,false));
 			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceSheetEnum,true));
-			if(shelfstatus[i])flipped++;
-			//printf("node %i flipping to sheet\n",nodes[i]->Sid());
+			if(shelfstatus[i]){
+				flipped++;
+				if((nodes[i]->Sid()+1)==36)printf("UpdateShelfStatus: El %i Node %i grounding %g %g %g\n",this->Id(),nodes[i]->Sid()+1,b[i],ba[i],s[i]);
+			}
 			VecSetValue(new_shelf_nodes,nodes[i]->Sid(),0,INSERT_VALUES);
 		}
@@ -5380,6 +5504,8 @@
 			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceShelfEnum,true));
 			nodes[i]->inputs->AddInput(new BoolInput(NodeOnIceSheetEnum,false));
-			if(!shelfstatus[i])flipped++;
-			//printf("node %i flipping to shelf\n",nodes[i]->Sid());
+			if(!shelfstatus[i]){
+				flipped++;
+				if((nodes[i]->Sid()+1)==36)printf("UpdateShelfStatus: El %i Node %i floating %g %g %g\n",this->Id(),nodes[i]->Sid()+1,b[i],ba[i],s[i]);
+			}
 			VecSetValue(new_shelf_nodes,nodes[i]->Sid(),1,INSERT_VALUES);
 		}
@@ -5405,4 +5531,13 @@
 	bool flag;
 	int  i;
+	double  h[3];
+	double  s[3];
+	double  b[3];
+	double  ba[3];
+
+	GetParameterListOnVertices(&h[0],ThicknessEnum);
+	GetParameterListOnVertices(&s[0],SurfaceEnum);
+	GetParameterListOnVertices(&b[0],BedEnum);
+	GetParameterListOnVertices(&ba[0],BathymetryEnum);
 
 	for(i=0;i<3;i++){
Index: issm/trunk/src/c/objects/Elements/Tria.h
===================================================================
--- issm/trunk/src/c/objects/Elements/Tria.h	(revision 7318)
+++ issm/trunk/src/c/objects/Elements/Tria.h	(revision 7319)
@@ -113,4 +113,6 @@
 		void   MaxVy(double* pmaxvy, bool process_units);
 		void   MaxVz(double* pmaxvz, bool process_units);
+		void   AgressiveMigration();
+		void   AgressiveShelfSync();
 		void   MigrateGroundingLine();
 		void   MinVel(double* pminvel, bool process_units);
