Index: /issm/trunk-jpl/src/c/analyses/DamageEvolutionAnalysis.cpp
===================================================================
--- /issm/trunk-jpl/src/c/analyses/DamageEvolutionAnalysis.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/analyses/DamageEvolutionAnalysis.cpp	(revision 18237)
@@ -69,9 +69,4 @@
 	iomodel->FetchDataToInput(elements,PressureEnum);
 
-	bool dakota_analysis;
-	iomodel->Constant(&dakota_analysis,QmuIsdakotaEnum);
-	if(dakota_analysis){
-		elements->InputDuplicate(DamageDEnum, QmuDamageDEnum);
-	}
 }/*}}}*/
 void DamageEvolutionAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
Index: /issm/trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp
===================================================================
--- /issm/trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp	(revision 18237)
@@ -78,11 +78,4 @@
 	InputUpdateFromConstantx(elements,0.,VyMeshEnum);
 	InputUpdateFromConstantx(elements,0.,VzMeshEnum);
-	if(dakota_analysis){
-		elements->InputDuplicate(TemperatureEnum,QmuTemperatureEnum);
-		elements->InputDuplicate(BasalforcingsGroundediceMeltingRateEnum,QmuMeltingEnum);
-		elements->InputDuplicate(VxMeshEnum,QmuVxMeshEnum);
-		elements->InputDuplicate(VxMeshEnum,QmuVyMeshEnum);
-		elements->InputDuplicate(VxMeshEnum,QmuVzMeshEnum);
-	}
 	if(islevelset){
 		iomodel->FetchDataToInput(elements,IceMaskNodeActivationEnum);
Index: /issm/trunk-jpl/src/c/analyses/MasstransportAnalysis.cpp
===================================================================
--- /issm/trunk-jpl/src/c/analyses/MasstransportAnalysis.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/analyses/MasstransportAnalysis.cpp	(revision 18237)
@@ -71,12 +71,4 @@
 	if(stabilization==3){
 		iomodel->FetchDataToInput(elements,MasstransportSpcthicknessEnum); //for DG, we need the spc in the element
-	}
-
-	if(dakota_analysis){
-		elements->InputDuplicate(BaseEnum,QmuBaseEnum);
-		elements->InputDuplicate(ThicknessEnum,QmuThicknessEnum);
-		elements->InputDuplicate(SurfaceEnum,QmuSurfaceEnum);
-		elements->InputDuplicate(MaskIceLevelsetEnum,QmuMaskIceLevelsetEnum);
-		if(isgroundingline) elements->InputDuplicate(MaskGroundediceLevelsetEnum,QmuMaskGroundediceLevelsetEnum);
 	}
 
Index: /issm/trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp
===================================================================
--- /issm/trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp	(revision 18237)
@@ -213,7 +213,5 @@
 	iomodel->FetchDataToInput(elements,MaterialsRheologyNEnum);
 	iomodel->FetchDataToInput(elements,VxEnum,0.);
-	if(dakota_analysis)elements->InputDuplicate(VxEnum,QmuVxEnum);
 	iomodel->FetchDataToInput(elements,VyEnum,0.);
-	if(dakota_analysis)elements->InputDuplicate(VyEnum,QmuVyEnum);
 	iomodel->FetchDataToInput(elements,LoadingforceXEnum);
 	iomodel->FetchDataToInput(elements,LoadingforceYEnum);
@@ -228,10 +226,8 @@
 		iomodel->FetchDataToInput(elements,LoadingforceZEnum);
 		iomodel->FetchDataToInput(elements,VzEnum,0.);
-		if(dakota_analysis)elements->InputDuplicate(VzEnum,QmuVzEnum);
 	}
 	if(isFS){
 		iomodel->FetchDataToInput(elements,PressureEnum,0.);
 		iomodel->FetchDataToInput(elements,BasalforcingsFloatingiceMeltingRateEnum,0.);
-		if(dakota_analysis)elements->InputDuplicate(PressureEnum,QmuPressureEnum);
 	}
 	if(islevelset){
Index: /issm/trunk-jpl/src/c/analyses/ThermalAnalysis.cpp
===================================================================
--- /issm/trunk-jpl/src/c/analyses/ThermalAnalysis.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/analyses/ThermalAnalysis.cpp	(revision 18237)
@@ -75,11 +75,4 @@
 	InputUpdateFromConstantx(elements,0.,VyMeshEnum);
 	InputUpdateFromConstantx(elements,0.,VzMeshEnum);
-	if(dakota_analysis){
-		elements->InputDuplicate(TemperatureEnum,QmuTemperatureEnum);
-		elements->InputDuplicate(BasalforcingsGroundediceMeltingRateEnum,QmuMeltingEnum);
-		elements->InputDuplicate(VxMeshEnum,QmuVxMeshEnum);
-		elements->InputDuplicate(VxMeshEnum,QmuVyMeshEnum);
-		elements->InputDuplicate(VxMeshEnum,QmuVzMeshEnum);
-	}
 	if(islevelset){
 		iomodel->FetchDataToInput(elements,IceMaskNodeActivationEnum);
Index: /issm/trunk-jpl/src/c/classes/Constraints/SpcDynamic.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Constraints/SpcDynamic.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Constraints/SpcDynamic.cpp	(revision 18237)
@@ -54,5 +54,5 @@
 }		
 /*}}}*/
-int    SpcDynamic::Id(void){ return sid; }/*{{{*/
+int SpcDynamic::Id(void){ return sid; }/*{{{*/
 /*}}}*/
 int SpcDynamic::ObjectEnum(void){/*{{{*/
@@ -63,5 +63,15 @@
 /*}}}*/
 Object* SpcDynamic::copy() {/*{{{*/
-	return new SpcDynamic(*this); 
+
+	SpcDynamic* spcdyn = new SpcDynamic(*this); 
+
+	spcdyn->sid=this->sid;
+	spcdyn->nodeid=this->nodeid;
+	spcdyn->dof=this->dof;
+	spcdyn->value=this->value;
+	spcdyn->analysis_type=this->analysis_type;
+	spcdyn->isset=this->isset;
+
+	return (Object*) spcdyn;
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Constraints/SpcStatic.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Constraints/SpcStatic.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Constraints/SpcStatic.cpp	(revision 18237)
@@ -57,5 +57,5 @@
 }		
 /*}}}*/
-int    SpcStatic::Id(void){ return sid; }/*{{{*/
+int SpcStatic::Id(void){ return sid; }/*{{{*/
 /*}}}*/
 int SpcStatic::ObjectEnum(void){/*{{{*/
@@ -66,5 +66,14 @@
 /*}}}*/
 Object* SpcStatic::copy() {/*{{{*/
-	return new SpcStatic(*this); 
+	
+	SpcStatic* spcstat = new SpcStatic(*this); 
+
+	spcstat->sid=this->sid;
+	spcstat->nodeid=this->nodeid;
+	spcstat->dof=this->dof;
+	spcstat->value=this->value;
+	spcstat->analysis_type=this->analysis_type;
+
+	return (Object*) spcstat;
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Contour.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Contour.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Contour.h	(revision 18237)
@@ -77,5 +77,8 @@
 		/*}}}*/
 		Object* copy() {/*{{{*/
-			return new Contour(*this); 
+
+			Contour* contour = new Contour(this->id,this->nods,this->x,this->y,this->closed);
+
+			return (Object*) contour;
 		}
 		/*}}}*/
Index: /issm/trunk-jpl/src/c/classes/DofIndexing.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/DofIndexing.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/DofIndexing.cpp	(revision 18237)
@@ -55,5 +55,10 @@
 		this->s_set=xNew<bool>(this->gsize);
 		this->svalues=xNew<IssmDouble>(this->gsize);
-		if(in->doftype)this->doftype=xNew<int>(this->gsize); 
+		if(in->doftype){
+			this->doftype=xNew<int>(this->gsize); 
+		}
+		else{
+			this->doftype=NULL;
+		}
 		this->gdoflist=xNew<int>(this->gsize); 
 	}
@@ -65,6 +70,6 @@
 		this->gdoflist = NULL;
 	}
-	if(this->fsize>0 && this->fsize!=UNDEF)this->fdoflist=xNew<int>(this->fsize); else this->fdoflist=NULL;
-	if(this->ssize>0 && this->ssize!=UNDEF)this->sdoflist=xNew<int>(this->ssize); else this->sdoflist=NULL;
+	if(this->fsize>0)this->fdoflist=xNew<int>(this->fsize); else this->fdoflist=NULL;
+	if(this->ssize>0)this->sdoflist=xNew<int>(this->ssize); else this->sdoflist=NULL;
 
 	if(this->gsize>0){
@@ -75,6 +80,6 @@
 		memcpy(this->gdoflist,in->gdoflist,this->gsize*sizeof(int));
 	}
-	if(this->fsize>0 && this->fsize!=UNDEF)memcpy(this->fdoflist,in->fdoflist,this->fsize*sizeof(int));
-	if(this->ssize>0 && this->ssize!=UNDEF)memcpy(this->sdoflist,in->sdoflist,this->ssize*sizeof(int));
+	if(this->fsize>0)memcpy(this->fdoflist,in->fdoflist,this->fsize*sizeof(int));
+	if(this->ssize>0)memcpy(this->sdoflist,in->sdoflist,this->ssize*sizeof(int));
 
 }
@@ -82,12 +87,62 @@
 DofIndexing::~DofIndexing(){ //destructor/*{{{*/
 
-	xDelete<bool>(f_set); 
-	xDelete<bool>(s_set); 
-	xDelete<IssmDouble>(svalues);
-	xDelete<int>(doftype); 
-	xDelete<int>(gdoflist);
-	xDelete<int>(fdoflist);
-	xDelete<int>(sdoflist);
-
+	if(this->f_set) xDelete<bool>(f_set); 
+	if(this->s_set) xDelete<bool>(s_set); 
+	if(this->svalues) xDelete<IssmDouble>(svalues);
+	if(this->doftype) xDelete<int>(doftype); 
+	if(this->gdoflist) xDelete<int>(gdoflist);
+	if(this->fdoflist) xDelete<int>(fdoflist);
+	if(this->sdoflist) xDelete<int>(sdoflist);
+
+}
+/*}}}*/
+DofIndexing DofIndexing::operator=( const DofIndexing& in ){/*{{{*/
+
+	this->copy(in);
+
+	return this;
+}
+/*}}}*/
+void DofIndexing::copy(const DofIndexing& in ){/*{{{*/
+
+	this->gsize  = in.gsize;
+	this->fsize  = in.fsize;
+	this->ssize  = in.ssize;
+	this->clone  = in.clone;
+	this->active = in.active;
+
+	if(this->gsize>0){
+		this->f_set=xNew<bool>(this->gsize);
+		this->s_set=xNew<bool>(this->gsize);
+		this->svalues=xNew<IssmDouble>(this->gsize);
+		if(in.doftype){
+			this->doftype=xNew<int>(this->gsize);
+		}
+		else{
+			this->doftype=NULL;
+		}
+		this->gdoflist=xNew<int>(this->gsize);
+	}
+	else{
+		this->f_set    = NULL;
+		this->s_set    = NULL;
+		this->svalues  = NULL;
+		this->doftype  = NULL;
+		this->gdoflist = NULL;
+	}
+	if(this->fsize>0)this->fdoflist=xNew<int>(this->fsize); else this->fdoflist=NULL;
+	if(this->ssize>0)this->sdoflist=xNew<int>(this->ssize); else this->sdoflist=NULL;
+
+	if(this->gsize>0){
+		memcpy(this->f_set,in.f_set,this->gsize*sizeof(bool));
+		memcpy(this->s_set,in.s_set,this->gsize*sizeof(bool));
+		xMemCpy<IssmDouble>(this->svalues,in.svalues,this->gsize);
+		if(this->doftype)memcpy(this->doftype,in.doftype,this->gsize*sizeof(int));
+		memcpy(this->gdoflist,in.gdoflist,this->gsize*sizeof(int));
+	}
+	if(this->fsize>0)memcpy(this->fdoflist,in.fdoflist,this->fsize*sizeof(int));
+	if(this->ssize>0)memcpy(this->sdoflist,in.sdoflist,this->ssize*sizeof(int));
+
+	return;
 }
 /*}}}*/
@@ -101,11 +156,11 @@
 	/*memory allocation */
 	if(this->gsize>0){
-		this->f_set    = xNew<bool>(this->gsize);
-		this->s_set    = xNew<bool>(this->gsize);
-		this->svalues  = xNew<IssmDouble>(this->gsize);
-		this->gdoflist = xNew<int>(this->gsize);
-
-		if(in_doftype)
-		 this->doftype = xNew<int>(this->gsize);
+		this->f_set    = xNew<bool>((unsigned int)in_gsize);
+		this->s_set    = xNew<bool>((unsigned int)in_gsize);
+		this->svalues  = xNew<IssmDouble>((unsigned int)in_gsize);
+		this->gdoflist = xNew<int>((unsigned int)in_gsize);
+
+		if(in_doftype) this->doftype = xNew<int>((unsigned int)in_gsize);
+		else this->doftype = NULL;
 	}
 
@@ -117,6 +172,5 @@
 		this->gdoflist[i] = UNDEF;
 
-		if(this->doftype)
-		 this->doftype[i]=in_doftype[i];
+		if(this->doftype) this->doftype[i]=in_doftype[i];
 	}
 }
