Index: /issm/trunk-jpl/src/c/classes/Elements/Tria.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Tria.cpp	(revision 15213)
+++ /issm/trunk-jpl/src/c/classes/Elements/Tria.cpp	(revision 15214)
@@ -4703,5 +4703,5 @@
 
 		/*Compute SurfaceLogVelMisfit:
-		 *                 [        vel + eps     ] 2
+		 *        4         [        vel + eps     ] 2
 		 * J = 4 \bar{v}^2 | log ( -----------  ) |  
 		 *                 [       vel   + eps    ]
@@ -6178,5 +6178,5 @@
 		water_input->GetInputValue(&water_load,gauss);
 		transfer_input->GetInputValue(&transfer,gauss);
-		scalar = Jdet*gauss->weight*(water_load-transfer);
+		scalar = Jdet*gauss->weight*(water_load+transfer);
 		if(reCast<bool,IssmDouble>(dt)) scalar = scalar*dt;
 		for(int i=0;i<numdof;i++) pe->values[i]+=scalar*basis[i];
@@ -6236,5 +6236,5 @@
 		/*Loading term*/
 		transfer_input->GetInputValue(&transfer,gauss);
-		scalar = Jdet*gauss->weight*transfer;
+		scalar = Jdet*gauss->weight*(-transfer);
 		if(reCast<bool,IssmDouble>(dt)) scalar = scalar*dt;
 		for(int i=0;i<numdof;i++) pe->values[i]+=scalar*basis[i];
@@ -6418,10 +6418,13 @@
 	this->inputs->GetInputValue(&converged,ConvergedEnum);
 
+	/*Get inputs*/
+	if(isefficientlayer){
+		GetInputListOnVertices(&activeEpl[0],HydrologydcMaskEplactiveEnum);
+	}
 	if(converged){
 		this->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
 		this->parameters->FindParam(&kmax,HydrologySedimentKmaxEnum);
 		this->parameters->FindParam(&penalty_factor,HydrologydcPenaltyFactorEnum);
-
-		if(isefficientlayer)GetInputListOnVertices(&activeEpl[0],HydrologydcMaskEplactiveEnum);
+		
 		
 		kappa=kmax*pow(10.,penalty_factor);
@@ -6441,9 +6444,23 @@
 		}
 	}
+	else{
+		for(int i=0;i<NUMVERTICES;i++){	
+			if(isefficientlayer){
+				if(activeEpl[i]==1.0)activate[i]=1.0;
+			}				
+		}
+	}
+
 	/*Add input to the element: */
-	if(isefficientlayer) this->inputs->AddInput(new TriaP1Input(HydrologydcMaskEplactiveEnum,activate));
+	if(isefficientlayer) this->inputs->AddInput(new TriaP1Input(HydrologydcMaskEplactiveEnum,&activate[0]));
 	this->inputs->AddInput(new TriaP1Input(SedimentHeadEnum,values));
 	this->inputs->AddInput(new TriaP1Input(SedimentHeadResidualEnum,residual));
 
+	/*		if(id==1717){
+			printf("6 \n");
+			Input* EplMask=inputs->GetInput(HydrologydcMaskEplactiveEnum);
+			EplMask->Echo();
+		}
+	*/
 	/*Free ressources:*/
 	xDelete<int>(doflist);
@@ -6506,5 +6523,4 @@
 				_error_("no case higher than 3 for SedimentlimitFlag");
 		}
-
 		/*Assign output pointer*/
 		*ph_max=h_max;
@@ -6520,5 +6536,5 @@
 	int        transfermethod;
 	IssmDouble sed_trans,sed_thick;
-	IssmDouble leakage;
+	IssmDouble leakage,h_max;
 	IssmDouble activeEpl[numdof];
 	IssmDouble wh_trans[numdof]={0.0};
@@ -6534,5 +6550,5 @@
 		/*Also get the flag to the transfer method*/
 		this->parameters->FindParam(&transfermethod,HydrologydcTransferFlagEnum);
-		
+
 		/*Switch between the different transfer methods cases*/
 		switch(transfermethod){
@@ -6552,15 +6568,22 @@
 			
 			for(int i=0;i<numdof;i++){
-			
-				if(activeEpl[i]==0.0)break;
-				
+				if(activeEpl[i]==0.0)continue;
+		
 				if(sed_head[i]>epl_head[i]){
 					storing[i]=matpar->GetSedimentStoring();
-					wh_trans[i]=sed_trans*storing[i]*(sed_head[i]-epl_head[i])/(leakage*sed_thick);
+					wh_trans[i]=sed_trans*storing[i]*(epl_head[i]-sed_head[i])/(leakage*sed_thick);
 				}
 				else{
+					this->GetHydrologyDCInefficientHmax(&h_max,nodes[i]);
 					storing[i]=matpar->GetEplStoring();
-					wh_trans[i]=sed_trans*storing[i]*(sed_head[i]-epl_head[i])/(leakage*sed_thick);
+					wh_trans[i]=sed_trans*storing[i]*(epl_head[i]-sed_head[i])/(leakage*sed_thick);
+					if(sed_head[i]>h_max){
+						wh_trans[i]=0.0;
+					}
+					if((sed_head[i]+wh_trans[i])>h_max){
+						wh_trans[i]=h_max-sed_head[i];
+					}
 				}
+				transfer->SetValue(doflist[i],wh_trans[i],INS_VAL);
 			}
 			break;
@@ -6570,5 +6593,5 @@
 	}
 	/*Assign output pointer*/
-	transfer->SetValues(numdof,doflist,&wh_trans[0],ADD_VAL);
+	/*transfer->SetValues(numdof,doflist,&wh_trans[0],INS_VAL);*/
 }
 
Index: /issm/trunk-jpl/src/c/solutionsequences/solutionsequence_hydro_nonlinear.cpp
===================================================================
--- /issm/trunk-jpl/src/c/solutionsequences/solutionsequence_hydro_nonlinear.cpp	(revision 15213)
+++ /issm/trunk-jpl/src/c/solutionsequences/solutionsequence_hydro_nonlinear.cpp	(revision 15214)
@@ -73,8 +73,9 @@
 		femmodel->UpdateConstraintsx();
 		femmodel->parameters->SetParam(HydrologySedimentEnum,HydrologyLayerEnum);
-		femmodel->HydrologyTransferx();
-
+		/*		femmodel->HydrologyTransferx();
+		 */
 		/*Iteration on the sediment layer*/
 		for(;;){
+			femmodel->HydrologyTransferx();
 			femmodel->SystemMatricesx(&Kff, &Kfs, &pf,&df, &sediment_kmax);
 			CreateNodalConstraintsx(&ys,femmodel->nodes,HydrologyDCInefficientAnalysisEnum);
@@ -117,4 +118,5 @@
 		/*Iteration on the EPL layer*/
 		for(;;){
+			femmodel->HydrologyTransferx();
 			femmodel->SystemMatricesx(&Kff, &Kfs, &pf,&df,NULL);
 			CreateNodalConstraintsx(&ys,femmodel->nodes,HydrologyDCEfficientAnalysisEnum);
