Index: /issm/trunk/src/c/modules/Gradjx/Gradjx.cpp
===================================================================
--- /issm/trunk/src/c/modules/Gradjx/Gradjx.cpp	(revision 4591)
+++ /issm/trunk/src/c/modules/Gradjx/Gradjx.cpp	(revision 4592)
@@ -12,11 +12,13 @@
 void Gradjx( Vec* pgradient, Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,int control_type){
 
-	int i;
-	int dim;
-	int numberofvertices;
-	Vec gradient=NULL;
+	int  i;
+	int  dim;
+	int  numberofvertices;
+	bool extrude;
+	Vec  gradient = NULL;
 	
 	/*retrieve some parameters: */
 	parameters->FindParam(&dim,DimEnum);
+	parameters->FindParam(&extrude,ExtrudeParamEnum);
 	numberofvertices=vertices->NumberOfVertices();
 
@@ -35,5 +37,5 @@
 
 	/*Extrude if needed: */
-	if(dim==3) VecExtrudex(gradient, elements,nodes, vertices, loads, materials, parameters,0);
+	if(dim==3 && extrude) VecExtrudex(gradient, elements,nodes, vertices, loads, materials, parameters,0);
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/InputExtrudex/InputExtrudex.cpp
===================================================================
--- /issm/trunk/src/c/modules/InputExtrudex/InputExtrudex.cpp	(revision 4591)
+++ /issm/trunk/src/c/modules/InputExtrudex/InputExtrudex.cpp	(revision 4592)
@@ -9,5 +9,5 @@
 #include "../../EnumDefinitions/EnumDefinitions.h"
 
-void InputExtrudex( Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,int enum_type){
+void InputExtrudex( Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,int enum_type,bool only_if_collapsed){
 
 	int i;
@@ -18,5 +18,5 @@
 		if (element->Enum()==PentaEnum){
 			Penta* penta=(Penta*)element;
-			penta->InputExtrude(enum_type);
+			penta->InputExtrude(enum_type,only_if_collapsed);
 		}
 	}
Index: /issm/trunk/src/c/modules/InputExtrudex/InputExtrudex.h
===================================================================
--- /issm/trunk/src/c/modules/InputExtrudex/InputExtrudex.h	(revision 4591)
+++ /issm/trunk/src/c/modules/InputExtrudex/InputExtrudex.h	(revision 4592)
@@ -9,5 +9,5 @@
 
 /* local prototypes: */
-void InputExtrudex( Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,int enum_type);
+void InputExtrudex( Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,int enum_type,bool only_if_collapsed=false);
 
 #endif  /* _INPUTEXTRUDEX_H */
Index: /issm/trunk/src/c/objects/Elements/Penta.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 4591)
+++ /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 4592)
@@ -4767,15 +4767,17 @@
 /*}}}*/
 /*FUNCTION Penta::InputExtrude {{{1*/