Index: /issm/trunk-jpl/src/c/classes/DofIndexing.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/DofIndexing.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/DofIndexing.h	(revision 18237)
@@ -41,9 +41,10 @@
 		DofIndexing(DofIndexing* properties);
 		~DofIndexing();
+		DofIndexing operator=(const DofIndexing& in);
 		/*}}}*/
 		/*Object like functionality: {{{*/
 		void  Echo(void); 
 		void  DeepEcho(void); 
-		void  copy(DofIndexing* properties);
+		void  copy(const DofIndexing& in);
 		/*}}}*/
 		/*DofIndexing management: {{{*/
Index: /issm/trunk-jpl/src/c/classes/Elements/Element.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Element.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Element.cpp	(revision 18237)
@@ -289,5 +289,8 @@
 	if(nodes){
 		int numnodes = this->GetNumberOfNodes();
-		for(int i=0;i<numnodes;i++) nodes[i]->Echo();
+		for(int i=0;i<numnodes;i++) {
+			_printf_("nodes[" << i << "] = " << nodes[i]);	
+			nodes[i]->Echo();
+		}
 	}
 	else _printf_("nodes = NULL\n");
Index: /issm/trunk-jpl/src/c/classes/Elements/Element.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Element.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Element.h	(revision 18237)
@@ -165,4 +165,5 @@
 		virtual void       Configure(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters)=0;
 		virtual void       SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Materials* materials,Parameters* parameters)=0;
+		virtual void       ResetHooks()=0;
 		virtual void   ElementSizes(IssmDouble* phx,IssmDouble* phy,IssmDouble* phz)=0;
 
Index: /issm/trunk-jpl/src/c/classes/Elements/ElementHook.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/ElementHook.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/ElementHook.cpp	(revision 18237)
@@ -29,8 +29,5 @@
 	int i;
 
-	for(i=0;i<this->numanalyses;i++){
-		if (this->hnodes[i]) delete this->hnodes[i];
-	}
-	delete [] this->hnodes;
+	if (this->hnodes) delete [] this->hnodes;
 	delete hvertices;
 	delete hmaterial;
@@ -76,5 +73,5 @@
 
 void ElementHook::SetHookNodes(int* node_ids,int numnodes,int analysis_counter){/*{{{*/
-	this->hnodes[analysis_counter]= new Hook(node_ids,numnodes);
+	if(this->hnodes) this->hnodes[analysis_counter]= new Hook(node_ids,numnodes);
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Elements/Elements.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Elements.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Elements.cpp	(revision 18237)
@@ -62,4 +62,18 @@
 }
 /*}}}*/
+void Elements::ResetHooks(){/*{{{*/
+
+	vector<Object*>::iterator object;
+	Element* element=NULL;
+
+	for ( object=objects.begin() ; object < objects.end(); object++ ){
+
+		element=dynamic_cast<Element*>((*object));
+		element->ResetHooks();
+
+	}
+
+}
+/*}}}*/
 int  Elements::MaxNumNodes(void){/*{{{*/
 
Index: /issm/trunk-jpl/src/c/classes/Elements/Elements.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Elements.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Elements.h	(revision 18237)
@@ -27,4 +27,5 @@
 		int    MaxNumNodes(void);
 		void   SetCurrentConfiguration(Elements* elements,Loads* loads, Nodes* nodes, Vertices* vertices, Materials* materials,Parameters* parameters);
+		void   ResetHooks();
 		int    NumberOfElements(void);
 		void   InputDuplicate(int input_enum,int output_enum);
Index: /issm/trunk-jpl/src/c/classes/Elements/Penta.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Penta.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Penta.cpp	(revision 18237)
@@ -64,5 +64,4 @@
 
 	int i;
-
 	Penta* penta=NULL;
 
@@ -70,37 +69,56 @@
 
 	//deal with PentaRef mother class
-	penta->element_type_list=xNew<int>(this->numanalyses);
-	for(i=0;i<this->numanalyses;i++) penta->element_type_list[i]=this->element_type_list[i];
-
-	//deal with ElementHook
-	penta->numanalyses=this->numanalyses;
-	penta->hnodes=new Hook*[penta->numanalyses];
-	for(i=0;i<penta->numanalyses;i++)penta->hnodes[i]=(Hook*)this->hnodes[i]->copy();
-	penta->hvertices=(Hook*)this->hvertices->copy();
-	penta->hmaterial=(Hook*)this->hmaterial->copy();
-	penta->hmatpar=(Hook*)this->hmatpar->copy();
-	penta->hneighbors=(Hook*)this->hneighbors->copy();
-
-	/*deal with Penta  copy fields: */
-	penta->id=this->id;
-	penta->sid=this->sid;
-	if(this->inputs){
-		penta->inputs=(Inputs*)this->inputs->Copy();
-	}
-	else{
-		penta->inputs=new Inputs();
-	}
+	int nanalyses = this->numanalyses;
+	if(nanalyses > 0){
+		penta->element_type_list=xNew<int>(nanalyses);
+		for(i=0;i<nanalyses;i++) {
+			if (this->element_type_list[i]) penta->element_type_list[i]=this->element_type_list[i];
+			else penta->element_type_list[i] = NULL;
+		}
+	}
+	else penta->element_type_list = NULL;
+	penta->element_type=this->element_type;
+	penta->numanalyses=nanalyses;
+
+	//deal with ElementHook mother class
+	if (this->hnodes){
+		penta->hnodes=xNew<Hook*>(penta->numanalyses);
+		for(i=0;i<penta->numanalyses;i++){
+			if (this->hnodes[i]) penta->hnodes[i] = (Hook*)(this->hnodes[i]->copy());
+			else penta->hnodes[i] = NULL;
+		}
+	}
+	else penta->hnodes = NULL;
+
+	penta->hvertices = (Hook*)this->hvertices->copy();
+	penta->hmaterial = (Hook*)this->hmaterial->copy();
+	penta->hmatpar   = (Hook*)this->hmatpar->copy();
+	if (this->hneighbors) penta->hneighbors = (Hook*)(this->hneighbors->copy());
+	else penta->hneighbors = NULL;
+
+	/*deal with Tria fields: */
+	penta->id  = this->id;
+	penta->sid = this->sid;
+	if(this->inputs) penta->inputs = (Inputs*)(this->inputs->Copy());
+	else penta->inputs=new Inputs();
+
 	/*point parameters: */
 	penta->parameters=this->parameters;
 
 	/*recover objects: */
-	penta->nodes=xNew<Node*>(6); //we cannot rely on an analysis_counter to tell us which analysis_type we are running, so we just copy the nodes.
-	for(i=0;i<6;i++)penta->nodes[i]=this->nodes[i];
-	penta->vertices=(Vertex**)penta->hvertices->deliverp();
-	penta->material=(Material*)penta->hmaterial->delivers();
-	penta->matpar=(Matpar*)penta->hmatpar->delivers();
-	penta->verticalneighbors=(Penta**)penta->hneighbors->deliverp();
+	if (this->nodes) {
+		unsigned int num_nodes = 6;
+		penta->nodes = xNew<Node*>(num_nodes); //we cannot rely on an analysis_counter to tell us which analysis_type we are running, so we just copy the nodes.
+		for(i=0;i<num_nodes;i++) if(this->nodes[i]) penta->nodes[i]=this->nodes[i]; else penta->nodes[i] = NULL;
+	}
+	else penta->nodes = NULL;
+
+	penta->vertices = (Vertex**)this->hvertices->deliverp();
+	penta->material = (Material*)this->hmaterial->delivers();
+	penta->matpar   = (Matpar*)this->hmatpar->delivers();
+	penta->verticalneighbors = (Penta**)this->hneighbors->deliverp();
 
 	return penta;
+
 }
 /*}}}*/
@@ -1897,4 +1915,22 @@
 	if(this->hnodes[analysis_counter]) this->nodes=(Node**)this->hnodes[analysis_counter]->deliverp();
 	else this->nodes=NULL;
+
+}
+/*}}}*/
+void       Penta::ResetHooks(){/*{{{*/
+
+	this->nodes=NULL;
+	this->vertices=NULL;
+	this->material=NULL;
+	this->matpar=NULL;
+	this->verticalneighbors=NULL;
+	this->parameters=NULL;
+
+	//deal with ElementHook mother class
+	for(int i=0;i<this->numanalyses;i++) if(this->hnodes[i]) this->hnodes[i]->reset();
+	this->hvertices->reset();
+	this->hmaterial->reset();
+	this->hmatpar->reset();
+	if(this->hneighbors) this->hneighbors->reset();
 
 }
Index: /issm/trunk-jpl/src/c/classes/Elements/Penta.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Penta.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Penta.h	(revision 18237)
@@ -62,4 +62,5 @@
 		void   FSContactMigration(Vector<IssmDouble>* vertexgrounded,Vector<IssmDouble>* vertexfloating);
 		void   SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Materials* materials,Parameters* parameters);
+		void   ResetHooks();
 		void   Delta18oParameterization(void);
 		Penta* GetUpperPenta(void);
Index: /issm/trunk-jpl/src/c/classes/Elements/Seg.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Seg.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Seg.h	(revision 18237)
@@ -59,4 +59,5 @@
 		void        Configure(Elements* elements,Loads* loads,Nodes* nodesin,Vertices* verticesin,Materials* materials,Parameters* parameters){_error_("not implemented yet");};
 		void        SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Materials* materials,Parameters* parameters){_error_("not implemented yet");};
+		void        ResetHooks(){_error_("not implemented yet");};
 		void        Delta18oParameterization(void){_error_("not implemented yet");};
 		void        ElementSizes(IssmDouble* hx,IssmDouble* hy,IssmDouble* hz){_error_("not implemented yet");};
Index: /issm/trunk-jpl/src/c/classes/Elements/Tetra.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Tetra.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Tetra.cpp	(revision 18237)
@@ -48,5 +48,57 @@
 /*}}}*/
 Object* Tetra::copy() {/*{{{*/
-	_error_("not implemented yet");
+
+	int i;
+	Tetra* tetra=NULL;
+
+	tetra=new Tetra();
+
+	//deal with TetraRef mother class
+	int nanalyses = this->numanalyses;
+	if(nanalyses > 0){
+		tetra->element_type_list=xNew<int>(nanalyses);
+		for(i=0;i<nanalyses;i++){
+			if (this->element_type_list[i]) tetra->element_type_list[i]=this->element_type_list[i];
+			else tetra->element_type_list[i] = NULL;
+		}
+	}
+	else tetra->element_type_list = NULL;
+	tetra->element_type=this->element_type;
+	tetra->numanalyses=nanalyses;
+
+	//deal with ElementHook mother class
+	if (this->hnodes){
+		tetra->hnodes=xNew<Hook*>(tetra->numanalyses);
+		for(i=0;i<tetra->numanalyses;i++){
+			if (this->hnodes[i]) tetra->hnodes[i] = (Hook*)(this->hnodes[i]->copy());
+			else tetra->hnodes[i] = NULL;
+		}
+	}
+	else tetra->hnodes = NULL;
+
+	tetra->hvertices = (Hook*)this->hvertices->copy();
+	tetra->hmaterial = (Hook*)this->hmaterial->copy();
+	tetra->hmatpar   = (Hook*)this->hmatpar->copy();
+	tetra->hneighbors = NULL;
+
+	/*deal with Tria fields: */
+	tetra->id  = this->id;
+	tetra->sid = this->sid;
+	if(this->inputs) tetra->inputs = (Inputs*)(this->inputs->Copy());
+	else tetra->inputs=new Inputs();
+
+	/*point parameters: */
+	tetra->parameters=this->parameters;
+
+	/*recover objects: */
+	unsigned int num_nodes = 3;
+	tetra->nodes = xNew<Node*>(num_nodes); //we cannot rely on an analysis_counter to tell us which analysis_type we are running, so we just copy the nodes.
+	for(i=0;i<num_nodes;i++) if(this->nodes[i]) tetra->nodes[i]=this->nodes[i]; else tetra->nodes[i] = NULL;
+
+	tetra->vertices = (Vertex**)this->hvertices->deliverp();
+	tetra->material = (Material*)this->hmaterial->delivers();
+	tetra->matpar   = (Matpar*)this->hmatpar->delivers();
+
+	return tetra;
 }
 /*}}}*/
