Index: issm/trunk-jpl/src/c/classes/AdaptiveMeshRefinement.cpp
===================================================================
--- issm/trunk-jpl/src/c/classes/AdaptiveMeshRefinement.cpp	(revision 22241)
+++ issm/trunk-jpl/src/c/classes/AdaptiveMeshRefinement.cpp	(revision 22276)
@@ -32,5 +32,4 @@
 	this->refinement_type				= cp.refinement_type;
 	this->level_max						= cp.level_max;
-	this->radius_level_max				= cp.radius_level_max;
 	this->gradation						= cp.gradation;
 	this->lag								= cp.lag;
@@ -39,6 +38,6 @@
 	this->thicknesserror_threshold	= cp.thicknesserror_threshold;
 	this->deviatoricerror_threshold	= cp.deviatoricerror_threshold;
-	this->max_deviatoricerror			= cp.max_deviatoricerror;
-	this->max_thicknesserror			= cp.max_thicknesserror;
+	this->deviatoricerror_maximum		= cp.deviatoricerror_maximum;
+	this->thicknesserror_maximum		= cp.thicknesserror_maximum;
 	this->sid2index.clear();
 	this->sid2index.resize(cp.sid2index.size());
@@ -66,5 +65,4 @@
 	this->refinement_type				= -1;
 	this->level_max						= -1;
-	this->radius_level_max				= -1;
 	this->gradation						= -1;
 	this->lag								= -1;
@@ -73,6 +71,6 @@
 	this->thicknesserror_threshold	= -1;
 	this->deviatoricerror_threshold	= -1;
-	this->max_deviatoricerror			= -1;
-	this->max_thicknesserror			= -1;
+	this->deviatoricerror_maximum		= -1;
+	this->thicknesserror_maximum		= -1;
 	this->sid2index.clear();
 	this->index2sid.clear();
@@ -87,5 +85,4 @@
 	this->refinement_type				= -1;
 	this->level_max						= -1;
-	this->radius_level_max				= -1;
 	this->gradation						= -1;
 	this->lag								= -1;
@@ -94,6 +91,6 @@
 	this->thicknesserror_threshold	= -1;
 	this->deviatoricerror_threshold	= -1;
-	this->max_deviatoricerror			= -1;
-	this->max_thicknesserror			= -1;
+	this->deviatoricerror_maximum		= -1;
+	this->thicknesserror_maximum		= -1;
 	this->sid2index.clear();
 	this->index2sid.clear();
@@ -139,8 +136,8 @@
 	int numberofcriteria				=-1;
 	int nconformelements				= this->sid2index.size();
-	double gl_radius_h				=-1;
-	double gl_radius_hmax			= std::max(this->radius_level_max,this->groundingline_distance);
-	double if_radius_h				=-1;
-	double if_radius_hmax			= std::max(this->radius_level_max,this->icefront_distance);
+	double gl_distance_h				=-1;
+	double gl_distance_hmax			= this->groundingline_distance;
+	double if_distance_h				=-1;
+	double if_distance_hmax			= this->icefront_distance;
 	double gl_groupdistance			=-1;
 	double if_groupdistance			=-1;
@@ -163,9 +160,9 @@
 
 	/*Calculate the maximum of the estimators, if requested{{{*/
-	if(this->deviatoricerror_threshold>0 && this->max_deviatoricerror<0){ 
-		for(int i=0;i<nconformelements;i++) this->max_deviatoricerror=max(this->max_deviatoricerror,deviatoricerror[i]);
-	}
-	if(this->thicknesserror_threshold>0 && this->max_thicknesserror<0){
-		for(int i=0;i<nconformelements;i++) this->max_thicknesserror=max(this->max_thicknesserror,thicknesserror[i]);
+	if(this->deviatoricerror_threshold>0 && this->deviatoricerror_maximum<DBL_EPSILON){ 
+		for(int i=0;i<nconformelements;i++) this->deviatoricerror_maximum=max(this->deviatoricerror_maximum,deviatoricerror[i]);
+	}
+	if(this->thicknesserror_threshold>0 && this->thicknesserror_maximum<DBL_EPSILON){
+		for(int i=0;i<nconformelements;i++) this->thicknesserror_maximum=max(this->thicknesserror_maximum,thicknesserror[i]);
 	}
 	/*}}}*/
@@ -181,8 +178,8 @@
 		gmesh->Element(this->specialelementsindex[i])->Father()->GetHigherSubElements(sons);
 		/*Limits*/
-		gl_radius_h = gl_radius_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(this->specialelementsindex[i])->Level());
-		if_radius_h = if_radius_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(this->specialelementsindex[i])->Level());
-		d_maxerror	= this->deviatoricerror_threshold*this->max_deviatoricerror;
-		t_maxerror	= this->thicknesserror_threshold*this->max_thicknesserror;
+		gl_distance_h	= gl_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(this->specialelementsindex[i])->Level());
+		if_distance_h	= if_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(this->specialelementsindex[i])->Level());
+		d_maxerror		= this->deviatoricerror_threshold*this->deviatoricerror_maximum;
+		t_maxerror		= this->thicknesserror_threshold*this->thicknesserror_maximum;
 		/*Calculate the distance and error of the group (sons)*/
 		gl_groupdistance=INFINITY;if_groupdistance=INFINITY;deviatoric_grouperror=0;thickness_grouperror=0;
@@ -196,8 +193,8 @@
 		}	
 		criteria=0;
