Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 1664)
+++ /issm/trunk/src/c/Makefile.am	(revision 1665)
@@ -258,4 +258,6 @@
 					./Reducevectorgtosx/Reducevectorgtosx.cpp\
 					./Reducevectorgtosx/Reducevectorgtosx.h\
+					./Reducevectorgtofx/Reducevectorgtofx.cpp\
+					./Reducevectorgtofx/Reducevectorgtofx.h\
 					./Reducematrixfromgtofx/Reducematrixfromgtofx.cpp\
 					./Reducematrixfromgtofx/Reducematrixfromgton.cpp\
@@ -543,4 +545,6 @@
 					./Reducevectorgtosx/Reducevectorgtosx.cpp\
 					./Reducevectorgtosx/Reducevectorgtosx.h\
+					./Reducevectorgtofx/Reducevectorgtofx.cpp\
+					./Reducevectorgtofx/Reducevectorgtofx.h\
 					./Reducematrixfromgtofx/Reducematrixfromgtofx.cpp\
 					./Reducematrixfromgtofx/Reducematrixfromgton.cpp\
Index: /issm/trunk/src/c/Reducevectorgtofx/Reducevectorgtofx.cpp
===================================================================
--- /issm/trunk/src/c/Reducevectorgtofx/Reducevectorgtofx.cpp	(revision 1665)
+++ /issm/trunk/src/c/Reducevectorgtofx/Reducevectorgtofx.cpp	(revision 1665)
@@ -0,0 +1,36 @@
+/*!\file Reducevectorgtofx
+ * \brief reduce petsc vector from g set to s set (free dofs), using the nodeset partitioning 
+ * vectors.
+ */
+
+#include "./Reducevectorgtofx.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "Reducevectorgtofx"
+
+void Reducevectorgtofx(Vec* puf, Vec ug, NodeSets* nodesets){
+
+	/*output: */
+	Vec uf=NULL;
+
+	/*intermediary: */
+	Vec un=NULL;
+
+	if(nodesets){
+
+
+		if (nodesets->GetNSize() && nodesets->GetFSize()){
+
+			VecPartition(&un,ug,nodesets->GetPV_N(),nodesets->GetNSize());
+		
+			VecPartition(&uf,un,nodesets->GetPV_F(),nodesets->GetFSize());
+		
+		}
+
+		/*Free ressources:*/
+		VecFree(&un);
+	}
+	
+	/*Assign output pointers:*/
+	*puf=uf;
+}
Index: /issm/trunk/src/c/Reducevectorgtofx/Reducevectorgtofx.h
===================================================================
--- /issm/trunk/src/c/Reducevectorgtofx/Reducevectorgtofx.h	(revision 1665)
+++ /issm/trunk/src/c/Reducevectorgtofx/Reducevectorgtofx.h	(revision 1665)
@@ -0,0 +1,15 @@
+/*!\file:  Reducevectorgtofx.h
+ * \brief reduce petsc vector from g set to f set (free dofs), using the nodeset partitioning 
+ * vectors.
+ */ 
+
+#ifndef _REDUCEVECTORGTOFX_H
+#define _REDUCEVECTORGTOFX_H
+
+#include "../objects/objects.h"
+
+/* local prototypes: */
+void	Reducevectorgtofx(Vec* puf, Vec ug, NodeSets* nodesets);
+
+#endif  /* _REDUCEVECTORGTOFX_H */
+
Index: /issm/trunk/src/c/issm.h
===================================================================
--- /issm/trunk/src/c/issm.h	(revision 1664)
+++ /issm/trunk/src/c/issm.h	(revision 1665)
@@ -32,4 +32,5 @@
 #include "./BuildNodeSetsx/BuildNodeSetsx.h"
 #include "./Reducevectorgtosx/Reducevectorgtosx.h"
+#include "./Reducevectorgtofx/Reducevectorgtofx.h"
 #include "./NormalizeConstraintsx/NormalizeConstraintsx.h"
 #include "./ConfigureObjectsx/ConfigureObjectsx.h"
Index: /issm/trunk/src/c/parallel/diagnostic_core_nonlinear.cpp
===================================================================
--- /issm/trunk/src/c/parallel/diagnostic_core_nonlinear.cpp	(revision 1664)
+++ /issm/trunk/src/c/parallel/diagnostic_core_nonlinear.cpp	(revision 1665)
@@ -66,10 +66,11 @@
 	loads=fem->loads->Copy();
 
-	/*Initialize ug and ug_old */
+	/*Initialize ug, uf, ug_old and uf_old */
 	if (numberofdofspernode>=3)dofs[2]=1;//only keep vz if running with more than 3 dofs per node
 	if (numberofdofspernode==4)dofs[3]=1;//only keep vz and presure if running with more than 3 dofs per node
 	ug=inputs->Get("velocity",&dofs[0],4);
-	VecDuplicate(ug,&old_ug);
-	VecCopy(ug,old_ug);
+	VecDuplicate(ug,&old_ug); VecCopy(ug,old_ug);
+	Reducevectorgtofx(&uf,ug,fem->nodesets);
+	VecDuplicate(uf,&old_uf); VecCopy(uf,old_uf);
 
 	count=1;
@@ -143,18 +144,13 @@
 
 		/*mechanical residue = norm(KUold-F)/norm(F)*/