@@ -727,4 +779,20 @@
 }
 /*}}}*/
+void     Tetra::ResetHooks(){/*{{{*/
+
+	this->nodes=NULL;
+	this->vertices=NULL;
+	this->material=NULL;
+	this->matpar=NULL;
+	this->parameters=NULL;
+
+	//deal with ElementHook mother class
+	for(int i=0;i<this->numanalyses;i++) if(this->hnodes[i]) this->hnodes[i]->reset();
+	this->hvertices->reset();
+	this->hmaterial->reset();
+	this->hmatpar->reset();
+	if(this->hneighbors) this->hneighbors->reset();
+}
+/*}}}*/
 Element* Tetra::SpawnBasalElement(void){/*{{{*/
 
Index: /issm/trunk-jpl/src/c/classes/Elements/Tetra.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Tetra.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Tetra.h	(revision 18237)
@@ -59,4 +59,5 @@
 		void        Configure(Elements* elements,Loads* loads,Nodes* nodesin,Vertices* verticesin,Materials* materials,Parameters* parameters);
 		void        SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Materials* materials,Parameters* parameters);
+		void        ResetHooks();
 		void        Delta18oParameterization(void){_error_("not implemented yet");};
 		void        ElementSizes(IssmDouble* hx,IssmDouble* hy,IssmDouble* hz);
Index: /issm/trunk-jpl/src/c/classes/Elements/Tria.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Tria.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Tria.cpp	(revision 18237)
@@ -42,5 +42,10 @@
 		this->material = NULL;
 		this->matpar   = NULL;
-		this->element_type_list=xNew<int>(nummodels);
+		if(nummodels>0){
+			this->element_type_list=xNew<int>(nummodels);
+			for(int i=0;i<nummodels;i++) this->element_type_list[i] = NULL;
+		}
+		else this->element_type_list = NULL;
+
 }
 /*}}}*/
@@ -57,34 +62,52 @@
 
 	//deal with TriaRef mother class
-	tria->element_type_list=xNew<int>(this->numanalyses);
-	for(i=0;i<this->numanalyses;i++) tria->element_type_list[i]=this->element_type_list[i];
+	int nanalyses = this->numanalyses;
+	if(nanalyses > 0){
+		tria->element_type_list=xNew<int>(nanalyses);
+		for(i=0;i<nanalyses;i++){
+			if (this->element_type_list[i]) tria->element_type_list[i]=this->element_type_list[i];
+			else tria->element_type_list[i] = NULL;
+		}
+	}
+	else tria->element_type_list = NULL;
+	tria->element_type=this->element_type;
+	tria->numanalyses=nanalyses;
 
 	//deal with ElementHook mother class
-	tria->numanalyses=this->numanalyses;
-	tria->hnodes=new Hook*[tria->numanalyses];
-	for(i=0;i<tria->numanalyses;i++)tria->hnodes[i]=(Hook*)this->hnodes[i]->copy();
+	if (this->hnodes){
+		tria->hnodes=xNew<Hook*>(tria->numanalyses);
+		for(i=0;i<tria->numanalyses;i++){
+			if (this->hnodes[i]) tria->hnodes[i] = (Hook*)(this->hnodes[i]->copy());
+			else tria->hnodes[i] = NULL;
+		}
+	}
+	else tria->hnodes = NULL;
+
 	tria->hvertices = (Hook*)this->hvertices->copy();
 	tria->hmaterial = (Hook*)this->hmaterial->copy();
 	tria->hmatpar   = (Hook*)this->hmatpar->copy();
+	tria->hneighbors = NULL;
 
 	/*deal with Tria fields: */
 	tria->id  = this->id;
 	tria->sid = this->sid;
-	if(this->inputs){
-		tria->inputs=(Inputs*)this->inputs->Copy();
-	}
-	else{
-		tria->inputs=new Inputs();
-	}
+	if(this->inputs) tria->inputs = (Inputs*)(this->inputs->Copy());
+	else tria->inputs=new Inputs();
+
 	/*point parameters: */
 	tria->parameters=this->parameters;
 
 	/*recover objects: */
-	tria->nodes = xNew<Node*>(3); //we cannot rely on an analysis_counter to tell us which analysis_type we are running, so we just copy the nodes.
-	for(i=0;i<3;i++)tria->nodes[i]=this->nodes[i];
-
-	tria->vertices = (Vertex**)tria->hvertices->deliverp();
-	tria->material = (Material*)tria->hmaterial->delivers();
-	tria->matpar   = (Matpar*)tria->hmatpar->delivers();
+	if (this->nodes){
+		unsigned int num_nodes = 3;
+		tria->nodes = xNew<Node*>(num_nodes); //we cannot rely on an analysis_counter to tell us which analysis_type we are running, so we just copy the nodes.
+		for(i=0;i<num_nodes;i++) if(this->nodes[i]) tria->nodes[i]=this->nodes[i]; else tria->nodes[i] = NULL;
+	}
+	else tria->nodes = NULL;
+	
+
+	tria->vertices = (Vertex**)this->hvertices->deliverp();
+	tria->material = (Material*)this->hmaterial->delivers();
+	tria->matpar   = (Matpar*)this->hmatpar->delivers();
 
 	return tria;
@@ -307,9 +330,13 @@
 
 	/*Get Element type*/
-	this->element_type=this->element_type_list[analysis_counter];
+	if (this->element_type_list) this->element_type=this->element_type_list[analysis_counter];
 
 	/*Take care of hooking up all objects for this element, ie links the objects in the hooks to their respective 
 	 * datasets, using internal ids and offsets hidden in hooks: */
-	if(this->hnodes[analysis_counter]) this->hnodes[analysis_counter]->configure(nodesin);
+	if(this->hnodes){
+		if (this->hnodes[analysis_counter]) this->hnodes[analysis_counter]->configure(nodesin);
+		else this->hnodes[analysis_counter] = NULL;
+	}
+	else this->hnodes = NULL; 
 	this->hvertices->configure(verticesin);
 	this->hmaterial->configure(materialsin);
@@ -317,5 +344,5 @@
 
 	/*Now, go pick up the objects inside the hooks: */
-	if(this->hnodes[analysis_counter]) this->nodes=(Node**)this->hnodes[analysis_counter]->deliverp();
+	if(this->hnodes && this->hnodes[analysis_counter]) this->nodes=(Node**)this->hnodes[analysis_counter]->deliverp();
 	else this->nodes=NULL;
 	this->vertices = (Vertex**)this->hvertices->deliverp();
@@ -327,5 +354,5 @@
 
 	/*get inputs configured too: */
-	this->inputs->Configure(parameters);
+	this->inputs->Configure(this->parameters);
 
 }
@@ -856,5 +883,6 @@
 /*}}}*/
 int        Tria::GetNumberOfNodes(void){/*{{{*/
-	return this->NumberofNodes(this->element_type);
+	if (this->nodes) return this->NumberofNodes(this->element_type);
+	else return 0;
 }
 /*}}}*/
@@ -1684,4 +1712,21 @@
 }
 /*}}}*/
+void       Tria::ResetHooks(){/*{{{*/
+
+	this->nodes=NULL;
+	this->vertices=NULL;
+	this->material=NULL;
+	this->matpar=NULL;
+	this->parameters=NULL;
+
+	//deal with ElementHook mother class
+	for(int i=0;i<this->numanalyses;i++) if(this->hnodes[i]) this->hnodes[i]->reset();
+	this->hvertices->reset();
+	this->hmaterial->reset();
+	this->hmatpar->reset();
+	if(this->hneighbors) this->hneighbors->reset();
+
+}
+/*}}}*/
 void       Tria::SetClone(int* minranks){/*{{{*/
 
@@ -1759,9 +1804,10 @@
 
 	/*Get Element type*/
-	this->element_type=this->element_type_list[analysis_counter];
+	if(this->element_type_list) this->element_type=this->element_type_list[analysis_counter];
 
 	/*Pick up nodes*/
-	if(this->hnodes[analysis_counter]) this->nodes=(Node**)this->hnodes[analysis_counter]->deliverp();
-	else this->nodes=NULL;
+	if(this->hnodes && this->hnodes[analysis_counter]){
+		this->nodes=(Node**)this->hnodes[analysis_counter]->deliverp();
+	}
 
 }
Index: /issm/trunk-jpl/src/c/classes/Elements/Tria.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Elements/Tria.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Elements/Tria.h	(revision 18237)
@@ -58,4 +58,5 @@
 		void        Configure(Elements* elements,Loads* loads,Nodes* nodesin,Vertices* verticesin,Materials* materials,Parameters* parameters);
 		void        SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Materials* materials,Parameters* parameters);
+		void        ResetHooks();
 		void        Delta18oParameterization(void);
 		void        ElementSizes(IssmDouble* hx,IssmDouble* hy,IssmDouble* hz);
Index: /issm/trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 18237)
@@ -106,18 +106,7 @@
 	char *outbinfilename = NULL;
 	char *lockfilename   = NULL;
-	bool  waitonlock     = false;
-
-	/*Close output file: */
-	this->parameters->FindParam(&output_fid,OutputFilePointerEnum); 
-	this->parameters->FindParam(&outbinfilename,OutputFileNameEnum); 
-	pfclose(output_fid,outbinfilename);
-
-	/*Write lock file if requested: */
-	this->parameters->FindParam(&waitonlock,SettingsWaitonlockEnum);
+
+	this->parameters->FindParam(&outbinfilename,OutputFileNameEnum);
 	this->parameters->FindParam(&lockfilename,LockFileNameEnum);
-	if(waitonlock){
-		_printf0_("write lock file:\n");
-		WriteLockFile(lockfilename);
-	}
 
 	/*Delete all the datasets: */
@@ -134,4 +123,113 @@
 	delete results;
 