-		if(this->groundingline_distance>0		&& gl_groupdistance<gl_radius_h)			criteria++;
-		if(this->icefront_distance>0				&& if_groupdistance<if_radius_h)			criteria++;
-		if(this->deviatoricerror_threshold>0	&& deviatoric_grouperror>d_maxerror)	criteria++;
-		if(this->thicknesserror_threshold>0		&& thickness_grouperror>t_maxerror)		criteria++;
+		if(this->groundingline_distance>0		&& gl_groupdistance<gl_distance_h+DBL_EPSILON)		criteria++;
+		if(this->icefront_distance>0				&& if_groupdistance<if_distance_h+DBL_EPSILON)		criteria++;
+		if(this->deviatoricerror_threshold>0	&& deviatoric_grouperror>d_maxerror-DBL_EPSILON)	criteria++;
+		if(this->thicknesserror_threshold>0		&& thickness_grouperror>t_maxerror-DBL_EPSILON)		criteria++;
 		/*Finally, it keeps the father index if it must be refine*/
 		if(criteria) index.push_back(gmesh->Element(this->specialelementsindex[i])->FatherIndex());
@@ -230,8 +227,8 @@
 		if(!gmesh->Element(i)->Father()) _error_("father is NULL!\n");
 		/*Limits with lag*/
-		gl_radius_h = this->lag*gl_radius_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(i)->Level());
-		if_radius_h = this->lag*if_radius_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(i)->Level());
-		d_maxerror	= 0.05*this->max_deviatoricerror;//itapopo definir melhor
-		t_maxerror	= 0.05*this->max_thicknesserror;//itapopo definir melhor
+		gl_distance_h = this->lag*gl_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(i)->Level());
+		if_distance_h = this->lag*if_distance_hmax*std::pow(this->gradation,this->level_max-gmesh->Element(i)->Level());
+		d_maxerror	  = 0.01*this->deviatoricerror_maximum;//itapopo definir melhor 0.05
+		t_maxerror	  = 0.01*this->thicknesserror_maximum;//itapopo definir melhor 0.05
 		/*Get the sons of the father (sibilings)*/	
 		sons.clear();
@@ -252,8 +249,8 @@
 		/*Verify the criteria*/
 		criteria=0;
-		if(this->groundingline_distance>0		&& gl_groupdistance>gl_radius_h)			criteria++;
-		if(this->icefront_distance>0				&& if_groupdistance>if_radius_h)			criteria++;
-		if(this->deviatoricerror_threshold>0	&& deviatoric_grouperror<d_maxerror)	criteria++;
-		if(this->thicknesserror_threshold>0		&& thickness_grouperror<t_maxerror)		criteria++;
+		if(this->groundingline_distance>0		&& gl_groupdistance>gl_distance_h-DBL_EPSILON)		criteria++;
+		if(this->icefront_distance>0				&& if_groupdistance>if_distance_h-DBL_EPSILON)		criteria++;
+		if(this->deviatoricerror_threshold>0	&& deviatoric_grouperror<d_maxerror+DBL_EPSILON)	criteria++;
+		if(this->thicknesserror_threshold>0		&& thickness_grouperror<t_maxerror+DBL_EPSILON)		criteria++;
 		/*Now, if the group attends the criteria, unrefine it*/
 		if(criteria==numberofcriteria){ 
@@ -280,15 +277,15 @@
 		sid=this->index2sid[gmesh->Element(i)->Index()];
 		if(sid<0) continue;
-		/*Filter: set the region/radius for level h*/
-		gl_radius_h	= gl_radius_hmax*std::pow(this->gradation,this->level_max-(gmesh->Element(i)->Level()+1));//+1, current element level is <level_max
-		if_radius_h	= if_radius_hmax*std::pow(this->gradation,this->level_max-(gmesh->Element(i)->Level()+1));//+1, current element level is <level_max
-		d_maxerror	= this->deviatoricerror_threshold*this->max_deviatoricerror;
-		t_maxerror	= this->thicknesserror_threshold*this->max_thicknesserror;
+		/*Set the distance for level h*/
+		gl_distance_h	= gl_distance_hmax*std::pow(this->gradation,this->level_max-(gmesh->Element(i)->Level()+1));//+1: current element level is <level_max
+		if_distance_h	= if_distance_hmax*std::pow(this->gradation,this->level_max-(gmesh->Element(i)->Level()+1));//+1: current element level is <level_max
+		d_maxerror		= this->deviatoricerror_threshold*this->deviatoricerror_maximum;
+		t_maxerror		= this->thicknesserror_threshold*this->thicknesserror_maximum;
 		/*Verify distance and error of the element, if requested*/
 		criteria=0;
-		if(this->groundingline_distance>0		&& gl_distance[sid]<gl_radius_h)		criteria++; 
-		if(this->icefront_distance>0				&& if_distance[sid]<if_radius_h)		criteria++; 
-		if(this->deviatoricerror_threshold>0	&& deviatoricerror[sid]>d_maxerror)	criteria++; 
-		if(this->thicknesserror_threshold>0		&& thicknesserror[sid]>t_maxerror)	criteria++; 
+		if(this->groundingline_distance>0		&& gl_distance[sid]<gl_distance_h+DBL_EPSILON)	criteria++; 
+		if(this->icefront_distance>0				&& if_distance[sid]<if_distance_h+DBL_EPSILON)	criteria++; 
+		if(this->deviatoricerror_threshold>0	&& deviatoricerror[sid]>d_maxerror-DBL_EPSILON)	criteria++; 
+		if(this->thicknesserror_threshold>0		&& thicknesserror[sid]>t_maxerror-DBL_EPSILON)	criteria++; 
 		/*Now, if it attends any criterion, keep the element index to refine in next step*/
 		if(criteria)index.push_back(i);