-		if (count>1){
-			//compute KUoldF = KUold - F = K*Uold - F
-			VecDuplicate(uf,&KUold); MatMultPatch(Kff,old_uf,KUold);
-			VecDuplicate(KUold,&KUoldF);VecCopy(KUold,KUoldF); VecAYPX(KUoldF,-1.0,pf);
-			//compute norm(KUF), norm(F) and residue
-			VecNorm(KUoldF,NORM_2,&nKUoldF);
-			mechanical_residue=nKUoldF/nF;
-			//clean up
-			VecFree(&KUold);
-			VecFree(&KUoldF);
-		}
-		else{
-			mechanical_residue=nKUoldF/nF;
-		}
+		//compute KUoldF = KUold - F = K*Uold - F
+		VecDuplicate(uf,&KUold); MatMultPatch(Kff,old_uf,KUold);
+		VecDuplicate(KUold,&KUoldF);VecCopy(KUold,KUoldF); VecAYPX(KUoldF,-1.0,pf);
+		//compute norm(KUF), norm(F) and residue
+		VecNorm(KUoldF,NORM_2,&nKUoldF);
+		mechanical_residue=nKUoldF/nF;
+		//clean up
+		VecFree(&KUold);
+		VecFree(&KUoldF);
 		if (debug) _printf_("%-50s%g%s\n","   Convergence criterion: norm(KUold-F)/norm(F)",mechanical_residue*100," \%");
 
Index: /issm/trunk/src/m/solutions/cielo/diagnostic_core_nonlinear.m
===================================================================
--- /issm/trunk/src/m/solutions/cielo/diagnostic_core_nonlinear.m	(revision 1664)
+++ /issm/trunk/src/m/solutions/cielo/diagnostic_core_nonlinear.m	(revision 1665)
@@ -13,5 +13,5 @@
 
 	soln(count).u_g=get(inputs,'velocity',[1 1 (m.parameters.numberofdofspernode>=3) (m.parameters.numberofdofspernode>=3)]); %only keep vz if running with more than 3 dofs per node
-	soln(count).u_f=[];
+	soln(count).u_f= Reducevectorgtof(soln(count).u_g,m.nodesets);
 
 	displaystring(m.parameters.debug,'\n%s',['   starting direct shooting method']);
@@ -65,9 +65,5 @@
 
 		%Force equilibrium
-		if count>2,
-			mechanical_residue=norm(K_ff*soln(count-1).u_f-p_f,2)/norm(p_f,2);
-		else
-			mechanical_residue=NaN;
-		end
+		mechanical_residue=norm(K_ff*soln(count-1).u_f-p_f,2)/norm(p_f,2);
 		displaystring(m.parameters.debug,'%-53s%g%s','      convergence criterion: norm(KUold-F)/norm(F)',mechanical_residue*100,' %');
 
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 1664)
+++ /issm/trunk/src/mex/Makefile.am	(revision 1665)
@@ -38,4 +38,5 @@
 				Reducematrixfromgtof\
 				Reducevectorgtos\
+				Reducevectorgtof\
 				SetStructureField\
 				Solver\
@@ -180,4 +181,7 @@
 			  Reducevectorgtos/Reducevectorgtos.h
 
+Reducevectorgtof_SOURCES = Reducevectorgtof/Reducevectorgtof.cpp\
+									Reducevectorgtof/Reducevectorgtof.h
+
 SetStructureField_SOURCES = SetStructureField/SetStructureField.cpp\
 			  SetStructureField/SetStructureField.h
Index: /issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.cpp
===================================================================
--- /issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.cpp	(revision 1665)
+++ /issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.cpp	(revision 1665)
@@ -0,0 +1,49 @@
+/*\file Reducevectorgtof.c
+ *\brief: reduce g set vector to s set vector (set of single point constraints)
+ */
+
+#include "./Reducevectorgtof.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*diverse: */
+	int   noerr=1;
+
+	/*input datasets: */
+	Vec ug=NULL;
+	NodeSets* nodesets=NULL;
+
+	/* output datasets: */
+	Vec uf=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ReducevectorgtofUsage);
+
+	/*Input datasets: */
+	FetchData((void**)&ug,NULL,NULL,UG,"Vector",NULL);
+	FetchNodeSets(&nodesets,NODESETS);
+
+	/*!Reduce vector: */
+	Reducevectorgtofx(&uf,ug,nodesets);
+
+	/*write output datasets: */
+	WriteData(UF,uf,0,0,"Vector",NULL);
+
+	/*Free ressources: */
+	delete nodesets;
+	VecFree(&ug);
+	VecFree(&uf);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void ReducevectorgtofUsage(void)
+{
+	_printf_("\n");
+	_printf_("   usage: uf = %s(ug,nodesets);\n",__FUNCT__);
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.h
===================================================================
--- /issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.h	(revision 1665)
+++ /issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.h	(revision 1665)
@@ -0,0 +1,33 @@
+
+/*
+	Reducevectorgtof.h
+*/
+
+
+#ifndef _REDUCEVECTORGTOF_H
+#define _REDUCEVECTORGTOF_H
+
+/* local prototypes: */
+void ReducevectorgtofUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Reducevectorgtof"
+
+/* serial input macros: */
+#define UG (mxArray*)prhs[0]
+#define NODESETS (mxArray*)prhs[1]
+
+/* serial output macros: */
+#define UF (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  2
+
+
+#endif  /* _REDUCEVECTORGTOF_H */
+