+	/*Now delete: */
+	delete profiler;
+
+}
+/*}}}*/
+
+/*Object management*/
+void FemModel::Echo(void){/*{{{*/
+
+	_printf_("FemModel echo: \n");
+	_printf_("   number of fem models: " << nummodels << "\n");
+	_printf_("   analysis_type_list: \n");
+	for(int i=0;i<nummodels;i++)_printf_("     " << i << ": " << EnumToStringx(analysis_type_list[i]) << "\n");
+	_printf_("   current analysis_type: \n");
+	_printf_("     " << analysis_counter << ": " << EnumToStringx(analysis_type_list[analysis_counter]) << "\n");
+
+}
+/*}}}*/
+void FemModel::InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* toolkitsfilename, char* lockfilename, const int in_solution_type,const int* analyses,const int nummodels){/*{{{*/
+
+	/*intermediary*/
+	int         i;
+	int         analysis_type;
+	FILE       *IOMODEL = NULL;
+	FILE       *toolkitsoptionsfid = NULL;
+	FILE       *output_fid = NULL;
+	int         my_rank;
+
+	/*recover my_rank:*/
+	my_rank=IssmComm::GetRank();
+
+	/*Open input file on cpu 0: */
+	if(my_rank==0) IOMODEL = pfopen0(inputfilename ,"rb");
+
+	/*Open toolkits file: */
+	toolkitsoptionsfid=pfopen(toolkitsfilename,"r");
+
+	/*Initialize internal data: */
+	this->nummodels        = nummodels;
+	this->solution_type    = in_solution_type;
+	this->analysis_counter = nummodels-1;   //point to last analysis_type carried out.
+	this->results          = new Results(); //not initialized by CreateDataSets
+
+	/*Dynamically allocate whatever is a list of length nummodels: */
+	analysis_type_list=xNew<int>(nummodels);
+
+	/*Initialize: */
+	for(i=0;i<nummodels;i++)analysis_type_list[i]=analyses[i];
+
+	/*create datasets for all analyses*/
+	ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,IOMODEL,toolkitsoptionsfid,rootpath,this->solution_type,nummodels,analyses);
+
+	/*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
+	for(i=0;i<nummodels;i++){
+
+		if(VerboseMProcessor()) _printf0_("   Processing finite element model of analysis " << EnumToStringx(analysis_type_list[i]) << ":\n");
+		analysis_type=analysis_type_list[i];
+		this->SetCurrentConfiguration(analysis_type);
+
+		if(i==0){
+			if(VerboseMProcessor()) _printf0_("      creating vertex PIDs\n");
+			VerticesDofx(vertices,parameters); //only call once, we only have one set of vertices
+		}
+
+		if(VerboseMProcessor()) _printf0_("      resolving node constraints\n");
+		SpcNodesx(nodes,constraints,parameters,analysis_type); 
+
+		if(VerboseMProcessor()) _printf0_("      creating nodal degrees of freedom\n");
+		NodesDofx(nodes,parameters,analysis_type);
+
+		if(VerboseMProcessor()) _printf0_("      configuring element and loads\n");
+		ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
+	}
+
+	/*Close input file and toolkits file descriptors: */
+	if(my_rank==0) pfclose(IOMODEL,inputfilename);
+	pfclose(toolkitsoptionsfid,toolkitsfilename);
+
+	/*Open output file once for all and add output file name and file descriptor to parameters*/
+	output_fid=pfopen(outputfilename,"wb");
+	this->parameters->AddObject(new StringParam(OutputFileNameEnum,outputfilename));
+	this->parameters->SetParam(output_fid,OutputFilePointerEnum);
+
+	/*Save lock file name for later: */
+	this->parameters->AddObject(new StringParam(LockFileNameEnum,lockfilename));
+
+	}
+/*}}}*/
+void FemModel::CleanUp(void){/*{{{*/
+
+	/*Intermediary*/
+	FILE *output_fid;
+	char *outbinfilename = NULL;
+	char *lockfilename   = NULL;
+	bool  waitonlock     = false;
+
+	/*Close output file: */
+	this->parameters->FindParam(&output_fid,OutputFilePointerEnum);
+	this->parameters->FindParam(&outbinfilename,OutputFileNameEnum);
+	pfclose(output_fid,outbinfilename);
+
+	/*Write lock file if requested: */
+	this->parameters->FindParam(&waitonlock,SettingsWaitonlockEnum);
+	this->parameters->FindParam(&lockfilename,LockFileNameEnum);
+	if(waitonlock){
+		_printf0_("write lock file:\n");
+		WriteLockFile(lockfilename);
+	}
+
 	/*Before we delete the profiler, report statistics for this run: */
 	profiler->Tag(Finish);  //final tagging
@@ -141,103 +239,17 @@
 	_printf0_("\n");
 	_printf0_("   Total elapsed time:"
-			<<profiler->DeltaTimeModHour(Start,Finish)<<" hrs "
-			<<profiler->DeltaTimeModMin(Start,Finish)<<" min "
-			<<profiler->DeltaTimeModSec(Start,Finish)<<" sec"
-			);
+				<<profiler->DeltaTimeModHour(Start,Finish)<<" hrs "
+				<<profiler->DeltaTimeModMin(Start,Finish)<<" min "
+				<<profiler->DeltaTimeModSec(Start,Finish)<<" sec"
+				);
 	_printf0_("\n");
-
-	/*Now delete: */
-	delete profiler;
 
 	/*Finalize PETSC for this model: */
 	#ifdef _HAVE_PETSC_
 	_printf0_("closing PETSc\n");
-	PetscFinalize(); 
+	PetscFinalize();
 	#endif
 
 }
-/*}}}*/
-
-/*Object management*/
-void FemModel::Echo(void){/*{{{*/
-
-	_printf_("FemModel echo: \n");
-	_printf_("   number of fem models: " << nummodels << "\n");
-	_printf_("   analysis_type_list: \n");
-	for(int i=0;i<nummodels;i++)_printf_("     " << i << ": " << EnumToStringx(analysis_type_list[i]) << "\n");
-	_printf_("   current analysis_type: \n");
-	_printf_("     " << analysis_counter << ": " << EnumToStringx(analysis_type_list[analysis_counter]) << "\n");
-
-}
-/*}}}*/
-void FemModel::InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* toolkitsfilename, char* lockfilename, const int in_solution_type,const int* analyses,const int nummodels){/*{{{*/
-
-	/*intermediary*/
-	int         i;
-	int         analysis_type;
-	FILE       *IOMODEL = NULL;
-	FILE       *toolkitsoptionsfid = NULL;
-	FILE       *output_fid = NULL;
-	int         my_rank;
-
-	/*recover my_rank:*/
-	my_rank=IssmComm::GetRank();
-
-	/*Open input file on cpu 0: */
-	if(my_rank==0) IOMODEL = pfopen0(inputfilename ,"rb");
-
-	/*Open toolkits file: */
-	toolkitsoptionsfid=pfopen(toolkitsfilename,"r");
-
-	/*Initialize internal data: */
-	this->nummodels        = nummodels;
-	this->solution_type    = in_solution_type;
-	this->analysis_counter = nummodels-1;   //point to last analysis_type carried out.
-	this->results          = new Results(); //not initialized by CreateDataSets
-
-	/*Dynamically allocate whatever is a list of length nummodels: */
-	analysis_type_list=xNew<int>(nummodels);
-
-	/*Initialize: */
-	for(i=0;i<nummodels;i++)analysis_type_list[i]=analyses[i];
-
-	/*create datasets for all analyses*/
-	ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,IOMODEL,toolkitsoptionsfid,rootpath,this->solution_type,nummodels,analyses);
-
-	/*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
-	for(i=0;i<nummodels;i++){
-
-		if(VerboseMProcessor()) _printf0_("   Processing finite element model of analysis " << EnumToStringx(analysis_type_list[i]) << ":\n");
-		analysis_type=analysis_type_list[i];
-		this->SetCurrentConfiguration(analysis_type);
-
-		if(i==0){
-			if(VerboseMProcessor()) _printf0_("      creating vertex PIDs\n");
-			VerticesDofx(vertices,parameters); //only call once, we only have one set of vertices
-		}
-
-		if(VerboseMProcessor()) _printf0_("      resolving node constraints\n");
-		SpcNodesx(nodes,constraints,parameters,analysis_type); 
-
-		if(VerboseMProcessor()) _printf0_("      creating nodal degrees of freedom\n");
-		NodesDofx(nodes,parameters,analysis_type);
-
-		if(VerboseMProcessor()) _printf0_("      configuring element and loads\n");
-		ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
-	}
-
-	/*Close input file and toolkits file descriptors: */
-	if(my_rank==0) pfclose(IOMODEL,inputfilename);
-	pfclose(toolkitsoptionsfid,toolkitsfilename);
-
-	/*Open output file once for all and add output file name and file descriptor to parameters*/
-	output_fid=pfopen(outputfilename,"wb");
-	this->parameters->AddObject(new StringParam(OutputFileNameEnum,outputfilename));
-	this->parameters->SetParam(output_fid,OutputFilePointerEnum);
-
-	/*Save lock file name for later: */
-	this->parameters->AddObject(new StringParam(LockFileNameEnum,lockfilename));
-
-	}
 /*}}}*/
 void FemModel::SetStaticComm(void){/*{{{*/
@@ -348,4 +360,52 @@
 }
 /*}}}*/