-void  Penta::InputExtrude(int enum_type){
-
-	bool onbed;
-	bool onsurface;
-
-	Penta* penta=NULL;
-	Input* original_input=NULL;
+void  Penta::InputExtrude(int enum_type,bool only_if_collapsed){
+
+	bool   onbed,onsurface,collapse;
+	Penta *penta          = NULL;
+	Input *original_input = NULL;
 
 	/*recover parameters: */
+	inputs->GetParameterValue(&collapse,CollapseEnum);
 	inputs->GetParameterValue(&onbed,ElementOnBedEnum);
 	inputs->GetParameterValue(&onsurface,ElementOnSurfaceEnum);
+
+	/*First: if only_if_collapsed, check wether this penta is collapsed*/
+	if (only_if_collapsed && !collapse) return;
 
 	/*Are we on the base, not on the surface?:*/
Index: /issm/trunk/src/c/objects/Elements/Penta.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.h	(revision 4591)
+++ /issm/trunk/src/c/objects/Elements/Penta.h	(revision 4592)
@@ -168,5 +168,5 @@
 		void	  GetStrainRateStokes(double* epsilon, double* velocity, double* xyz_list, double* gauss_coord);
 		Penta*  GetUpperElement(void);
-		void	  InputExtrude(int enum_type);
+		void	  InputExtrude(int enum_type,bool only_if_collapsed);
 		void    InputUpdateFromSolutionAdjointHoriz( double* solutiong);
 		void    InputUpdateFromSolutionAdjointStokes( double* solutiong);
Index: /issm/trunk/src/c/solvers/solver_diagnostic_nonlinear.cpp
===================================================================
--- /issm/trunk/src/c/solvers/solver_diagnostic_nonlinear.cpp	(revision 4591)
+++ /issm/trunk/src/c/solvers/solver_diagnostic_nonlinear.cpp	(revision 4592)
@@ -131,7 +131,7 @@
 	/*extrude if we are in 3D: */
 	if (dim==3){
-		if(verbose)_printf_("%s\n","extruding velocity and pressure in 3d...");
-		InputExtrudex( femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,VxEnum);
-		InputExtrudex( femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,VyEnum);
+		if(verbose)_printf_("%s\n","extruding velocity of collapsed elements...");
+		InputExtrudex( femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,VxEnum,true); //true means that the velocity is only extruded if collapsed
+		InputExtrudex( femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,VyEnum,true);
 	}
 
Index: /issm/trunk/src/m/solvers/solver_diagnostic_nonlinear.m
===================================================================
--- /issm/trunk/src/m/solvers/solver_diagnostic_nonlinear.m	(revision 4591)
+++ /issm/trunk/src/m/solvers/solver_diagnostic_nonlinear.m	(revision 4592)
@@ -85,6 +85,6 @@
 	if dim==3,
 		displaystring(femmodel.parameters.Verbose,'%s','   extruding horizontal velocity in 3d...');
-		femmodel.elements=InputExtrude( femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters,VxEnum);
-		femmodel.elements=InputExtrude( femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters,VyEnum);
+		femmodel.elements=InputExtrude( femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters,VxEnum,true);%true means only if collapsed
+		femmodel.elements=InputExtrude( femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters,VyEnum,true);
 	end
 			
Index: /issm/trunk/src/mex/InputExtrude/InputExtrude.cpp
===================================================================
--- /issm/trunk/src/mex/InputExtrude/InputExtrude.cpp	(revision 4591)
+++ /issm/trunk/src/mex/InputExtrude/InputExtrude.cpp	(revision 4592)
@@ -8,11 +8,12 @@
 
 	/*input datasets: */
-	Elements* elements=NULL;
-	Nodes* nodes=NULL;
-	Vertices* vertices=NULL;
-	Loads* loads=NULL;
-	Materials* materials=NULL;
-	Parameters* parameters=NULL;
-	int      NameEnum;
+	Elements   *elements   = NULL;
+	Nodes      *nodes      = NULL;
+	Vertices   *vertices   = NULL;
+	Loads      *loads      = NULL;
+	Materials  *materials  = NULL;
+	Parameters *parameters = NULL;
+	int         NameEnum;
+	bool        ifcollapsed=false;
 
 	/*Boot module: */
@@ -20,5 +21,9 @@
 
 	/*checks on arguments on the matlab side: */
-	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InputExtrudeUsage);
+	//CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InputExtrudeUsage); Cant' use it here, as we have variable inputs.
+	if((nlhs!=NLHS) || (nrhs!=7 && nrhs!=8)){
+		InputExtrudeUsage();
+		ISSMERROR(" usage. See above");
+	}
 
 	/*Input datasets: */
@@ -30,4 +35,7 @@
 	FetchParams(&parameters,PARAMETERS);
 	FetchData(&NameEnum,NAME);
+	if (nrhs==8){
+		FetchData(&ifcollapsed,IFCOLLAPSED);
+	}
 
 	/*configure: */
@@ -37,5 +45,8 @@
 
 	/*!Call core code: */
-	InputExtrudex(elements,nodes,vertices,loads,materials,parameters,NameEnum);
+	if (nrhs==7)
+	 InputExtrudex(elements,nodes,vertices,loads,materials,parameters,NameEnum);
+	else
+	 InputExtrudex(elements,nodes,vertices,loads,materials,parameters,NameEnum,ifcollapsed);
 
 	/*write output : */
@@ -59,4 +70,5 @@
 	_printf_("\n");
 	_printf_("   usage: [elements] = %s(elements, nodes, vertices, loads, materials, parameters, name_enum);\n",__FUNCT__);
+	_printf_("   usage: [elements] = %s(elements, nodes, vertices, loads, materials, parameters, name_enum,true);\n",__FUNCT__);
 	_printf_("\n");
 }
Index: /issm/trunk/src/mex/InputExtrude/InputExtrude.h
===================================================================
--- /issm/trunk/src/mex/InputExtrude/InputExtrude.h	(revision 4591)
+++ /issm/trunk/src/mex/InputExtrude/InputExtrude.h	(revision 4592)
@@ -24,4 +24,5 @@
 #define PARAMETERS (mxArray*)prhs[5]
 #define NAME (mxArray*)prhs[6]
+#define IFCOLLAPSED (mxArray*)prhs[7]
 
 /* serial output macros: */
@@ -32,5 +33,5 @@
 #define NLHS  1
 #undef NRHS
-#define NRHS  7
+#define NRHS  8
 
 #endif  /* _EXTRUDEINPUT_H */