+FemModel* FemModel::copy(void){/*{{{*/
+
+	FemModel* output=NULL;
+	int       i;
+	int       analysis_type;
+
+	output=new FemModel(*this); //Use default copy constructor.
+
+	output->comm = this->comm;
+	output->nummodels = this->nummodels;
+	output->solution_type = this->solution_type;
+	output->analysis_counter = this->analysis_counter;
+
+	/*Now, deep copy arrays: */
+	output->analysis_type_list=xNew<int>(nummodels);
+	xMemCpy<int>(output->analysis_type_list,this->analysis_type_list,this->nummodels);
+
+	output->profiler=static_cast<Profiler*>(this->profiler->copy());
+
+	output->loads=static_cast<Loads*>(this->loads->Copy());
+	output->materials=static_cast<Materials*>(this->materials->Copy());
+	output->parameters=static_cast<Parameters*>(this->parameters->Copy());
+	output->constraints=static_cast<Constraints*>(this->constraints->Copy());
+	output->results=static_cast<Results*>(this->results->Copy());
+
+	output->nodes=static_cast<Nodes*>(this->nodes->Copy());
+	output->vertices=static_cast<Vertices*>(this->vertices->Copy());
+	output->elements=static_cast<Elements*>(this->elements->Copy());
+
+	/*reset hooks for elements, loads and nodes: */
+	output->elements->ResetHooks();
+	output->loads->ResetHooks();
+	output->materials->ResetHooks();
+
+	/*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
+	for(i=0;i<nummodels;i++){
+		analysis_type=output->analysis_type_list[i];
+		output->SetCurrentConfiguration(analysis_type);
+		if(i==0) VerticesDofx(output->vertices,output->parameters); //only call once, we only have one set of vertices
+		SpcNodesx(output->nodes,output->constraints,output->parameters,analysis_type);
+		NodesDofx(output->nodes,output->parameters,analysis_type);
+		ConfigureObjectsx(output->elements,output->loads,output->nodes,output->vertices,output->materials,output->parameters);
+	}
+
+	return output;
+}
+/*}}}*/
+
 /*Modules:*/
 int  FemModel::UpdateVertexPositionsx(void){ /*{{{*/
Index: /issm/trunk-jpl/src/c/classes/FemModel.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/FemModel.h	(revision 18237)
@@ -52,5 +52,7 @@
 		/*Methods:*/
 		void Echo();
+		FemModel* copy();
 		void InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* petscfilename, char* lockfilename, const int solution_type,const int* analyses,const int nummodels);
+		void CleanUp(void);
 		void Solve(void);
 		void SetStaticComm();
Index: /issm/trunk-jpl/src/c/classes/Hook.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Hook.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Hook.cpp	(revision 18237)
@@ -29,15 +29,16 @@
 
 	/*Get out if num=0*/
-	if (num==0){
+	if (this->num<=0){
 		/*Empty hook*/
 		this->ids     = NULL;
 		this->objects = NULL;
 		this->offsets = NULL;
+		this->num = 0;
 	}
 	else{
 		/*Allocate: */
-		this->objects=xNew<Object*>(this->num);
-		this->ids=xNew<int>(this->num);
-		this->offsets=xNew<int>(this->num);
+		this->objects=xNew<Object*>(in_num);
+		this->ids=xNew<int>(in_num);
+		this->offsets=xNew<int>(in_num);
 
 		/*Copy ids: */
@@ -109,18 +110,9 @@
 
 	/*initalize output: */
-	output=new Hook();
-
-	/*copy in the fields: */
-	output->num=this->num;
-	if(output->num){
-		output->objects = xNew<Object*>(output->num);
-		output->ids     = xNew<int>(output->num);
-		output->offsets = xNew<int>(output->num);
-	}
+	output=new Hook(this->ids,this->num);
 
 	for(int i=0;i<output->num;i++){
 		output->objects[i] = this->objects[i];
 		output->offsets[i] = this->offsets[i];
-		output->ids[i]     = this->ids[i];
 	}
 
@@ -130,4 +122,15 @@
 
 /*Hook management: */
+void Hook::reset(){/*{{{*/
+
+	/*intermediary: */
+	Object* object=NULL;
+	int i;
+
+	for(i=0;i<this->num;i++){
+			this->objects[i]=NULL; //reset this node.
+	}
+}
+/*}}}*/
 void Hook::configure(DataSet* dataset){/*{{{*/
 
@@ -161,4 +164,5 @@
 			else this->offsets[i]=UNDEF; //object offset was wrong, reset it.
 		}
+		else this->offsets[i]=UNDEF;
 
 		/*Now, for this->objects that did not get resolved, and for which we have no offset, chase them in the dataset, by id: */
@@ -174,5 +178,5 @@
 
 	/*first, check that we only have one T object in our object list: */
-	if (this->num!=1) _error_("trying to delivery a single hook object when hook holds " << this->num << " objects" << "\n");
+	if (this->num!=1) _error_("trying to deliver a single hook object when hook holds " << this->num << " objects" << "\n");
 
 	/*check NULL: */
Index: /issm/trunk-jpl/src/c/classes/Hook.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Hook.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Hook.h	(revision 18237)
@@ -39,4 +39,5 @@
 		Object**   deliverp(void); //deliver all objects
 		void       configure(DataSet* dataset);
+		void       reset(void);
 		Hook*      Spawn(int* indices, int numindices);
 		int*       Ids(void);
Index: /issm/trunk-jpl/src/c/classes/Inputs/DatasetInput.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Inputs/DatasetInput.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Inputs/DatasetInput.cpp	(revision 18237)
@@ -65,7 +65,10 @@
 	output = new DatasetInput();
 	output->enum_type=this->enum_type;
-	output->inputs=(Inputs*)this->inputs->Copy();
+	output->numids=this->numids;
+	output->ids=xNew<int>(output->numids);
+	xMemCpy(output->ids,this->ids,output->numids);
+	output->inputs=static_cast<Inputs*>(this->inputs->Copy());
 
-	return output;
+	return (Object*)output;
 }
 /*}}}*/
@@ -152,5 +155,5 @@
 	/*Get requested input within dataset*/
 	for(int i=0;i<this->numids;i++) if(this->ids[i]==id) offset=i;
-	if(offset<0) _error_("Could not find input of id "<<id);
+	if(offset<0) _error_("Could not find input of id "<<id );
 
 	Input* input=dynamic_cast<Input*>(this->inputs->GetObjectByOffset(offset));
Index: /issm/trunk-jpl/src/c/classes/Inputs/PentaInput.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Inputs/PentaInput.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Inputs/PentaInput.cpp	(revision 18237)
@@ -20,10 +20,18 @@
 
 	/*Set Enum*/
-	enum_type=in_enum_type;
+	this->enum_type=in_enum_type;
 	this->interpolation_type=interpolation_type_in;
 
+	int numnodes = this->NumberofNodes(this->interpolation_type);
+
 	/*Set values*/
-	this->values=xNew<IssmDouble>(this->NumberofNodes(this->interpolation_type));
-	for(int i=0;i<this->NumberofNodes(this->interpolation_type);i++) values[i]=in_values[i];
+	if (numnodes > 0){
+		this->values=xNew<IssmDouble>((unsigned int)numnodes);
+		for(int i=0;i<this->NumberofNodes(this->interpolation_type);i++) values[i]=in_values[i];
+	}
+	else{
+		this->values = NULL;
+	}
+
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Inputs/TetraInput.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Inputs/TetraInput.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Inputs/TetraInput.cpp	(revision 18237)
@@ -20,10 +20,18 @@
 
 	/*Set Enum*/
-	enum_type=in_enum_type;
+	this->enum_type=in_enum_type;
 	this->interpolation_type=interpolation_type_in;
 
+	int numnodes = this->NumberofNodes(this->interpolation_type);
+
 	/*Set values*/
-	this->values=xNew<IssmDouble>(this->NumberofNodes(this->interpolation_type));
-	for(int i=0;i<this->NumberofNodes(this->interpolation_type);i++) values[i]=in_values[i];
+	if (numnodes > 0){
+		this->values=xNew<IssmDouble>((unsigned int)numnodes);
+		for(int i=0;i<this->NumberofNodes(this->interpolation_type);i++) values[i]=in_values[i];
+	}
+	else{
+		this->values = NULL;
+	}
+
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Inputs/TransientInput.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Inputs/TransientInput.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Inputs/TransientInput.cpp	(revision 18237)
@@ -80,7 +80,7 @@
 }
 /*}}}*/
-int    TransientInput::Id(void){ return -1; }/*{{{*/
-/*}}}*/
-int TransientInput::ObjectEnum(void){/*{{{*/
+int  TransientInput::Id(void){ return -1; }/*{{{*/
+/*}}}*/
+int  TransientInput::ObjectEnum(void){/*{{{*/
 
 	return TransientInputEnum;
@@ -96,9 +96,9 @@
 	output->numtimesteps=this->numtimesteps;
 	output->timesteps=xNew<IssmDouble>(this->numtimesteps);
-        xMemCpy(output->timesteps,this->timesteps,this->numtimesteps);
-	output->inputs=(Inputs*)this->inputs->Copy();
+	xMemCpy(output->timesteps,this->timesteps,this->numtimesteps);
+	output->inputs=static_cast<Inputs*>(this->inputs->Copy());
 	output->parameters=this->parameters;
 
-	return output;
+	return (Object*)output;
 
 }
@@ -315,5 +315,5 @@
 }
 /*}}}*/
-int TransientInput::GetResultInterpolation(void){/*{{{*/
+int  TransientInput::GetResultInterpolation(void){/*{{{*/
 
 	IssmDouble time;
@@ -330,5 +330,5 @@
 }
 /*}}}*/
-int TransientInput::GetResultNumberOfNodes(void){/*{{{*/
+int  TransientInput::GetResultNumberOfNodes(void){/*{{{*/
 
 	IssmDouble time;
Index: /issm/trunk-jpl/src/c/classes/Inputs/TriaInput.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Inputs/TriaInput.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Inputs/TriaInput.cpp	(revision 18237)
@@ -20,10 +20,17 @@
 
 	/*Set Enum*/
-	enum_type=in_enum_type;
+	this->enum_type=in_enum_type;
 	this->interpolation_type=interpolation_type_in;
 
+	int numnodes = this->NumberofNodes(this->interpolation_type);
+
 	/*Set values*/
-	this->values=xNew<IssmDouble>(this->NumberofNodes(this->interpolation_type));
-	for(int i=0;i<this->NumberofNodes(this->interpolation_type);i++) values[i]=in_values[i];
+	if (numnodes > 0){
+		this->values=xNew<IssmDouble>((unsigned int)numnodes);
+		for(int i=0;i<this->NumberofNodes(this->interpolation_type);i++) values[i]=in_values[i];
+	}
+	else{
+		this->values = NULL;
+	}
 }
 /*}}}*/
@@ -45,7 +52,7 @@
 }
 /*}}}*/
-int    TriaInput::Id(void){ return -1; }/*{{{*/
-/*}}}*/
-int TriaInput::ObjectEnum(void){/*{{{*/
+int  TriaInput::Id(void){ return -1; }/*{{{*/
+/*}}}*/
+int  TriaInput::ObjectEnum(void){/*{{{*/
 
 	return TriaInputEnum;
Index: /issm/trunk-jpl/src/c/classes/Loads/Load.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Load.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Load.h	(revision 18237)
@@ -26,4 +26,5 @@
 		virtual       ~Load(){};
 		virtual void  Configure(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters)=0;
+		virtual void  ResetHooks()=0;
 		virtual bool  IsPenalty(void)=0;
 		virtual int   GetNumberOfNodes(void)=0;
Index: /issm/trunk-jpl/src/c/classes/Loads/Loads.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Loads.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Loads.cpp	(revision 18237)
@@ -43,4 +43,18 @@
 		load=dynamic_cast<Load*>(*object);
 		load->Configure(elements,loads,nodes,vertices,materials,parameters);
+
+	}
+
+}
+/*}}}*/
+void Loads::ResetHooks(){/*{{{*/
+
+	vector<Object*>::iterator object;
+	Load* load=NULL;
+
+	for ( object=objects.begin() ; object < objects.end(); object++ ){
+
+		load=dynamic_cast<Load*>((*object));
+		load->ResetHooks();
 
 	}
Index: /issm/trunk-jpl/src/c/classes/Loads/Loads.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Loads.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Loads.h	(revision 18237)
@@ -24,4 +24,5 @@
 		/*numerics*/
 		void  Configure(Elements* elements,Loads* loads, Nodes* nodes, Vertices* vertices, Materials* materials,Parameters* parameters);
+		void  ResetHooks();
 		bool  IsPenalty(int analysis);
 		int   MaxNumNodes(int analysis);
Index: /issm/trunk-jpl/src/c/classes/Loads/Numericalflux.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Numericalflux.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Numericalflux.cpp	(revision 18237)
@@ -158,5 +158,5 @@
 }		
 /*}}}*/
-int    Numericalflux::Id(void){/*{{{*/
+int Numericalflux::Id(void){/*{{{*/
 	return id;
 }
@@ -215,4 +215,18 @@
 /*}}}*/
 void  Numericalflux::SetCurrentConfiguration(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
+
+}
+/*}}}*/
+void  Numericalflux::ResetHooks(){/*{{{*/
+
+	this->nodes=NULL;
+	this->vertices=NULL;
+	this->element=NULL;
+	this->parameters=NULL;
+
+	/*Get Element type*/
+	this->hnodes->reset();
+	this->hvertices->reset();
+	this->helement->reset();
 
 }
@@ -277,5 +291,5 @@
 }
 /*}}}*/
-void Numericalflux::GetNodesSidList(int* sidlist){/*{{{*/
+void  Numericalflux::GetNodesSidList(int* sidlist){/*{{{*/
 
 	_assert_(sidlist);
@@ -294,5 +308,5 @@
 }
 /*}}}*/
-void Numericalflux::GetNodesLidList(int* lidlist){/*{{{*/
+void  Numericalflux::GetNodesLidList(int* lidlist){/*{{{*/
 
 	_assert_(lidlist);
@@ -311,5 +325,5 @@
 }
 /*}}}*/
-int Numericalflux::GetNumberOfNodes(void){/*{{{*/
+int   Numericalflux::GetNumberOfNodes(void){/*{{{*/
 
 	switch(this->flux_type){
@@ -324,5 +338,5 @@
 }
 /*}}}*/
-bool Numericalflux::IsPenalty(void){/*{{{*/
+bool  Numericalflux::IsPenalty(void){/*{{{*/
 	return false;
 }
@@ -342,10 +356,10 @@
 }
 /*}}}*/
-bool Numericalflux::InAnalysis(int in_analysis_type){/*{{{*/
+bool  Numericalflux::InAnalysis(int in_analysis_type){/*{{{*/
 	if (in_analysis_type==this->analysis_type) return true;
 	else return false;
 }
 /*}}}*/
-void Numericalflux::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
+void  Numericalflux::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
 
 	/*Output */
Index: /issm/trunk-jpl/src/c/classes/Loads/Numericalflux.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Numericalflux.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Numericalflux.h	(revision 18237)
@@ -58,4 +58,5 @@
 		void Configure(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
 		void SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
+		void ResetHooks();
 		void CreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs);
 		void CreatePVector(Vector<IssmDouble>* pf);
Index: /issm/trunk-jpl/src/c/classes/Loads/Pengrid.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Pengrid.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Pengrid.cpp	(revision 18237)
@@ -160,4 +160,18 @@
 }
 /*}}}*/
+void  Pengrid::ResetHooks(){/*{{{*/
+
+	this->node=NULL;
+	this->element=NULL;
+	this->matpar=NULL;
+	this->parameters=NULL;
+
+	/*Get Element type*/
+	this->hnode->reset();
+	this->helement->reset();
+	this->hmatpar->reset();
+
+}
+/*}}}*/
 void  Pengrid::CreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs){/*{{{*/
 
@@ -189,5 +203,5 @@
 }
 /*}}}*/
-void Pengrid::GetNodesSidList(int* sidlist){/*{{{*/
+void  Pengrid::GetNodesSidList(int* sidlist){/*{{{*/
 
 	_assert_(sidlist);
@@ -197,5 +211,5 @@
 }
 /*}}}*/
-void Pengrid::GetNodesLidList(int* lidlist){/*{{{*/
+void  Pengrid::GetNodesLidList(int* lidlist){/*{{{*/
 
 	_assert_(lidlist);
@@ -205,5 +219,5 @@
 }
 /*}}}*/
-int Pengrid::GetNumberOfNodes(void){/*{{{*/
+int   Pengrid::GetNumberOfNodes(void){/*{{{*/
 
 	return NUMVERTICES;
@@ -268,14 +282,14 @@
 }
 /*}}}*/
-bool Pengrid::InAnalysis(int in_analysis_type){/*{{{*/
+bool  Pengrid::InAnalysis(int in_analysis_type){/*{{{*/
 	if (in_analysis_type==this->analysis_type)return true;
 	else return false;
 }
 /*}}}*/
-bool Pengrid::IsPenalty(void){/*{{{*/
+bool  Pengrid::IsPenalty(void){/*{{{*/
 	return true;
 }
 /*}}}*/
-void Pengrid::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
+void  Pengrid::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
 
 	/*Output */
Index: /issm/trunk-jpl/src/c/classes/Loads/Pengrid.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Pengrid.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Pengrid.h	(revision 18237)
@@ -68,4 +68,5 @@
 		void  Configure(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
 		void  SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
+		void  ResetHooks();
 		void  CreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs);
 		void  CreatePVector(Vector<IssmDouble>* pf);
Index: /issm/trunk-jpl/src/c/classes/Loads/Penpair.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Penpair.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Penpair.cpp	(revision 18237)
@@ -65,7 +65,7 @@
 }		
 /*}}}*/
-int    Penpair::Id(void){ return id; }/*{{{*/
-/*}}}*/
-int Penpair::ObjectEnum(void){/*{{{*/
+int  Penpair::Id(void){ return id; }/*{{{*/
+/*}}}*/
+int  Penpair::ObjectEnum(void){/*{{{*/
 
 	return PenpairEnum;
@@ -113,4 +113,14 @@
 }
 /*}}}*/
+void  Penpair::ResetHooks(){/*{{{*/
+
+	this->nodes=NULL;
+	this->parameters=NULL;
+
+	/*Get Element type*/
+	this->hnodes->reset();
+
+}
+/*}}}*/
 void  Penpair::CreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs){/*{{{*/
 	/*If you code this piece, don't forget that a penalty will be inactive if it is dealing with clone nodes*/
@@ -131,5 +141,5 @@
 }
 /*}}}*/
-void Penpair::GetNodesSidList(int* sidlist){/*{{{*/
+void  Penpair::GetNodesSidList(int* sidlist){/*{{{*/
 
 	_assert_(sidlist);
@@ -139,5 +149,5 @@
 }
 /*}}}*/
-void Penpair::GetNodesLidList(int* lidlist){/*{{{*/
+void  Penpair::GetNodesLidList(int* lidlist){/*{{{*/
 
 	_assert_(lidlist);
@@ -147,10 +157,10 @@
 }
 /*}}}*/
-int Penpair::GetNumberOfNodes(void){/*{{{*/
+int   Penpair::GetNumberOfNodes(void){/*{{{*/
 
 	return NUMVERTICES;
 }
 /*}}}*/
-bool Penpair::IsPenalty(void){/*{{{*/
+bool  Penpair::IsPenalty(void){/*{{{*/
 	return true;
 }
@@ -190,10 +200,10 @@
 }
 /*}}}*/
-bool Penpair::InAnalysis(int in_analysis_type){/*{{{*/
+bool  Penpair::InAnalysis(int in_analysis_type){/*{{{*/
 	if (in_analysis_type==this->analysis_type)return true;
 	else return false;
 }
 /*}}}*/
-void Penpair::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
+void  Penpair::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
 
 	/*Output */
Index: /issm/trunk-jpl/src/c/classes/Loads/Penpair.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Penpair.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Penpair.h	(revision 18237)
@@ -48,4 +48,5 @@
 			/*Load virtual functions definitions: {{{*/
 		void  Configure(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
+		void  ResetHooks();
 		void  SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
 		void  CreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs);
Index: /issm/trunk-jpl/src/c/classes/Loads/Riftfront.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Riftfront.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Riftfront.cpp	(revision 18237)
@@ -208,5 +208,5 @@
 }
 /*}}}*/
-void    Riftfront::InputUpdateFromVector(IssmDouble* vector, int name, int type){/*{{{*/
+void  Riftfront::InputUpdateFromVector(IssmDouble* vector, int name, int type){/*{{{*/
 
 	_error_("not implemented yet");
@@ -216,5 +216,5 @@
 
 /*Load virtual functions definitions:*/
-void  Riftfront::Configure(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
+void  Riftfront::Configure(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/	
 
 	/*Take care of hooking up all objects for this element, ie links the objects in the hooks to their respective 
@@ -234,5 +234,19 @@
 }
 /*}}}*/
-bool Riftfront::IsPenalty(void){/*{{{*/
+void  Riftfront::ResetHooks(){/*{{{*/
+
+	this->nodes=NULL;
+	this->elements=NULL;
+	this->matpar=NULL;
+	this->parameters=NULL;
+
+	/*Get Element type*/
+	this->hnodes->reset();
+	this->helements->reset();
+	this->hmatpar->reset();
+
+}
+/*}}}*/
+bool  Riftfront::IsPenalty(void){/*{{{*/
 	return true;
 }
@@ -302,5 +316,5 @@
 }
 /*}}}*/
-void Riftfront::GetNodesSidList(int* sidlist){/*{{{*/
+void  Riftfront::GetNodesSidList(int* sidlist){/*{{{*/
 
 	_assert_(sidlist);
@@ -310,5 +324,5 @@
 }
 /*}}}*/
-void Riftfront::GetNodesLidList(int* lidlist){/*{{{*/
+void  Riftfront::GetNodesLidList(int* lidlist){/*{{{*/
 
 	_assert_(lidlist);
@@ -318,15 +332,15 @@
 }
 /*}}}*/
-int Riftfront::GetNumberOfNodes(void){/*{{{*/
+int   Riftfront::GetNumberOfNodes(void){/*{{{*/
 
 	return NUMVERTICES;
 }
 /*}}}*/
-bool Riftfront::InAnalysis(int in_analysis_type){/*{{{*/
+bool  Riftfront::InAnalysis(int in_analysis_type){/*{{{*/
 	if (in_analysis_type==this->analysis_type) return true;
 	else return false;
 }
 /*}}}*/
-void Riftfront::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
+void  Riftfront::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
 
 	/*Output */
@@ -556,5 +570,5 @@
 /*}}}*/
 #define _ZIGZAGCOUNTER_
-int Riftfront::Constrain(int* punstable){/*{{{*/
+int    Riftfront::Constrain(int* punstable){/*{{{*/
 
 	IssmDouble  penetration;
Index: /issm/trunk-jpl/src/c/classes/Loads/Riftfront.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Loads/Riftfront.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Loads/Riftfront.h	(revision 18237)
@@ -74,4 +74,5 @@
 		/*Load virtual functions definitions: {{{*/
 		void  Configure(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
+		void  ResetHooks();
 		void  SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
 		void  CreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs);
Index: /issm/trunk-jpl/src/c/classes/Materials/Material.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Materials/Material.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Materials/Material.h	(revision 18237)
@@ -41,4 +41,5 @@
 		virtual IssmDouble GetDbar()=0;
 		virtual bool       IsDamage()=0;
+		virtual void       ResetHooks()=0;
 
 };
Index: /issm/trunk-jpl/src/c/classes/Materials/Materials.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Materials/Materials.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Materials/Materials.cpp	(revision 18237)
@@ -44,2 +44,16 @@
 }
 /*}}}*/
+void Materials::ResetHooks(){/*{{{*/
+
+	vector<Object*>::iterator object;
+	Material* material=NULL;
+
+	for ( object=objects.begin() ; object < objects.end(); object++ ){
+
+		material=dynamic_cast<Material*>((*object));
+		material->ResetHooks();
+
+	}
+
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Materials/Materials.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Materials/Materials.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Materials/Materials.h	(revision 18237)
@@ -24,4 +24,5 @@
 		/*numerics*/
 		void  Configure(Elements* elements,Loads* loads, Nodes* nodes, Vertices* vertices, Materials* materials,Parameters* parameters);
+		void  ResetHooks();
 
 };
Index: /issm/trunk-jpl/src/c/classes/Materials/Matice.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Materials/Matice.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Materials/Matice.cpp	(revision 18237)
@@ -567,2 +567,11 @@
 }
 /*}}}*/
+void  Matice::ResetHooks(){/*{{{*/
+
+	this->element=NULL;
+
+	/*Get Element type*/
+	this->helement->reset();
+
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Materials/Matice.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Materials/Matice.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Materials/Matice.h	(revision 18237)
@@ -41,5 +41,5 @@
 		Object* copy();
 		/*}}}*/
-		/*Update virtual functions definitions: {{{*/
+		/*Update virtual funictions definitions: {{{*/
 		void  InputUpdateFromVector(IssmDouble* vector, int name, int type);
 		void  InputUpdateFromMatrixDakota(IssmDouble* matrix, int nrow, int ncols, int name, int type);
@@ -70,4 +70,5 @@
 		IssmDouble GetN();
 		bool       IsDamage();
+		void       ResetHooks();
 		/*}}}*/
 };
Index: /issm/trunk-jpl/src/c/classes/Materials/Matpar.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Materials/Matpar.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Materials/Matpar.cpp	(revision 18237)
@@ -135,5 +135,47 @@
 /*}}}*/
 Object* Matpar::copy() {/*{{{*/
-	return new Matpar(*this); 
+
+	/*Output*/
+	Matpar* matpar;
+
+	/*Initialize output*/
+	matpar=new Matpar(*this);
+
+	/*copy fields: */
+	matpar->mid=this->mid;
+	matpar->rho_ice=this->rho_ice;
+	matpar->rho_water=this->rho_water;
+	matpar->rho_freshwater=this->rho_freshwater;
+	matpar->mu_water=this->mu_water;
+	matpar->heatcapacity=this->heatcapacity;
+	matpar->thermalconductivity=this->thermalconductivity;
+	matpar->temperateiceconductivity=this->temperateiceconductivity;
+	matpar->latentheat=this->latentheat;
+	matpar->beta=this->beta;
+	matpar->meltingpoint=this->meltingpoint;
+	matpar->referencetemperature=this->referencetemperature;
+	matpar->mixed_layer_capacity=this->mixed_layer_capacity;
+	matpar->thermal_exchange_velocity=this->thermal_exchange_velocity;
+	matpar->g=this->g;
+	matpar->desfac=this->desfac;
+	matpar->s0p=this->s0p;
+
+	matpar->sediment_compressibility=this->sediment_compressibility;
+	matpar->sediment_porosity=this->sediment_porosity;
+	matpar->sediment_thickness=this->sediment_thickness;
+	matpar->water_compressibility=this->water_compressibility;
+
+	matpar->epl_compressibility=this->epl_compressibility;
+	matpar->epl_porosity=this->epl_porosity;
+	matpar->epl_init_thickness=this->epl_init_thickness;
+	matpar->epl_max_thickness=this->epl_max_thickness;
+	matpar->epl_conductivity=this->epl_conductivity;
+
+	matpar->lithosphere_shear_modulus=this->lithosphere_shear_modulus;
+	matpar->lithosphere_density=this->lithosphere_density;
+	matpar->mantle_shear_modulus=this->mantle_shear_modulus;
+	matpar->mantle_density=this->mantle_density;
+
+	return matpar;
 }
 /*}}}*/
@@ -401,2 +443,8 @@
 }		 
 /*}}}*/ 
+void  Matpar::ResetHooks(){/*{{{*/
+
+	//Nothing to be done
+	return;
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Materials/Matpar.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Materials/Matpar.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Materials/Matpar.h	(revision 18237)
@@ -91,4 +91,5 @@
 		IssmDouble GetDbar(){_error_("not supported");};
 		bool       IsDamage(){_error_("not supported");};
+		void       ResetHooks();
 		/*}}}*/
 		/*Numerics: {{{*/
Index: /issm/trunk-jpl/src/c/classes/Misfit.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Misfit.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Misfit.h	(revision 18237)
@@ -88,5 +88,8 @@
 		/*}}}*/
 		Object* copy() {/*{{{*/
-			return new Misfit(this->name,this->model_enum,this->observation_enum,this->timeinterpolation,this->weights_enum);
+			Misfit* mf = new Misfit(this->name,this->model_enum,this->observation_enum,this->timeinterpolation,this->weights_enum);
+			mf->misfit=this->misfit;
+			mf->lock=this->lock;
+			return (Object*) mf;
 		}
 		/*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Node.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Node.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Node.cpp	(revision 18237)
@@ -125,4 +125,31 @@
 }
 /*}}}*/
+Object* Node::copy(void){/*{{{*/
+
+	int k,l;
+
+	/*output: */
+	Node* output=NULL;
+
+	/*initalize output: */
+	output=new Node();
+
+	/*id: */
+	output->id  = this->id;
+	output->sid = this->sid;
+	output->lid = this->lid;
+	output->analysis_enum = this->analysis_enum;
+	output->approximation = this->approximation;
+
+	/*Initialize coord_system: */
+	for(k=0;k<3;k++) for(l=0;l<3;l++) output->coord_system[k][l]=this->coord_system[k][l];
+
+	/*indexing:*/
+	output->indexingupdate = this->indexingupdate;
+	output->indexing.copy(this->indexing);
+
+	return (Object*)output; 
+}
+/*}}}*/
 
 /*Object virtual functions definitions:*/
@@ -514,5 +541,5 @@
 		else if (setenum==SsetEnum){
 			if(this->indexing.doftype){
-				numdofs=0;
+			numdofs=0;
 				for(i=0;i<this->indexing.gsize;i++){
 					if((this->indexing.doftype[i]==approximation_enum) && (this->indexing.s_set[i])) numdofs++;
Index: /issm/trunk-jpl/src/c/classes/Node.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Node.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Node.h	(revision 18237)
@@ -49,5 +49,5 @@
 		int     Id();
 		int     ObjectEnum();
-		Object *copy(){_error_("Not implemented yet (similar to Elements)"); };
+		Object *copy();
 
 		/*Node numerical routines*/
Index: /issm/trunk-jpl/src/c/classes/Params/DoubleParam.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Params/DoubleParam.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Params/DoubleParam.cpp	(revision 18237)
@@ -38,7 +38,7 @@
 }
 /*}}}*/
-int    DoubleParam::Id(void){ return -1; }/*{{{*/
+int  DoubleParam::Id(void){ return -1; }/*{{{*/
 /*}}}*/
-int DoubleParam::ObjectEnum(void){/*{{{*/
+int  DoubleParam::ObjectEnum(void){/*{{{*/
 
 	return DoubleParamEnum;
Index: /issm/trunk-jpl/src/c/classes/Params/Parameters.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Params/Parameters.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Params/Parameters.cpp	(revision 18237)
@@ -108,5 +108,5 @@
 		}
 	}
-	_error_("could not find parameter " << EnumToStringx(enum_type));
+	_error_("could not find parameter " <<  EnumToStringx(enum_type));
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/Profiler.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Profiler.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Profiler.cpp	(revision 18237)
@@ -29,4 +29,19 @@
 }
 /*}}}*/
+Object* Profiler::copy(){/*{{{*/
+	/*First do simple copy: */
+	Profiler* output=new Profiler();
+	delete output->time;
+	delete output->flops;
+	delete output->memory;
+
+	/*Now for deep copy: */
+	output->time=(Parameters*)this->time->Copy();
+	output->flops=(Parameters*)this->flops->Copy();
+	output->memory=(Parameters*)this->memory->Copy();
+
+	return (Object*)output;
+}
+/*}}}*/
 
 /*Object virtual functions definitions:*/
@@ -47,7 +62,7 @@
 }
 /*}}}*/
-int    Profiler::Id(void){ return -1; }/*{{{*/
+int  Profiler::Id(void){ return -1; }/*{{{*/
 /*}}}*/
-int Profiler::ObjectEnum(void){/*{{{*/
+int  Profiler::ObjectEnum(void){/*{{{*/
 
 	return ProfilerEnum;
Index: /issm/trunk-jpl/src/c/classes/Profiler.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Profiler.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/Profiler.h	(revision 18237)
@@ -42,5 +42,5 @@
 		int     Id();
 		int     ObjectEnum();
-		Object *copy()        {_error_("Not implemented yet"); };
+		Object *copy();
 		/*}}}*/
 		/*Profiler routines {{{*/
Index: /issm/trunk-jpl/src/c/classes/kriging/ExponentialVariogram.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/ExponentialVariogram.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/ExponentialVariogram.cpp	(revision 18237)
@@ -49,4 +49,8 @@
 }
 /*}}}*/
+Object* ExponentialVariogram::copy(void){/*{{{*/
+	   return new ExponentialVariogram(*this);
+}
+/*}}}*/
 
 /*Variogram function*/
Index: /issm/trunk-jpl/src/c/classes/kriging/ExponentialVariogram.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/ExponentialVariogram.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/ExponentialVariogram.h	(revision 18237)
@@ -26,5 +26,5 @@
 		int   Id(){_error_("Not implemented yet");}; 
 		int   ObjectEnum(){_error_("Not implemented yet");};
-		Object* copy(){_error_("Not implemented yet");};
+		Object* copy();
 
 		/*Variogram functions*/
Index: /issm/trunk-jpl/src/c/classes/kriging/GaussianVariogram.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/GaussianVariogram.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/GaussianVariogram.cpp	(revision 18237)
@@ -49,4 +49,8 @@
 }
 /*}}}*/
+Object* GaussianVariogram::copy(void){/*{{{*/
+	   return new GaussianVariogram(*this);
+}
+/*}}}*/
 
 /*Variogram function*/
Index: /issm/trunk-jpl/src/c/classes/kriging/GaussianVariogram.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/GaussianVariogram.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/GaussianVariogram.h	(revision 18237)
@@ -27,5 +27,5 @@
 		int   Id(){_error_("Not implemented yet");}; 
 		int   ObjectEnum(){_error_("Not implemented yet");};
-		Object* copy(){_error_("Not implemented yet");};
+		Object* copy();
 
 		/*Variogram functions*/
Index: /issm/trunk-jpl/src/c/classes/kriging/Observation.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/Observation.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/Observation.cpp	(revision 18237)
@@ -41,4 +41,14 @@
 }
 /*}}}*/
+Object* Observation::copy(void){/*{{{*/
+
+	Observation* observation = new Observation(this->x,this->y,this->xi,this->yi,this->index,this->value);
+
+	observation->weight = this->weight;
+
+	return (Object*) observation;
+
+}
+/*}}}*/
 
 /*Observations functions*/
Index: /issm/trunk-jpl/src/c/classes/kriging/Observation.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/Observation.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/Observation.h	(revision 18237)
@@ -27,5 +27,5 @@
 		int     Id()        {_error_("Not implemented yet"); };
 		int     ObjectEnum(){_error_("Not implemented yet"); };
-		Object *copy()      {_error_("Not implemented yet"); };
+		Object *copy();
 
 		/*Management*/
Index: /issm/trunk-jpl/src/c/classes/kriging/PowerVariogram.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/PowerVariogram.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/PowerVariogram.cpp	(revision 18237)
@@ -50,4 +50,8 @@
 }
 /*}}}*/
+Object* PowerVariogram::copy(void){/*{{{*/
+	   return new PowerVariogram(*this);
+}
+/*}}}*/
 
 /*Variogram function*/
Index: /issm/trunk-jpl/src/c/classes/kriging/PowerVariogram.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/PowerVariogram.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/PowerVariogram.h	(revision 18237)
@@ -26,5 +26,5 @@
 		int   Id(){_error_("Not implemented yet");}; 
 		int   ObjectEnum(){_error_("Not implemented yet");};
-		Object* copy(){_error_("Not implemented yet");};
+		Object* copy();
 
 		/*Variogram functions*/
Index: /issm/trunk-jpl/src/c/classes/kriging/Quadtree.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/Quadtree.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/Quadtree.cpp	(revision 18237)
@@ -498,4 +498,24 @@
 
 }/*}}}*/
+Object* Quadtree::QuadtreeBox::copy(void){/*{{{*/
+
+	   QuadtreeBox* qtreebox = new QuadtreeBox(*this);
+
+		if (this->box){	
+			for (int i=0; i<4; ++i){
+				if(this->box[i]) qtreebox->box[i] = reinterpret_cast<QuadtreeBox*>(this->box[i]->copy());
+				else qtreebox->box[i] = NULL;
+			}
+		}
+		if (this->obs){
+			for (int i=0; i<4; ++i){
+				if(this->obs[i]) qtreebox->obs[i] = reinterpret_cast<Observation*>(this->obs[i]->copy());
+				else qtreebox->obs[i] = NULL;
+			}
+		}
+
+		return (Object*) qtreebox;
+}
+/*}}}*/
 int Quadtree::QuadtreeBox::IsWithinRange(double x,double y,double range){/*{{{*/
 
Index: /issm/trunk-jpl/src/c/classes/kriging/Quadtree.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/Quadtree.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/Quadtree.h	(revision 18237)
@@ -30,5 +30,5 @@
 				int     Id()        {_error_("not implemented yet"); };
 				int     ObjectEnum(){_error_("not implemented yet"); };
-				Object *copy()      {_error_("not implemented yet"); };
+				Object *copy();
 
 				/*Methods*/
Index: /issm/trunk-jpl/src/c/classes/kriging/SphericalVariogram.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/SphericalVariogram.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/SphericalVariogram.cpp	(revision 18237)
@@ -49,4 +49,8 @@
 }
 /*}}}*/
+Object* SphericalVariogram::copy(void){/*{{{*/
+	return new SphericalVariogram(*this);
+}
+/*}}}*/
 
 /*Variogram function*/
Index: /issm/trunk-jpl/src/c/classes/kriging/SphericalVariogram.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/kriging/SphericalVariogram.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/classes/kriging/SphericalVariogram.h	(revision 18237)
@@ -26,5 +26,5 @@
 		int   Id(){_error_("Not implemented yet");}; 
 		int   ObjectEnum(){_error_("Not implemented yet");};
-		Object* copy(){_error_("Not implemented yet");};
+		Object* copy();
 
 		/*Variogram functions*/
Index: /issm/trunk-jpl/src/c/cores/DakotaSpawnCore.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/DakotaSpawnCore.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/cores/DakotaSpawnCore.cpp	(revision 18237)
@@ -51,6 +51,7 @@
 	if(counter==-1)return 0;
 
-	/*cast void_femmodel to FemModel: */
-	femmodel=reinterpret_cast<FemModel*>(void_femmodel);
+	/*cast void_femmodel to FemModel, and at the same time, make a copy, so we start this new core run for this specific sample 
+	 *with a brand new copy of the model, which has not been tempered with by previous dakota runs: */
+	femmodel=(reinterpret_cast<FemModel*>(void_femmodel))->copy();
 
 	/*retrieve parameters: */
@@ -80,4 +81,7 @@
 	/*Free ressources:*/
 	DakotaFree(&d_variables,&d_variables_descriptors,&responses_descriptors, d_numvariables, numresponsedescriptors);
+
+	/*Avoid leaks here: */
+	delete femmodel;
 
 	return 1; //this is critical! do not return 0, otherwise, dakota_core will stop running!
Index: /issm/trunk-jpl/src/c/cores/damage_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/damage_core.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/cores/damage_core.cpp	(revision 18237)
@@ -22,13 +22,7 @@
 	//first recover parameters common to all solutions
 	femmodel->parameters->FindParam(&save_results,SaveResultsEnum);
-	femmodel->parameters->FindParam(&dakota_analysis,QmuIsdakotaEnum);
 	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
 	femmodel->parameters->FindParam(&numoutputs,DamageEvolutionNumRequestedOutputsEnum);
 	if(numoutputs) femmodel->parameters->FindParam(&requested_outputs,&numoutputs,DamageEvolutionRequestedOutputsEnum);
-
-	if(dakota_analysis && solution_type!=TransientSolutionEnum){
-		femmodel->SetCurrentConfiguration(DamageEvolutionAnalysisEnum);
-		ResetConstraintsx(femmodel);
-	}
 
 	if(VerboseSolution()) _printf0_("   computing damage\n");
Index: /issm/trunk-jpl/src/c/cores/masstransport_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/masstransport_core.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/cores/masstransport_core.cpp	(revision 18237)
@@ -26,16 +26,8 @@
 	femmodel->parameters->FindParam(&isFS,FlowequationIsFSEnum);
 	femmodel->parameters->FindParam(&isfreesurface,MasstransportIsfreesurfaceEnum);
-	femmodel->parameters->FindParam(&dakota_analysis,QmuIsdakotaEnum);
 	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
 	femmodel->parameters->FindParam(&domaintype,DomainTypeEnum);
 	femmodel->parameters->FindParam(&numoutputs,MasstransportNumRequestedOutputsEnum);
 	if(numoutputs) femmodel->parameters->FindParam(&requested_outputs,&numoutputs,MasstransportRequestedOutputsEnum);
-
-	/*for qmu analysis, reinitialize velocity so that fake sensitivities do not show up as a result of a different restart of the convergence at each trial.*/
-	if(dakota_analysis && solution_type==MasstransportSolutionEnum){
-		InputDuplicatex(femmodel,QmuSurfaceEnum,SurfaceEnum);
-		InputDuplicatex(femmodel,QmuThicknessEnum,ThicknessEnum);
-		InputDuplicatex(femmodel,QmuBaseEnum,BaseEnum);
-	}
 
 	/*Calculate new Surface Mass Balance (SMB)*/
Index: /issm/trunk-jpl/src/c/cores/stressbalance_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/stressbalance_core.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/cores/stressbalance_core.cpp	(revision 18237)
@@ -30,17 +30,8 @@
 	femmodel->parameters->FindParam(&isHO,FlowequationIsHOEnum);
 	femmodel->parameters->FindParam(&isFS,FlowequationIsFSEnum);
-	femmodel->parameters->FindParam(&dakota_analysis,QmuIsdakotaEnum);
 	femmodel->parameters->FindParam(&save_results,SaveResultsEnum);
 	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
 	femmodel->parameters->FindParam(&numoutputs,StressbalanceNumRequestedOutputsEnum);
 	if(numoutputs) femmodel->parameters->FindParam(&requested_outputs,&numoutputs,StressbalanceRequestedOutputsEnum);
-
-	/*for qmu analysis, reinitialize velocity so that fake sensitivities do not show up as a result of a different restart of the convergence at each trial.*/
-	if(dakota_analysis && solution_type==StressbalanceSolutionEnum){
-		InputDuplicatex(femmodel,QmuVxEnum,VxEnum);
-		InputDuplicatex(femmodel,QmuVyEnum,VyEnum);
-		if(domaintype==Domain3DEnum) InputDuplicatex(femmodel,QmuVzEnum,VzEnum);
-		if(isFS) InputDuplicatex(femmodel,QmuPressureEnum,PressureEnum);
-	}
 
 	/*Compute slopes if necessary */
Index: /issm/trunk-jpl/src/c/cores/thermal_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/thermal_core.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/cores/thermal_core.cpp	(revision 18237)
@@ -22,20 +22,8 @@
 	/*first recover parameters common to all solutions*/
 	femmodel->parameters->FindParam(&save_results,SaveResultsEnum);
-	femmodel->parameters->FindParam(&dakota_analysis,QmuIsdakotaEnum);
 	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
 	femmodel->parameters->FindParam(&isenthalpy,ThermalIsenthalpyEnum);
 	femmodel->parameters->FindParam(&numoutputs,ThermalNumRequestedOutputsEnum);
 	if(numoutputs) femmodel->parameters->FindParam(&requested_outputs,&numoutputs,ThermalRequestedOutputsEnum);
-
-	if(dakota_analysis && solution_type!=TransientSolutionEnum){
-		InputDuplicatex(femmodel,QmuVxMeshEnum,VxMeshEnum);
-		InputDuplicatex(femmodel,QmuVyMeshEnum,VyMeshEnum);
-		InputDuplicatex(femmodel,QmuVzMeshEnum,VzMeshEnum);
-		InputDuplicatex(femmodel,QmuTemperatureEnum,TemperatureEnum);
-		InputDuplicatex(femmodel,QmuMeltingEnum,BasalforcingsGroundediceMeltingRateEnum);
-		InputDuplicatex(femmodel,QmuMaterialsRheologyBEnum,MaterialsRheologyBEnum);
-		femmodel->SetCurrentConfiguration(ThermalAnalysisEnum);
-		ResetConstraintsx(femmodel);
-	}
 
 	if(isenthalpy){
Index: /issm/trunk-jpl/src/c/cores/transient_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/transient_core.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/cores/transient_core.cpp	(revision 18237)
@@ -60,37 +60,4 @@
 	step=0;
 	time=starttime;
-
-	/*for qmu analysis, reinitialize velocity so that fake sensitivities do not show up as a result of a different restart of the convergence at each trial.*/
-	if(dakota_analysis){
-		if(isstressbalance){
-			InputDuplicatex(femmodel,QmuVxEnum,VxEnum);
-			InputDuplicatex(femmodel,QmuVyEnum,VyEnum);
-			if(domaintype==Domain3DEnum){
-				InputDuplicatex(femmodel,QmuVzEnum,VzEnum);
-				if(isFS)InputDuplicatex(femmodel,QmuPressureEnum,PressureEnum);
-			}
-		}
-		if(ismasstransport || isgroundingline){
-			InputDuplicatex(femmodel,QmuThicknessEnum,ThicknessEnum);
-			InputDuplicatex(femmodel,QmuSurfaceEnum,SurfaceEnum);
-			InputDuplicatex(femmodel,QmuBaseEnum,BaseEnum);
-			InputDuplicatex(femmodel,QmuMaskIceLevelsetEnum,MaskIceLevelsetEnum);
-		}
-		if(isgroundingline) InputDuplicatex(femmodel,QmuMaskGroundediceLevelsetEnum,MaskGroundediceLevelsetEnum);
-		if(isthermal && domaintype==Domain3DEnum){
-			//Update Vertex Position after updating Thickness and Bed
-			femmodel->SetCurrentConfiguration(MasstransportAnalysisEnum);
-			femmodel->UpdateVertexPositionsx();
-			InputDuplicatex(femmodel,QmuVxMeshEnum,VxMeshEnum);
-			InputDuplicatex(femmodel,QmuVyMeshEnum,VyMeshEnum);
-			InputDuplicatex(femmodel,QmuVzMeshEnum,VzMeshEnum);
-			InputDuplicatex(femmodel,QmuTemperatureEnum,TemperatureEnum);
-			InputDuplicatex(femmodel,QmuMeltingEnum,BasalforcingsGroundediceMeltingRateEnum);
-			InputDuplicatex(femmodel,QmuMaterialsRheologyBEnum,MaterialsRheologyBEnum);
-			//Reset Thermal Constraints
-			femmodel->SetCurrentConfiguration(ThermalAnalysisEnum);
-			ResetConstraintsx(femmodel);
-		}
-	}
 
 	while(time < finaltime - (yts*DBL_EPSILON)){ //make sure we run up to finaltime.
Index: /issm/trunk-jpl/src/c/datastructures/DataSet.cpp
===================================================================
--- /issm/trunk-jpl/src/c/datastructures/DataSet.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/datastructures/DataSet.cpp	(revision 18237)
@@ -27,4 +27,5 @@
 
 	sorted=0;
+	numsorted=0;
 	sorted_ids=NULL;
 	id_offsets=NULL;
@@ -41,29 +42,37 @@
 }
 /*}}}*/
-DataSet*   DataSet::Copy(void){/*{{{*/
-
-	vector<Object*>::iterator object;
+DataSet* DataSet::Copy(void){/*{{{*/
+
+	vector<Object*>::iterator obj;
 	Object* object_copy=NULL;
 
-	DataSet* copy=new DataSet(enum_type);
-
-	copy->sorted=sorted;
-	copy->presorted=presorted;
-	if(sorted_ids){
-		copy->sorted_ids=xNew<int>(objects.size());
-		xMemCpy<int>(copy->sorted_ids,sorted_ids,objects.size());
-	}
-	if(id_offsets){
-		copy->id_offsets=xNew<int>(objects.size());
-		xMemCpy<int>(copy->id_offsets,id_offsets,objects.size());
-	}
+	DataSet* copy=new DataSet(this->enum_type);
+
+	copy->sorted=this->sorted;
+	copy->numsorted=this->numsorted;
+	copy->presorted=this->presorted;
 
 	/*Now we need to deep copy the objects: */
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
-
-		/*Call echo on object: */
-		object_copy = (*object)->copy();
+	for ( obj=this->objects.begin() ; obj < this->objects.end(); obj++ ){
+		/*Call copy on object: */
+		object_copy = (*obj)->copy();
 		copy->AddObject(object_copy);
 	}
+
+	/*Build id_offsets and sorted_ids*/
+	int objsize = this->numsorted;
+	if(this->sorted && objsize>0 && this->id_offsets){	
+		/*Allocate new ids*/
+		copy->id_offsets=xNew<int>(objsize);
+		xMemCpy<int>(copy->id_offsets,this->id_offsets,objsize);
+	}
+	else copy->id_offsets=NULL;
+	if(this->sorted && objsize>0 && this->sorted_ids){
+		/*Allocate new ids*/
+		copy->sorted_ids=xNew<int>(objsize);
+		xMemCpy<int>(copy->sorted_ids,this->sorted_ids,objsize);
+	}
+	else copy->sorted_ids=NULL;
+
 	return copy;
 }
@@ -77,5 +86,5 @@
 
 /*Specific methods*/
-int  DataSet::AddObject(Object* object){/*{{{*/
+int   DataSet::AddObject(Object* object){/*{{{*/
 
 	_assert_(this);
@@ -102,5 +111,5 @@
 }
 /*}}}*/
-int  DataSet::DeleteObject(Object* object){/*{{{*/
+int   DataSet::DeleteObject(Object* object){/*{{{*/
 
 	vector<Object*>::iterator iterator;
@@ -116,5 +125,5 @@
 }
 /*}}}*/
-void DataSet::DeepEcho(){/*{{{*/
+void  DataSet::DeepEcho(){/*{{{*/
 
 	vector<Object*>::iterator object;
@@ -132,5 +141,5 @@
 }
 /*}}}*/
-void DataSet::Echo(){/*{{{*/
+void  DataSet::Echo(){/*{{{*/
 
 	vector<Object*>::iterator object;
@@ -149,5 +158,5 @@
 }
 /*}}}*/
-int  DataSet::GetEnum(){/*{{{*/
+int   DataSet::GetEnum(){/*{{{*/
 	return enum_type;
 }
@@ -176,5 +185,5 @@
 
 	_assert_(this);
-	if(!sorted)_error_("trying to binary search on a non-sorted dataset!");
+	if(!sorted || objects.size()>numsorted)_error_("trying to binary search on a non-sorted dataset!");
 
 	/*Carry out a binary search on the sorted_ids: */
@@ -193,5 +202,5 @@
 }
 /*}}}*/
-void DataSet::Presort(){/*{{{*/
+void  DataSet::Presort(){/*{{{*/
 
 	/*vector of objects is already sorted, just allocate the sorted ids and their
@@ -200,6 +209,6 @@
 
 		/*Delete existing ids*/
-		xDelete<int>(sorted_ids);
-		xDelete<int>(id_offsets);
+		if(sorted_ids) xDelete<int>(sorted_ids);
+		if(id_offsets) xDelete<int>(id_offsets);
 
 		/*Allocate new ids*/
@@ -215,8 +224,9 @@
 
 	/*set sorted flag: */
+	numsorted=objects.size();
 	sorted=1;
 }
 /*}}}*/
-int  DataSet::Size(void){/*{{{*/
+int   DataSet::Size(void){/*{{{*/
 	_assert_(this!=NULL);
 
@@ -224,5 +234,5 @@
 }
 /*}}}*/
-void DataSet::Sort(){/*{{{*/
+void  DataSet::Sort(){/*{{{*/
 
 	/*Only sort if we are not already sorted: */
Index: /issm/trunk-jpl/src/c/datastructures/DataSet.h
===================================================================
--- /issm/trunk-jpl/src/c/datastructures/DataSet.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/datastructures/DataSet.h	(revision 18237)
@@ -25,4 +25,5 @@
 		int             sorted;
 		int             presorted;
+		int             numsorted;
 		int*            sorted_ids;
 		int*            id_offsets;
Index: /issm/trunk-jpl/src/c/main/issm.cpp
===================================================================
--- /issm/trunk-jpl/src/c/main/issm.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/main/issm.cpp	(revision 18237)
@@ -23,4 +23,7 @@
 
 	/*Wrap up: */
+	femmodel->CleanUp();
+
+	/*Delete Model: */
 	delete femmodel;
 
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp	(revision 18236)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateElementsVerticesAndMaterials.cpp	(revision 18237)
@@ -56,8 +56,6 @@
 				case 2:
 					elements->InputDuplicate(MaterialsRheologyBEnum,MaterialsRheologyBbarEnum);
-					if(dakota_analysis) elements->InputDuplicate(MaterialsRheologyBbarEnum,QmuMaterialsRheologyBEnum);
 					break;
 				case 3:
-					if(dakota_analysis) elements->InputDuplicate(MaterialsRheologyBEnum,QmuMaterialsRheologyBEnum); 
 					break;
 				default:
@@ -74,8 +72,6 @@
 					elements->InputDuplicate(MaterialsRheologyBEnum,MaterialsRheologyBbarEnum);
 					elements->InputDuplicate(DamageDEnum,DamageDbarEnum);
-					if(dakota_analysis) elements->InputDuplicate(MaterialsRheologyBbarEnum,QmuMaterialsRheologyBEnum);
 					break;
 				case 3:
-					if(dakota_analysis) elements->InputDuplicate(MaterialsRheologyBEnum,QmuMaterialsRheologyBEnum); 
 					break;
 				default:
Index: /issm/trunk-jpl/src/c/toolkits/issm/Bucket.h
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/issm/Bucket.h	(revision 18236)
+++ /issm/trunk-jpl/src/c/toolkits/issm/Bucket.h	(revision 18237)
@@ -125,5 +125,7 @@
 		} /*}}}*/
 		Object *copy()        {/*{{{*/
-			_error_("Not implemented yet (similar to Elements)"); };
+			if (this->type==MATRIX_BUCKET) return new Bucket(this->m,this->idxm,this->n,this->idxn,this->values,this->mode);
+			else if (this->type==VECTOR_BUCKET) return new Bucket(this->m,this->idxm,this->values,this->mode);
+			else _error_("No Copy of Bucket because its type is invalid."); };
 		/*}}}*/
 
