Index: ../trunk-jpl/src/c/analyses/LevelsetAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/LevelsetAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/LevelsetAnalysis.cpp	(revision 18521)
@@ -398,7 +398,7 @@
 	
 	/* set NaN on elements intersected by zero levelset */
 	for(i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		if(element->IsZeroLevelset(MaskIceLevelsetEnum))
 			for(k=0;k<element->GetNumberOfVertices();k++)
 				vec_dist_zerolevelset->SetValue(element->vertices[k]->Sid(),NAN,INS_VAL); 
@@ -406,7 +406,7 @@
 
 	/* set distance on elements intersected by zero levelset */
 	for(i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		if(element->IsZeroLevelset(MaskIceLevelsetEnum)){
 			SetDistanceToZeroLevelsetElement(vec_dist_zerolevelset, element);
 
Index: ../trunk-jpl/src/c/analyses/SeaiceAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/SeaiceAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/SeaiceAnalysis.cpp	(revision 18521)
@@ -371,7 +371,7 @@
 	/*Step 1: update mask of active nodes*/
 	mask=new Vector<IssmDouble>(femmodel->nodes->NumberOfNodes(SeaiceAnalysisEnum));
 	for (int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		/*Get current concentration of element and decide whether it is an active element*/
 		int    numnodes            = element->GetNumberOfNodes();
@@ -389,7 +389,7 @@
 	/*Update node activation accordingly*/
 	int counter =0;
 	for(int i=0;i<femmodel->nodes->Size();i++){
-		Node* node=dynamic_cast<Node*>(femmodel->nodes->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(femmodel->nodes->GetObjectByOffset(i));
 		if(node->InAnalysis(SeaiceAnalysisEnum)){
 			if(serial_mask[node->Sid()]==1.){
 				node->Activate();
@@ -551,7 +551,7 @@
 
 	/*Loop over the elements of this partition and update accordingly*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		/*Get Mohr-Coulomb parameters*/
 		compression_coef = element->GetMaterialParameter(MaterialsCompressionCoefEnum);
@@ -643,7 +643,7 @@
 
 	/*Loop over the elements of this partition and update accordingly*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		/*Get some inputs needed for the update*/
 		element->GetVerticesCoordinates(&xyz_list);
Index: ../trunk-jpl/src/c/analyses/MasstransportAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/MasstransportAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/MasstransportAnalysis.cpp	(revision 18521)
@@ -795,7 +795,7 @@
 
 	/*Create and assemble matrix*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element*       element = dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element*       element = xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		ElementMatrix* MLe     = this->CreateMassMatrix(element);
 		if(MLe){
 			MLe->Lump();
@@ -816,7 +816,7 @@
 
 	/*Create and assemble matrix*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element*       element = dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element*       element = xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		ElementMatrix* MLe     = this->CreateMassMatrix(element);
 		if(MLe){
 			MLe->AddToGlobal(Mff);
@@ -879,7 +879,7 @@
 
 	/*Create and assemble matrix*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element*       element = dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element*       element = xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		ElementMatrix* Ke     = this->CreateFctKMatrix(element);
 		if(Ke) Ke->AddToGlobal(Kff,Kfs);
 		delete Ke;
Index: ../trunk-jpl/src/c/analyses/LsfReinitializationAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/LsfReinitializationAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/LsfReinitializationAnalysis.cpp	(revision 18521)
@@ -368,7 +368,7 @@
 
 	/* deactivate all spcs */
 	for(i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		for(k=0;k<element->GetNumberOfNodes();k++){
 			node=element->GetNode(k);
 			if(node->IsActive()){
@@ -381,7 +381,7 @@
 
 	/* reactivate spcs on elements intersected by zero levelset */
 	for(i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		if(element->IsZeroLevelset(MaskIceLevelsetEnum)){
 			/*iterate over nodes and set spc */
 			numnodes=element->GetNumberOfNodes();
@@ -413,7 +413,7 @@
 	
 	/* set distance on elements intersected by zero levelset */
 	for(i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		if(element->IsZeroLevelset(MaskIceLevelsetEnum)){
 			SetDistanceToZeroLevelsetElement(vec_dist_zerolevelset, element);
 		}
Index: ../trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/StressbalanceAnalysis.cpp	(revision 18521)
@@ -5031,7 +5031,7 @@
 	parameters->FindParam(&dim,DomainDimensionEnum);
 
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 
 		/*Get inputs and parameters*/
 		element->GetVerticesCoordinates(&xyz_list);
@@ -5205,7 +5205,7 @@
 	else       tausize = 6;
 
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 
 		/*Get inputs and parameters*/
 		element->GetVerticesCoordinates(&xyz_list);
@@ -5418,7 +5418,7 @@
 	else       tausize = 6;
 
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 
 		/*Get inputs and parameters*/
 		element->GetVerticesCoordinates(&xyz_list);
@@ -6787,7 +6787,7 @@
 
 	/*Cast gauss to GaussPenta*/
 	_assert_(gauss_in->Enum()==GaussPentaEnum);
-	GaussPenta* gauss = dynamic_cast<GaussPenta*>(gauss_in);
+	GaussPenta* gauss = xDynamicCast<GaussPenta*>(gauss_in);
 
 	/*Get basis in actual coordinate system: */
 	basis[0]=gauss->coord1*(1-gauss->coord4)/2.0;
@@ -6836,7 +6836,7 @@
 
 	/*Cast gauss to GaussPenta*/
 	_assert_(gauss_in->Enum()==GaussPentaEnum);
-	GaussPenta* gauss = dynamic_cast<GaussPenta*>(gauss_in);
+	GaussPenta* gauss = xDynamicCast<GaussPenta*>(gauss_in);
 
 	/*Get basis in actual coordinate system: */
 	basis[0]=gauss->coord1*(1-gauss->coord4)/2.0;
@@ -6935,7 +6935,7 @@
 
 	/*Cast gauss to GaussPenta*/
 	_assert_(gauss_in->Enum()==GaussPentaEnum);
-	GaussPenta* gauss = dynamic_cast<GaussPenta*>(gauss_in);
+	GaussPenta* gauss = xDynamicCast<GaussPenta*>(gauss_in);
 
 	/*Get basis in actual coordinate system: */
 	basis[0]=gauss->coord1*(1-gauss->coord4)/2.0;
@@ -6973,7 +6973,7 @@
 
 	/*Cast gauss to GaussPenta*/
 	_assert_(gauss_in->Enum()==GaussPentaEnum);
-	GaussPenta* gauss = dynamic_cast<GaussPenta*>(gauss_in);
+	GaussPenta* gauss = xDynamicCast<GaussPenta*>(gauss_in);
 
 	/*Get basis in actual coordinate system: */
 	basis[0]=gauss->coord1*(1-gauss->coord4)/2.0;
Index: ../trunk-jpl/src/c/analyses/HydrologyDCInefficientAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/HydrologyDCInefficientAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/HydrologyDCInefficientAnalysis.cpp	(revision 18521)
@@ -691,7 +691,7 @@
 	Element* element=NULL;
 
 	for(int i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		int numvertices = element->GetNumberOfVertices();
 		Input* node_mask_input = element->GetInput(HydrologydcMaskEplactiveNodeEnum);
Index: ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp	(revision 18521)
@@ -879,7 +879,7 @@
 	if(isdrainage){
 		/*Drain excess water fraction in ice column: */
 		for(i=0;i<femmodel->elements->Size();i++){
-			Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+			Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 			DrainWaterfractionIcecolumn(element);
 		}
 	}
@@ -887,7 +887,7 @@
 	if(computebasalmeltingrates){
 		/*Compute basal melting rates: */
 		for(i=0;i<femmodel->elements->Size();i++){
-			Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+			Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 			ComputeBasalMeltingrate(element);
 		}
 	}
@@ -897,7 +897,7 @@
 		femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
 		if(solution_type==TransientSolutionEnum){
 			for(i=0;i<femmodel->elements->Size();i++){
-				Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+				Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 				UpdateBasalConstraints(element);
 			}
 		}
Index: ../trunk-jpl/src/c/analyses/FreeSurfaceBaseAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/FreeSurfaceBaseAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/FreeSurfaceBaseAnalysis.cpp	(revision 18521)
@@ -376,7 +376,7 @@
 
 	for(int i=0;i<femmodel->elements->Size();i++){
 
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		if(!element->IsOnBase()) continue;
 
 		int             numnodes = element->GetNumberOfNodes();
Index: ../trunk-jpl/src/c/analyses/ExtrapolationAnalysis.cpp
===================================================================
--- ../trunk-jpl/src/c/analyses/ExtrapolationAnalysis.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/analyses/ExtrapolationAnalysis.cpp	(revision 18521)
@@ -349,7 +349,7 @@
 void ExtrapolationAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
 
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		this->SetConstraintsOnIce(element);
 	}
 }/*}}}*/
Index: ../trunk-jpl/src/c/main/kriging.cpp
===================================================================
--- ../trunk-jpl/src/c/main/kriging.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/main/kriging.cpp	(revision 18521)
@@ -57,7 +57,7 @@
 		results->AddObject(new GenericExternalResult<double*>(results->Size()+1,0,predictions,ninterp,1,1,0));
 		results->AddObject(new GenericExternalResult<double*>(results->Size()+1,1,error,ninterp,1,1,0));
 		for(int i=0;i<results->Size();i++){
-			ExternalResult* result=dynamic_cast<ExternalResult*>(results->GetObjectByOffset(i));
+			ExternalResult* result=xDynamicCast<ExternalResult*>(results->GetObjectByOffset(i));
 			result->WriteData(output_fid,1);
 		}
 		pfclose(output_fid,outbinfilename);
Index: ../trunk-jpl/src/c/shared/Numerics/recast.h
===================================================================
--- ../trunk-jpl/src/c/shared/Numerics/recast.h	(revision 18520)
+++ ../trunk-jpl/src/c/shared/Numerics/recast.h	(revision 18521)
@@ -39,4 +39,15 @@
 
 #endif
 
+/*Morlighem's change: we do not want dynamic_casts because of performance
+ * issue, so for now, we just use C-like cast*/
+template<class To,class From> To xDynamicCast(const From& from) {
+
+	/*C-like cast (fast but not safe)*/
+	return (To) from;
+
+	/*C++ dynamic_cast, poor performance but safer*/
+	//return dynamic_cast<To>(from);
+}
+
 #endif
Index: ../trunk-jpl/src/c/modules/SetActiveNodesLSMx/SetActiveNodesLSMx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SetActiveNodesLSMx/SetActiveNodesLSMx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SetActiveNodesLSMx/SetActiveNodesLSMx.cpp	(revision 18521)
@@ -21,7 +21,7 @@
 	femmodel->parameters->FindParam(&domaintype,DomainTypeEnum);
 
 	for(i=0;i<elements->Size();i++){
-		Element    *element  = dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element    *element  = xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		int         numnodes = element->GetNumberOfNodes();
 		IssmDouble *mask     = xNew<IssmDouble>(numnodes);
 		// include switch for elements with multiple different sets of nodes
@@ -103,7 +103,7 @@
 	Vector<IssmDouble>* vec_mask_ice=new Vector<IssmDouble>(numvertices); //vertices that have ice at next time step
 	/*Fill vector with values: */
 	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		SetMaskOfIceElement(vec_mask_ice, element);
 	}
 
Index: ../trunk-jpl/src/c/modules/InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.cpp	(revision 18521)
@@ -19,7 +19,7 @@
 
 		/*Update elements, nodes, loads and materials from inputs: */
 		for(i=0;i<femmodel->elements->Size();i++){
-			Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+			Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 			element->InputUpdateFromMatrixDakota(matrix,nrows,ncols,name,type);
 		}
 		for(i=0;i<femmodel->loads->Size();i++){
Index: ../trunk-jpl/src/c/modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp	(revision 18521)
@@ -40,7 +40,7 @@
 
 	/*loop on each element, and add contribution of the element to the partition (surface weighted average): */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->AverageOntoPartition(partition_contributions,partition_areas,vertex_response,qmu_part);
 	}
 
Index: ../trunk-jpl/src/c/modules/InputUpdateFromVectorx/InputUpdateFromVectorx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputUpdateFromVectorx/InputUpdateFromVectorx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputUpdateFromVectorx/InputUpdateFromVectorx.cpp	(revision 18521)
@@ -19,7 +19,7 @@
 
 	/*Update elements, nodes, loads and materials from inputs: */
 	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputUpdateFromVector(vector,name,type);
 	}
 	for(i=0;i<femmodel->loads->Size();i++){
Index: ../trunk-jpl/src/c/modules/OutputDefinitionsResponsex/OutputDefinitionsResponsex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/OutputDefinitionsResponsex/OutputDefinitionsResponsex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/OutputDefinitionsResponsex/OutputDefinitionsResponsex.cpp	(revision 18521)
@@ -19,7 +19,7 @@
 	/*Now, go through the output definitions, and retrieve the object which corresponds to our requested response, output_string: */
 	for(int i=0;i<output_definitions->Size();i++){
 		
-		definition=dynamic_cast<Definition*>(output_definitions->GetObjectByOffset(i));
+		definition=xDynamicCast<Definition*>(output_definitions->GetObjectByOffset(i));
 
 		char* name = definition->Name();
 		if (strcmp(name,output_string)==0){
Index: ../trunk-jpl/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 18521)
@@ -46,7 +46,7 @@
 
 	/*Migrate grounding line : */
 	for(int i=0;i<elements->Size();i++){
-		element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->MigrateGroundingLine(phi_ungrounding);
 	}
 
@@ -71,7 +71,7 @@
 
 	/*Fill vector vertices_potentially_floating: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->FSContactMigration(vertexgrounded,vertexfloating);
 	}
 
@@ -119,7 +119,7 @@
 
 	/*Fill vector vertices_potentially_floating: */
 	for(i=0;i<elements->Size();i++){
-		element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->PotentialUngrounding(vec_vertices_potentially_ungrounding);
 	}
 
@@ -147,7 +147,7 @@
 	/*recover vec_phi*/
 	vec_phi=new Vector<IssmDouble>(vertices->NumberOfVertices());
 	for(i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->GetVectorFromInputs(vec_phi,MaskGroundediceLevelsetEnum);
 	}
 	vec_phi->Assemble();
@@ -161,7 +161,7 @@
 
 		/*Figure out if any of the nodes of the element will be floating -> elements neighbouting the floating ice*/
 		for(i=0;i<elements->Size();i++){
-			element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+			element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 			vec_elements_neighboring_floatingice->SetValue(element->Sid(),element->IsNodeOnShelfFromFlags(phi)?1.0:0.0,INS_VAL);
 		}
 
@@ -172,7 +172,7 @@
 		/*Go through elements_neighboring_floatingce, and update vector of the nodes that will start floating*/
 		local_nflipped=0;
 		for(i=0;i<elements->Size();i++){
-			element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+			element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 			if(reCast<int,IssmDouble>(elements_neighboring_floatingce[element->Sid()])){
 				local_nflipped+=element->UpdatePotentialUngrounding(vertices_potentially_ungrounding,vec_phi,phi);
 			}
Index: ../trunk-jpl/src/c/modules/AllocateSystemMatricesx/AllocateSystemMatricesx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/AllocateSystemMatricesx/AllocateSystemMatricesx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/AllocateSystemMatricesx/AllocateSystemMatricesx.cpp	(revision 18521)
@@ -133,7 +133,7 @@
 
 	k=0;
 	for(i=0;i<femmodel->elements->Size();i++){
-		element = dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element = xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		lidlist = xNew<int>(element->GetNumberOfNodes());
 		element->GetNodesLidList(lidlist);
 
@@ -156,7 +156,7 @@
 	count2offset_l = xNew<int>(femmodel->loads->Size(configuration_type)*numnodesperload);
 	k=0;
 	for(i=0;i<femmodel->loads->Size();i++){
-		load = dynamic_cast<Load*>(femmodel->loads->GetObjectByOffset(i));
+		load = xDynamicCast<Load*>(femmodel->loads->GetObjectByOffset(i));
 		if(!load->InAnalysis(configuration_type)) continue;
 		lidlist = xNew<int>(load->GetNumberOfNodes());
 		load->GetNodesLidList(lidlist);
@@ -189,7 +189,7 @@
 
 	/*Create connectivity vector*/
 	for(i=0;i<femmodel->nodes->Size();i++){
-		Node* node=dynamic_cast<Node*>(femmodel->nodes->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(femmodel->nodes->GetObjectByOffset(i));
 		if(node->InAnalysis(configuration_type)){
 
 			/*Reinitialize flags to false*/
@@ -213,7 +213,7 @@
 			//}
 			for(j=head_e[node->Lid()];j!=-1;j=next_e[j]){
 				offset=count2offset_e[j];
-				element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(offset));
+				element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(offset));
 				element->SetwiseNodeConnectivity(&d_nz,&o_nz,node,flags,flagsindices,set1enum,set2enum);
 				if(node->IsClone()){
 					connectivity_clone[node->Sid()]+=d_nz+o_nz;
@@ -225,7 +225,7 @@
 			}
 			for(j=head_l[node->Lid()];j!=-1;j=next_l[j]){
 				offset=count2offset_l[j];
-				load=dynamic_cast<Load*>(femmodel->loads->GetObjectByOffset(offset));
+				load=xDynamicCast<Load*>(femmodel->loads->GetObjectByOffset(offset));
 				load->SetwiseNodeConnectivity(&d_nz,&o_nz,node,flags,flagsindices,set1enum,set2enum);
 				if(node->IsClone()){
 					connectivity_clone[node->Sid()]+=d_nz+o_nz;
@@ -255,7 +255,7 @@
 		d_nnz=xNew<int>(m);
 		o_nnz=xNew<int>(m);
 		for(i=0;i<femmodel->nodes->Size();i++){
-			Node* node=dynamic_cast<Node*>(femmodel->nodes->GetObjectByOffset(i));
+			Node* node=xDynamicCast<Node*>(femmodel->nodes->GetObjectByOffset(i));
 			if(node->InAnalysis(configuration_type) && !node->IsClone()){
 				for(j=0;j<node->indexing.fsize;j++){
 					_assert_(count<m);
Index: ../trunk-jpl/src/c/modules/InputDuplicatex/InputDuplicatex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputDuplicatex/InputDuplicatex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputDuplicatex/InputDuplicatex.cpp	(revision 18521)
@@ -10,7 +10,7 @@
 void InputDuplicatex(FemModel* femmodel,int original_enum, int new_enum){
 	/*Go through elemnets, and ask to reinitialie the input: */
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputDuplicate(original_enum,new_enum);
 	}
 }
Index: ../trunk-jpl/src/c/modules/InputExtrudex/InputExtrudex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputExtrudex/InputExtrudex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputExtrudex/InputExtrudex.cpp	(revision 18521)
@@ -9,7 +9,7 @@
 
 void InputExtrudex(FemModel* femmodel,int input_enum,int start){
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputExtrude(input_enum,start);
 	}
 }
Index: ../trunk-jpl/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp	(revision 18521)
@@ -31,7 +31,7 @@
 	/*Go through elements and plug solution: */
 	Analysis* analysis = EnumToAnalysis(analysisenum);
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		analysis->GetSolutionFromInputs(solution,element);
 	}
 	delete analysis;
Index: ../trunk-jpl/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp	(revision 18521)
@@ -16,7 +16,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		J+=SurfaceAverageVelMisfit(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/InputScalex/InputScalex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputScalex/InputScalex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputScalex/InputScalex.cpp	(revision 18521)
@@ -14,7 +14,7 @@
 
 	/*Go through elemnets, and ask to reinitialie the input: */
 	for(i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->InputScale(enum_type,scale_factor);
 	}
 
Index: ../trunk-jpl/src/c/modules/SurfaceAreax/SurfaceAreax.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SurfaceAreax/SurfaceAreax.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SurfaceAreax/SurfaceAreax.cpp	(revision 18521)
@@ -19,7 +19,7 @@
 
 	/*Compute gradients: */
 	for(int i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		S+=element->SurfaceArea();
 	}
 
Index: ../trunk-jpl/src/c/modules/InputUpdateFromSolutionx/InputUpdateFromSolutionx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputUpdateFromSolutionx/InputUpdateFromSolutionx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputUpdateFromSolutionx/InputUpdateFromSolutionx.cpp	(revision 18521)
@@ -29,7 +29,7 @@
 
 	Analysis* analysis = EnumToAnalysis(analysisenum);
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		analysis->InputUpdateFromSolution(solution,element);
 	}
 	delete analysis;
Index: ../trunk-jpl/src/c/modules/GetVectorFromInputsx/GetVectorFromInputsx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/GetVectorFromInputsx/GetVectorFromInputsx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/GetVectorFromInputsx/GetVectorFromInputsx.cpp	(revision 18521)
@@ -18,7 +18,7 @@
 
 		/*Look up in elements*/
 		for(i=0;i<femmodel->elements->Size();i++){
-			Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+			Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 			element->GetVectorFromInputs(vector,name);
 		}
 	}
Index: ../trunk-jpl/src/c/modules/ThicknessAlongGradientx/ThicknessAlongGradientx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ThicknessAlongGradientx/ThicknessAlongGradientx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/ThicknessAlongGradientx/ThicknessAlongGradientx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=ThicknessAlongGradient(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/NodalValuex/NodalValuex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/NodalValuex/NodalValuex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/NodalValuex/NodalValuex.cpp	(revision 18521)
@@ -19,7 +19,7 @@
 	/*This is the vertex id for which we want to collect the data. Go through elements, and for each 
 	 *element, figure out  if they hold the vertex, and the data. If so, return it: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		found=element->NodalValue(&value,index,natureofdataenum);
 		if(found){
 			cpu_found=IssmComm::GetRank();
Index: ../trunk-jpl/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp	(revision 18521)
@@ -23,7 +23,7 @@
 
 	if(VerboseMProcessor()) _printf0_("      Configuring elements...\n");
 	for(i=0;i<elements->Size();i++){
-		element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->Configure(elements,loads,nodes,vertices,materials,parameters);
 	}
 	if(VerboseMProcessor()) _printf0_("      Configuring loads...\n");
Index: ../trunk-jpl/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=ThicknessAbsMisfit(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp	(revision 18521)
@@ -21,7 +21,7 @@
 
 	/*Update elements, nodes, loads and materials from inputs: */
 	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputUpdateFromVectorDakota(vector,name,type);
 	}
 	for(i=0;i<femmodel->loads->Size();i++){
Index: ../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 18521)
@@ -83,7 +83,7 @@
 
 					/*Now, for this particular misfit object, make sure we plug into the elements: the observation, and the weights.*/
 					for(i=0;i<elements->Size();i++){
-						Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+						Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 						element->InputCreate(misfit_observation_s[j], iomodel,misfit_observation_M_s[j],misfit_observation_N_s[j],1,misfit_observation_enum_s[j],7);
 						element->InputCreate(misfit_weights_s[j], iomodel,misfit_weights_M_s[j],misfit_weights_N_s[j],1,misfit_weights_enum_s[j],7);
 					}
Index: ../trunk-jpl/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=SurfaceLogVxVyMisfit(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/InputControlUpdatex/InputControlUpdatex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputControlUpdatex/InputControlUpdatex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputControlUpdatex/InputControlUpdatex.cpp	(revision 18521)
@@ -11,7 +11,7 @@
 
 	/*Go through elemnets, and ask to carry out the operation on inputs: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->InputControlUpdate(scalar,save_parameter);
 	}
 }
Index: ../trunk-jpl/src/c/modules/SystemMatricesx/SystemMatricesx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SystemMatricesx/SystemMatricesx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SystemMatricesx/SystemMatricesx.cpp	(revision 18521)
@@ -39,7 +39,7 @@
 
 		/*Get complete stiffness matrix without penalties*/
 		for (i=0;i<femmodel->elements->Size();i++){
-			element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+			element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 			ElementMatrix* Ke = analysis->CreateKMatrix(element);
 			ElementVector* pe = analysis->CreatePVector(element);
 			element->ReduceMatrices(Ke,pe);
@@ -49,7 +49,7 @@
 		}
 
 		for (i=0;i<femmodel->loads->Size();i++){
-			load=dynamic_cast<Load*>(femmodel->loads->GetObjectByOffset(i));
+			load=xDynamicCast<Load*>(femmodel->loads->GetObjectByOffset(i));
 			if(load->InAnalysis(configuration_type)) load->CreateKMatrix(Kff_temp,NULL);
 		}
 		Kff_temp->Assemble();
@@ -70,7 +70,7 @@
 
 	/*Fill stiffness matrix and load vector from elements*/
 	for (i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		ElementMatrix* Ke = analysis->CreateKMatrix(element);
 		ElementVector* pe = analysis->CreatePVector(element);
 		element->ReduceMatrices(Ke,pe);
@@ -84,7 +84,7 @@
 
 	/*Fill stiffness matrix and load vector from loads*/
 	for(i=0;i<femmodel->loads->Size();i++){
-		load=dynamic_cast<Load*>(femmodel->loads->GetObjectByOffset(i));
+		load=xDynamicCast<Load*>(femmodel->loads->GetObjectByOffset(i));
 		if(load->InAnalysis(configuration_type)){
 			load->CreateKMatrix(Kff,Kfs);
 			load->CreatePVector(pf);
@@ -94,7 +94,7 @@
 	/*Now deal with penalties (only in loads)*/
 	if(femmodel->loads->IsPenalty(configuration_type)){
 		for (i=0;i<femmodel->loads->Size();i++){
-			load=dynamic_cast<Load*>(femmodel->loads->GetObjectByOffset(i));
+			load=xDynamicCast<Load*>(femmodel->loads->GetObjectByOffset(i));
 			if(load->InAnalysis(configuration_type)){
 				load->PenaltyCreateKMatrix(Kff,Kfs,kmax);
 				load->PenaltyCreatePVector(pf,kmax);
@@ -105,7 +105,7 @@
 	/*Create dof vector for stiffness matrix preconditioning*/
 	if(pdf){
 		for(i=0;i<femmodel->elements->Size();i++){
-			element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+			element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 			ElementVector* de=analysis->CreateDVector(element);
 			if(de) de->InsertIntoGlobal(df);
 			delete de;
Index: ../trunk-jpl/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=SurfaceLogVelMisfit(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=SurfaceRelVelMisfit(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/CreateJacobianMatrixx/CreateJacobianMatrixx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/CreateJacobianMatrixx/CreateJacobianMatrixx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/CreateJacobianMatrixx/CreateJacobianMatrixx.cpp	(revision 18521)
@@ -28,7 +28,7 @@
 
 	/*Create and assemble matrix*/
 	for(i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		ElementMatrix* Je = analysis->CreateJacobianMatrix(element);
 		if(Je) Je->AddToGlobal(Jff);
 		delete Je;
Index: ../trunk-jpl/src/c/modules/FloatingiceMeltingRatex/FloatingiceMeltingRatex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/FloatingiceMeltingRatex/FloatingiceMeltingRatex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/FloatingiceMeltingRatex/FloatingiceMeltingRatex.cpp	(revision 18521)
@@ -32,7 +32,7 @@
 void LinearFloatingiceMeltingRatex(FemModel* femmodel){/*{{{*/
 
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->LinearFloatingiceMeltingRate();
 	}
 
Index: ../trunk-jpl/src/c/modules/SurfaceMassBalancex/SurfaceMassBalancex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SurfaceMassBalancex/SurfaceMassBalancex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SurfaceMassBalancex/SurfaceMassBalancex.cpp	(revision 18521)
@@ -63,7 +63,7 @@
 
 	/*Loop over all the elements of this partition*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		/*Allocate all arrays*/
 		int         numvertices = element->GetNumberOfVertices();
@@ -112,7 +112,7 @@
 void Delta18oParameterizationx(FemModel* femmodel){/*{{{*/
 
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->Delta18oParameterization();
 	}
 
@@ -203,7 +203,7 @@
 	//     *******END initialize PDD
 
 	for(i=0;i<femmodel->elements->Size();i++){
-		element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->PositiveDegreeDay(pdds,pds,signorm);
 	}
 
@@ -233,7 +233,7 @@
     
 	/*Loop over all the elements of this partition*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		/*Get reference SMB (uncorrected) and allocate all arrays*/
 		int         numvertices = element->GetNumberOfVertices();
@@ -291,7 +291,7 @@
 
 	/*Loop over all the elements of this partition*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		/*Allocate all arrays*/
 		int         numvertices = element->GetNumberOfVertices();
@@ -332,7 +332,7 @@
 
 	/*Loop over all the elements of this partition*/
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 
 		/*Allocate all arrays*/
 		int         numvertices = element->GetNumberOfVertices();
Index: ../trunk-jpl/src/c/modules/ResetFSBasalBoundaryConditionx/ResetFSBasalBoundaryConditionx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ResetFSBasalBoundaryConditionx/ResetFSBasalBoundaryConditionx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/ResetFSBasalBoundaryConditionx/ResetFSBasalBoundaryConditionx.cpp	(revision 18521)
@@ -11,7 +11,7 @@
 	Element *element = NULL;
 
 	for (int i=0;i<elements->Size();i++){
-		element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->ResetFSBasalBoundaryCondition();
 	}
 
Index: ../trunk-jpl/src/c/modules/InputDepthAverageAtBasex/InputDepthAverageAtBasex.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputDepthAverageAtBasex/InputDepthAverageAtBasex.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputDepthAverageAtBasex/InputDepthAverageAtBasex.cpp	(revision 18521)
@@ -9,7 +9,7 @@
 
 void InputDepthAverageAtBasex(FemModel* femmodel,int original_enum, int new_enum){
 	for(int i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputDepthAverageAtBase(original_enum,new_enum);
 	}
 }
Index: ../trunk-jpl/src/c/modules/InputUpdateFromConstantx/InputUpdateFromConstantx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/InputUpdateFromConstantx/InputUpdateFromConstantx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/InputUpdateFromConstantx/InputUpdateFromConstantx.cpp	(revision 18521)
@@ -13,7 +13,7 @@
 
 	/*Elements and loads drive the update: */
 	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputUpdateFromConstant(constant,name);
 	}
 
@@ -34,7 +34,7 @@
 
 	/*Elements and loads drive the update: */
 	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputUpdateFromConstant(constant,name);
 	}
 
@@ -55,7 +55,7 @@
 
 	/*Elements and loads drive the update: */
 	for(i=0;i<femmodel->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
 		element->InputUpdateFromConstant(constant,name);
 	}
 
@@ -77,7 +77,7 @@
 
 	/*Elements and loads drive the update: */
 	for(i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->InputUpdateFromConstant(constant,name);
 	}
 }
Index: ../trunk-jpl/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=SurfaceAbsVelMisfit(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=DragCoefficientAbsGradient(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/RheologyBbarAbsGradientx/RheologyBbarAbsGradientx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/RheologyBbarAbsGradientx/RheologyBbarAbsGradientx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/RheologyBbarAbsGradientx/RheologyBbarAbsGradientx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=RheologyBbarAbsGradient(element);
 	}
 
Index: ../trunk-jpl/src/c/modules/ThicknessAcrossGradientx/ThicknessAcrossGradientx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ThicknessAcrossGradientx/ThicknessAcrossGradientx.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/modules/ThicknessAcrossGradientx/ThicknessAcrossGradientx.cpp	(revision 18521)
@@ -15,7 +15,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		J+=ThicknessAcrossGradient(element);
 	}
 
Index: ../trunk-jpl/src/c/toolkits/gsl/DenseGslSolve.cpp
===================================================================
--- ../trunk-jpl/src/c/toolkits/gsl/DenseGslSolve.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/toolkits/gsl/DenseGslSolve.cpp	(revision 18521)
@@ -234,7 +234,7 @@
         IssmPDouble* pdoubleEDFin=xNew<IssmPDouble>(n*(n+1)); // provide space to transfer inputs during call_ext_fct
 	IssmPDouble* pdoubleEDFout=xNew<IssmPDouble>(n);           // provide space to transfer outputs during call_ext_fct
 	// call the wrapped solver through the registry entry we retrieve from parameters
-	call_ext_fct(dynamic_cast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
+	call_ext_fct(xDynamicCast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
 	             n*(n+1), pdoubleEDFin, adoubleEDFin,
 	             n, pdoubleEDFout,X);
 	// for(int i=0; i<n;  i++) {ADOLC_DUMP_MACRO(X[i]);}
Index: ../trunk-jpl/src/c/toolkits/mumps/MpiDenseMumpsSolve.cpp
===================================================================
--- ../trunk-jpl/src/c/toolkits/mumps/MpiDenseMumpsSolve.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/toolkits/mumps/MpiDenseMumpsSolve.cpp	(revision 18521)
@@ -243,7 +243,7 @@
   IssmPDouble *passivePack_A_rhs=xNew<IssmPDouble>(local_nnz+n);
   IssmPDouble *passiveSol=xNew<IssmPDouble>(n);
   IssmDouble *sol=xNew<IssmDouble>(n);
-  call_ext_fct(dynamic_cast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
+  call_ext_fct(xDynamicCast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
 	       packedDimsSparseArrLength, packedDimsSparseArr,
 	       local_nnz+n, passivePack_A_rhs, pack_A_rhs, 
 	       n, passiveSol,sol);
Index: ../trunk-jpl/src/c/toolkits/mumps/MumpsSolve.cpp
===================================================================
--- ../trunk-jpl/src/c/toolkits/mumps/MumpsSolve.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/toolkits/mumps/MumpsSolve.cpp	(revision 18521)
@@ -323,7 +323,7 @@
   IssmPDouble *passivePack_A_rhs=xNew<IssmPDouble>(local_nnz+n);
   IssmPDouble *passiveSol=xNew<IssmPDouble>(n);
   IssmDouble *sol=xNew<IssmDouble>(n);
-  call_ext_fct(dynamic_cast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
+  call_ext_fct(xDynamicCast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
 	       packedDimsSparseArrLength, packedDimsSparseArr,
 	       local_nnz+n, passivePack_A_rhs, pack_A_rhs, 
 	       n, passiveSol,sol);
Index: ../trunk-jpl/src/c/cores/ad_core.cpp
===================================================================
--- ../trunk-jpl/src/c/cores/ad_core.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/cores/ad_core.cpp	(revision 18521)
@@ -110,7 +110,7 @@
 			}
 
 			/*get the EDF pointer:*/
-			ext_diff_fct *anEDF_for_solverx_p=dynamic_cast<GenericParam<Adolc_edf> * >(femmodel->parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p;
+			ext_diff_fct *anEDF_for_solverx_p=xDynamicCast<GenericParam<Adolc_edf> * >(femmodel->parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p;
 
 			/*Branch according to AD driver: */
 			femmodel->parameters->FindParam(&driver,AutodiffDriverEnum);
Index: ../trunk-jpl/src/c/classes/Materials/Materials.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Materials/Materials.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Materials/Materials.cpp	(revision 18521)
@@ -36,7 +36,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		material=dynamic_cast<Material*>(*object);
+		material=xDynamicCast<Material*>(*object);
 		material->Configure(elements);
 
 	}
@@ -50,7 +50,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		material=dynamic_cast<Material*>((*object));
+		material=xDynamicCast<Material*>((*object));
 		material->ResetHooks();
 
 	}
Index: ../trunk-jpl/src/c/classes/Params/Parameters.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Params/Parameters.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Params/Parameters.cpp	(revision 18521)
@@ -56,7 +56,7 @@
 	Param* param=NULL;
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type) return true;
 	}
 	return false;
@@ -69,7 +69,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pbool);
 			return;
@@ -85,7 +85,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pinteger);
 			return;
@@ -101,7 +101,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pscalar);
 			return;
@@ -117,7 +117,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pscalar,time);
 			return;
@@ -133,7 +133,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pstring);
 			return;
@@ -150,7 +150,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pstringarray,pM);
 			return;
@@ -167,7 +167,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pintarray,pM);
 			return;
@@ -184,7 +184,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pintarray,pM,pN);
 			return;
@@ -201,7 +201,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pIssmDoublearray,pM);
 			return;
@@ -218,7 +218,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pIssmDoublearray,pM,pN);
 			return;
@@ -235,7 +235,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(parray,pM,pmdims_array,pndims_array);
 			return;
@@ -251,7 +251,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pvec);
 			return;
@@ -268,7 +268,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pmat);
 			return;
@@ -285,7 +285,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pfid);
 			return;
@@ -302,7 +302,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			param->GetParameterValue(pdataset);
 			return;
@@ -317,7 +317,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(boolean); //already exists, just set it.
 	else this->AddObject(new BoolParam(enum_type,boolean)); //just add the new parameter.
@@ -328,7 +328,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(integer); //already exists, just set it.
 	else this->AddObject(new IntParam(enum_type,integer)); //just add the new parameter.
@@ -339,7 +339,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(scalar); //already exists, just set it.
 	else this->AddObject(new DoubleParam(enum_type,scalar)); //just add the new parameter.
@@ -350,7 +350,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(string); //already exists, just set it.
 	else this->AddObject(new StringParam(enum_type,string)); //just add the new parameter.
@@ -361,7 +361,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(stringarray,M); //already exists, just set it.
 	else this->AddObject(new StringArrayParam(enum_type,stringarray,M)); //just add the new parameter.
@@ -372,7 +372,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(IssmDoublearray,M); //already exists, just set it.
 	else this->AddObject(new DoubleVecParam(enum_type,IssmDoublearray,M)); //just add the new parameter.
@@ -383,7 +383,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(IssmDoublearray,M,N); //already exists, just set it.
 	else this->AddObject(new DoubleMatParam(enum_type,IssmDoublearray,M,N)); //just add the new parameter.
@@ -394,7 +394,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(intarray,M); //already exists, just set it.
 	else this->AddObject(new IntVecParam(enum_type,intarray,M)); //just add the new parameter.
@@ -405,7 +405,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(intarray,M,N); //already exists, just set it.
 	else this->AddObject(new IntMatParam(enum_type,intarray,M,N)); //just add the new parameter.
@@ -416,7 +416,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(vector); //already exists, just set it.
 	else this->AddObject(new VectorParam(enum_type,vector)); //just add the new parameter.
@@ -427,7 +427,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(matrix); //already exists, just set it.
 	else this->AddObject(new MatrixParam(enum_type,matrix)); //just add the new parameter.
@@ -438,7 +438,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(fid); //already exists, just set it.
 	else this->AddObject(new FileParam(enum_type,fid)); //just add the new parameter.
@@ -449,7 +449,7 @@
 	Param* param=NULL;
 
 	/*first, figure out if the param has already been created: */
-	param=dynamic_cast<Param*>(this->FindParamObject(enum_type));
+	param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
 
 	if(param) param->SetValue(dataset); //already exists, just set it.
 	else this->AddObject(new DataSetParam(enum_type,dataset)); //just add the new parameter.
@@ -463,7 +463,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		param=dynamic_cast<Param*>(*object);
+		param=xDynamicCast<Param*>(*object);
 		if(param->InstanceEnum()==enum_type){
 			return (*object);
 		}
Index: ../trunk-jpl/src/c/classes/kriging/Observations.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/kriging/Observations.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/kriging/Observations.cpp	(revision 18521)
@@ -88,7 +88,7 @@
 		/*First check that this observation is not too close from another one*/
 		this->quadtree->ClosestObs(&index,x[i],y[i]);
 		if(index>=0){
-			observation=dynamic_cast<Observation*>(this->GetObjectByOffset(index));
+			observation=xDynamicCast<Observation*>(this->GetObjectByOffset(index));
 			if(pow(observation->x-x[i],2)+pow(observation->y-y[i],2) < minspacing) continue;
 		}
 
@@ -130,7 +130,7 @@
 	/*First, find closest point in Quadtree (fast but might not be the true closest obs)*/
 	this->quadtree->ClosestObs(&index,x_interp,y_interp);
 	if(index>=0){
-		observation=dynamic_cast<Observation*>(this->GetObjectByOffset(index));
+		observation=xDynamicCast<Observation*>(this->GetObjectByOffset(index));
 		hmin = sqrt((observation->x-x_interp)*(observation->x-x_interp) + (observation->y-y_interp)*(observation->y-y_interp));
 		if(hmin<radius) radius=hmin;
 	}
@@ -138,7 +138,7 @@
 	/*Find all observations that are in radius*/
 	this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,radius);
 	for (i=0;i<nobs;i++){
-		observation=dynamic_cast<Observation*>(this->GetObjectByOffset(indices[i]));
+		observation=xDynamicCast<Observation*>(this->GetObjectByOffset(indices[i]));
 		h2 = (observation->x-x_interp)*(observation->x-x_interp) + (observation->y-y_interp)*(observation->y-y_interp);
 		if(i==0){
 			hmin2 = h2;
@@ -154,7 +154,7 @@
 
 	/*Assign output pointer*/
 	if(nobs || hmin==radius){
-		observation=dynamic_cast<Observation*>(this->GetObjectByOffset(index));
+		observation=xDynamicCast<Observation*>(this->GetObjectByOffset(index));
 		*px   = observation->x;
 		*py   = observation->y;
 		*pobs = observation->value;
@@ -209,7 +209,7 @@
 	}
 	nobs = 0;
 	for(i=0;i<tempnobs;i++){
-		observation=dynamic_cast<Observation*>(this->GetObjectByOffset(tempindices[i]));
+		observation=xDynamicCast<Observation*>(this->GetObjectByOffset(tempindices[i]));
 		h2 = (observation->x-x_interp)*(observation->x-x_interp) + (observation->y-y_interp)*(observation->y-y_interp);
 
 		if(nobs==maxdata && h2>radius2) continue;
@@ -251,7 +251,7 @@
 
 		/*Loop over all observations and fill in x, y and obs*/
 		for(i=0;i<nobs;i++){
-			observation=dynamic_cast<Observation*>(this->GetObjectByOffset(indices[i]));
+			observation=xDynamicCast<Observation*>(this->GetObjectByOffset(indices[i]));
 			observation->WriteXYObs(&x[i],&y[i],&obs[i]);
 		}
 	}
@@ -279,7 +279,7 @@
 		y   = xNew<IssmPDouble>(nobs);
 		obs = xNew<IssmPDouble>(nobs);
 		for(int i=0;i<this->Size();i++){
-			observation=dynamic_cast<Observation*>(this->GetObjectByOffset(i));
+			observation=xDynamicCast<Observation*>(this->GetObjectByOffset(i));
 			observation->WriteXYObs(&x[i],&y[i],&obs[i]);
 		}
 	}
@@ -531,10 +531,10 @@
 	for(j=0;j<n;j++) gamma[j]   = 0.0;
 
 	for(i=0;i<this->Size();i++){
-		observation1=dynamic_cast<Observation*>(this->GetObjectByOffset(i));
+		observation1=xDynamicCast<Observation*>(this->GetObjectByOffset(i));
 
 		for(j=i+1;j<this->Size();j++){
-			observation2=dynamic_cast<Observation*>(this->GetObjectByOffset(j));
+			observation2=xDynamicCast<Observation*>(this->GetObjectByOffset(j));
 
 			distance=sqrt(pow(observation1->x - observation2->x,2) + pow(observation1->y - observation2->y,2));
 			if(distance>x[n-1]) continue;
Index: ../trunk-jpl/src/c/classes/Options/Options.h
===================================================================
--- ../trunk-jpl/src/c/classes/Options/Options.h	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Options/Options.h	(revision 18521)
@@ -25,7 +25,7 @@
 		template <class OptionType> void Get(OptionType* pvalue,const char* name){ /*{{{*/
 
 			/*Get option*/
-			GenericOption<OptionType>* genericoption=dynamic_cast<GenericOption<OptionType>*>(GetOption(name));
+			GenericOption<OptionType>* genericoption=xDynamicCast<GenericOption<OptionType>*>(GetOption(name));
 
 			/*If the pointer is not NULL, the option has been found*/
 			if(genericoption){
@@ -40,7 +40,7 @@
 		template <class OptionType> void Get(OptionType* pvalue,int* pnumel, const char* name){ /*{{{*/
 
 			/*Get option*/
-			GenericOption<OptionType>* genericoption=dynamic_cast<GenericOption<OptionType>*>(GetOption(name));
+			GenericOption<OptionType>* genericoption=xDynamicCast<GenericOption<OptionType>*>(GetOption(name));
 
 			/*If the pointer is not NULL, the option has been found*/
 			if(genericoption){
@@ -56,7 +56,7 @@
 		template <class OptionType> void Get(OptionType* pvalue,const char* name,OptionType default_value){ /*{{{*/
 
 			/*Get option*/
-			GenericOption<OptionType>* genericoption=dynamic_cast<GenericOption<OptionType>*>(GetOption(name));
+			GenericOption<OptionType>* genericoption=xDynamicCast<GenericOption<OptionType>*>(GetOption(name));
 
 			/*If the pointer is not NULL, the option has been found*/
 			if(genericoption){
@@ -71,7 +71,7 @@
 		template <class OptionType> void Get(OptionType* pvalue,int* pnumel, const char* name,OptionType default_value){ /*{{{*/
 
 			/*Get option*/
-			GenericOption<OptionType>* genericoption=dynamic_cast<GenericOption<OptionType>*>(GetOption(name));
+			GenericOption<OptionType>* genericoption=xDynamicCast<GenericOption<OptionType>*>(GetOption(name));
 
 			/*If the pointer is not NULL, the option has been found*/
 			if(genericoption){
@@ -91,7 +91,7 @@
 template <> inline void Options::Get(char** pvalue,const char* name,char* default_value){ /*{{{*/
 
 	/*Get option*/
-	GenericOption<char*>* genericoption=dynamic_cast<GenericOption<char*>*>(GetOption(name));
+	GenericOption<char*>* genericoption=xDynamicCast<GenericOption<char*>*>(GetOption(name));
 
 	/*If the pointer is not NULL, the option has been found*/
 	if(genericoption){
Index: ../trunk-jpl/src/c/classes/Options/Options.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Options/Options.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Options/Options.cpp	(revision 18521)
@@ -51,7 +51,7 @@
 	/*Finally, check that no option of the same name already exists in the dataset*/
 	for(object=objects.begin();object<objects.end();object++){
 
-		option=dynamic_cast<Option*>(*object);
+		option=xDynamicCast<Option*>(*object);
 		if (!strcmp(option->Name(),name)){
 			_error_("Options \"" << name << "\" found multiple times");
 			break;
@@ -72,7 +72,7 @@
 	/*Go through options and find option: */
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		option=dynamic_cast<Option*>(*object);
+		option=xDynamicCast<Option*>(*object);
 		//option=(Option*)(*object); //C-like cast
 		/*There is a crash on some machines (Einar Olason) that needs to be fixed*/
 		if(!option){
Index: ../trunk-jpl/src/c/classes/Loads/Loads.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Loads/Loads.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Loads/Loads.cpp	(revision 18521)
@@ -40,7 +40,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		load=dynamic_cast<Load*>(*object);
+		load=xDynamicCast<Load*>(*object);
 		load->Configure(elements,loads,nodes,vertices,materials,parameters);
 
 	}
@@ -54,7 +54,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		load=dynamic_cast<Load*>((*object));
+		load=xDynamicCast<Load*>((*object));
 		load->ResetHooks();
 
 	}
@@ -69,7 +69,7 @@
 	/*Now go through all loads, and get how many nodes they own, unless they are clone nodes: */
 	for(int i=0;i<this->Size();i++){
 
-		Load* load=dynamic_cast<Load*>(this->GetObjectByOffset(i));
+		Load* load=xDynamicCast<Load*>(this->GetObjectByOffset(i));
 		if (load->InAnalysis(analysis_type)){
 			if(load->IsPenalty()) ispenalty++;
 		}
@@ -94,7 +94,7 @@
 	/*Now go through all loads, and get how many nodes they own, unless they are clone nodes: */
 	for(int i=0;i<this->Size();i++){
 
-		Load* load=dynamic_cast<Load*>(this->GetObjectByOffset(i));
+		Load* load=xDynamicCast<Load*>(this->GetObjectByOffset(i));
 		if (load->InAnalysis(analysis_type)){
 			numnodes=load->GetNumberOfNodes();
 			if(numnodes>max)max=numnodes;
@@ -131,7 +131,7 @@
 	/*Get number of local loads*/
 	for(int i=0;i<this->Size();i++){
 
-		Load* load=dynamic_cast<Load*>(this->GetObjectByOffset(i));
+		Load* load=xDynamicCast<Load*>(this->GetObjectByOffset(i));
 
 		/*Check that this load corresponds to our analysis currently being carried out: */
 		if (load->InAnalysis(analysis_type)) localloads++;
@@ -156,7 +156,7 @@
 	/*Get number of local loads*/
 	for(int i=0;i<this->Size();i++){
 
-		Load* load=dynamic_cast<Load*>(this->GetObjectByOffset(i));
+		Load* load=xDynamicCast<Load*>(this->GetObjectByOffset(i));
 
 		/*Check that this load corresponds to our analysis currently being carried out: */
 		if (load->InAnalysis(analysis_type)) localloads++;
@@ -172,7 +172,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		load=dynamic_cast<Load*>(*object);
+		load=xDynamicCast<Load*>(*object);
 		load->SetCurrentConfiguration(elements,loads,nodes,vertices,materials,parameters);
 
 	}
Index: ../trunk-jpl/src/c/classes/ExternalResults/Results.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/ExternalResults/Results.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/ExternalResults/Results.cpp	(revision 18521)
@@ -40,7 +40,7 @@
 	parameters->FindParam(&io_gather,SettingsIoGatherEnum);
 
 	for(int i=0;i<this->Size();i++){
-		ExternalResult* result=dynamic_cast<ExternalResult*>(this->GetObjectByOffset(i));
+		ExternalResult* result=xDynamicCast<ExternalResult*>(this->GetObjectByOffset(i));
 		result->WriteData(fid,io_gather);
 	}
 
@@ -56,7 +56,7 @@
 	_assert_(in_result);
 
 	for(int i=0;i<this->Size();i++){
-		ExternalResult* result=dynamic_cast<ExternalResult*>(this->GetObjectByOffset(i));
+		ExternalResult* result=xDynamicCast<ExternalResult*>(this->GetObjectByOffset(i));
 
 		if(result->GetStep()==in_result->GetStep()){
 			char*    result_name =    result->GetResultName();
@@ -80,7 +80,7 @@
 int Results::DeleteResult(int result_enum,int result_step){/*{{{*/
 
 	for(int i=0;i<this->Size();i++){
-		ExternalResult* result=dynamic_cast<ExternalResult*>(this->GetObjectByOffset(i));
+		ExternalResult* result=xDynamicCast<ExternalResult*>(this->GetObjectByOffset(i));
 
 		if(result->GetStep()==result_step){
 			if(strcmp(result->GetResultName(),EnumToStringx(result_enum))==0){
Index: ../trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/FemModel.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/FemModel.cpp	(revision 18521)
@@ -602,7 +602,7 @@
 
 					/*Get interpolation (and compute input if necessary)*/
 					for(int j=0;j<elements->Size();j++){
-						Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(j));
+						Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(j));
 						element->ResultInterpolation(&rank_interpolation,&rank_nodesperelement,output_enum);
 					}
 
@@ -621,7 +621,7 @@
 
 						/*Fill-in matrix*/
 						for(int j=0;j<elements->Size();j++){
-							Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(j));
+							Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(j));
 							element->ResultToPatch(values,nodesperelement,output_enum);
 						}
 
@@ -738,7 +738,7 @@
 	element=(Element*)elements->GetObjectByOffset(0); min_dt=element->TimeAdapt();
 
 	for (i=1;i<elements->Size();i++){
-		element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		dt=element->TimeAdapt();
 		if(dt<min_dt)min_dt=dt;
 	}
@@ -755,7 +755,7 @@
 void FemModel::UpdateConstraintsExtrudeFromBasex(void){ /*{{{*/
 
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->UpdateConstraintsExtrudeFromBase();
 	}
 
@@ -764,7 +764,7 @@
 void FemModel::UpdateConstraintsExtrudeFromTopx(void){ /*{{{*/
 
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->UpdateConstraintsExtrudeFromTop();
 	}
 
@@ -838,7 +838,7 @@
 	/*Go through elements, and request velocity: */
 	maxabsvx=-INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_maxabsvx=element->inputs->MaxAbs(VxEnum);
 		if(element_maxabsvx>maxabsvx) maxabsvx=element_maxabsvx;
 	}
@@ -862,7 +862,7 @@
 	/*Go through elements, and request velocity: */
 	maxabsvy=-INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_maxabsvy=element->inputs->MaxAbs(VyEnum);
 		if(element_maxabsvy>maxabsvy) maxabsvy=element_maxabsvy;
 	}
@@ -886,7 +886,7 @@
 	/*Go through elements, and request velocity: */
 	maxabsvz=-INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_maxabsvz=element->inputs->MaxAbs(VzEnum);
 		if(element_maxabsvz>maxabsvz) maxabsvz=element_maxabsvz;
 	}
@@ -910,7 +910,7 @@
 	/*Go through elements, and request velocity: */
 	maxvel=-INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_maxvel = element->inputs->Max(VelEnum);
 		if(element_maxvel>maxvel) maxvel=element_maxvel;
 	}
@@ -934,7 +934,7 @@
 	/*Go through elements, and request velocity: */
 	maxvx=-INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_maxvx = element->inputs->Max(VxEnum);
 		if(element_maxvx>maxvx) maxvx=element_maxvx;
 	}
@@ -958,7 +958,7 @@
 	/*Go through elements, and request velocity: */
 	maxvy=-INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_maxvy = element->inputs->Max(VyEnum);
 		if(element_maxvy>maxvy) maxvy=element_maxvy;
 	}
@@ -982,7 +982,7 @@
 	/*Go through elements, and request velocity: */
 	maxvz=-INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_maxvz = element->inputs->Max(VzEnum);
 		if(element_maxvz>maxvz) maxvz=element_maxvz;
 	}
@@ -1006,7 +1006,7 @@
 	/*Go through elements, and request velocity: */
 	minvel=INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_minvel = element->inputs->Min(VelEnum);
 		if(element_minvel<minvel) minvel=element_minvel;
 	}
@@ -1030,7 +1030,7 @@
 	/*Go through elements, and request velocity: */
 	minvx=INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_minvx = element->inputs->Min(VxEnum);
 		if(element_minvx<minvx) minvx=element_minvx;
 	}
@@ -1054,7 +1054,7 @@
 	/*Go through elements, and request velocity: */
 	minvy=INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_minvy = element->inputs->Min(VyEnum);
 		if(element_minvy<minvy) minvy=element_minvy;
 	}
@@ -1078,7 +1078,7 @@
 	/*Go through elements, and request velocity: */
 	minvz=INFINITY;
 	for(i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element_minvz = element->inputs->Min(VzEnum);
 		if(element_minvz<minvz) minvz=element_minvz;
 	}
@@ -1098,7 +1098,7 @@
 	IssmDouble total_smb;
 
 	for(int i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		local_smb+=element->TotalSmb();
 	}
 	ISSM_MPI_Reduce(&local_smb,&total_smb,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
@@ -1114,7 +1114,7 @@
 	IssmDouble total_divergence;
 
 	for(int i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		local_divergence+=element->Divergence();
 	}
 	ISSM_MPI_Reduce(&local_divergence,&total_divergence,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
@@ -1142,7 +1142,7 @@
 	}
 
 	for(int i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		element->GetInputLocalMinMaxOnNodes(uLmin_local,uLmax_local,ug);
 	}
 
@@ -1163,7 +1163,7 @@
 	IssmDouble total_ice_volume;
 
 	for(int i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		local_ice_volume+=element->IceVolume();
 	}
 	ISSM_MPI_Reduce(&local_ice_volume,&total_ice_volume,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
@@ -1179,7 +1179,7 @@
 	IssmDouble total_ice_volume_af;
 
 	for(int i=0;i<this->elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		local_ice_volume_af+=element->IceVolumeAboveFloatation();
 	}
 	ISSM_MPI_Reduce(&local_ice_volume_af,&total_ice_volume_af,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
@@ -1204,7 +1204,7 @@
 
 	/*now, go through our elements, and retrieve the one with this id: index: */
 	for(int i=0;i<this->elements->Size();i++){
-		element=dynamic_cast<Element*>(this->elements->GetObjectByOffset(i));
+		element=xDynamicCast<Element*>(this->elements->GetObjectByOffset(i));
 		if (element->Id()==index){
 			found=1;
 			cpu_found=my_rank;
@@ -1242,7 +1242,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 
 		/*If on water, return 0: */
 		if(!element->IsIceInElement()) continue;
@@ -1310,7 +1310,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 
 		/*If on water, return 0: */
 		if(!element->IsIceInElement()) continue;
@@ -1340,7 +1340,7 @@
 
 	/*Compute Misfit: */
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 
 		/*If on water, return 0: */
 		if(!element->IsIceInElement()) continue;
@@ -1571,7 +1571,7 @@
 
 	/*Go through elements, and add contribution from each element to the deflection vector wg:*/
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		element->GiaDeflection(wg,dwgdt, x,y);
 	}
 }
@@ -1589,7 +1589,7 @@
 	mask=new Vector<IssmDouble>(nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
 
 	for (int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		effanalysis->HydrologyEPLGetMask(mask,element);
 	}
 
@@ -1605,7 +1605,7 @@
 	/*Step 2: update node activity. If one element is connected to mask=1, all nodes are active*/
 	active=new Vector<IssmDouble>(nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
 	for (int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		effanalysis->HydrologyEPLGetActive(active,element);
 	}
 
@@ -1617,7 +1617,7 @@
 	/*Update node activation accordingly*/
 	int counter =0;
 	for (int i=0;i<nodes->Size();i++){
-		Node* node=dynamic_cast<Node*>(nodes->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(nodes->GetObjectByOffset(i));
 		if(node->InAnalysis(HydrologyDCEfficientAnalysisEnum)){
 			if(serial_active[node->Sid()]==1.){
 				node->Activate();
@@ -1650,7 +1650,7 @@
 	/*update node activity. If one element is connected to mask=1, all nodes are active*/
 	active=new Vector<IssmDouble>(nodes->NumberOfNodes(HydrologyDCEfficientAnalysisEnum));
 	for (int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		effanalysis->HydrologyEPLGetActive(active,element);
 	}
 
@@ -1663,7 +1663,7 @@
 	/*Update node activation accordingly*/
 	int counter =0;
 	for (int i=0;i<nodes->Size();i++){
-		Node* node=dynamic_cast<Node*>(nodes->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(nodes->GetObjectByOffset(i));
 		if(node->InAnalysis(L2ProjectionEPLAnalysisEnum)){
 			if(serial_active[node->Sid()]==1.){
 				node->Activate();
Index: ../trunk-jpl/src/c/classes/Elements/Tria.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Elements/Tria.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Elements/Tria.cpp	(revision 18521)
@@ -1795,7 +1795,7 @@
 	seg->inputs=(Inputs*)this->inputs->SpawnSegInputs(index1,index2);
 	seg->parameters=this->parameters;
 	seg->element_type=P1Enum; //Only P1 CG for now (TO BE CHANGED)
-	this->SpawnSegHook(dynamic_cast<ElementHook*>(seg),index1,index2);
+	this->SpawnSegHook(xDynamicCast<ElementHook*>(seg),index1,index2);
 
 	/*Spawn material*/
 	seg->material=(Material*)this->material->copy2(seg);
Index: ../trunk-jpl/src/c/classes/Elements/PentaRef.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Elements/PentaRef.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Elements/PentaRef.cpp	(revision 18521)
@@ -47,7 +47,7 @@
 
 	/*Cast gauss to GaussPenta*/
 	_assert_(gauss_in->Enum()==GaussPentaEnum);
-	GaussPenta* gauss = dynamic_cast<GaussPenta*>(gauss_in);
+	GaussPenta* gauss = xDynamicCast<GaussPenta*>(gauss_in);
 
 	/*Figure out xi,eta and zi (parametric coordinates), for this gaussian point: */
 	A1  = gauss->coord1;
@@ -159,7 +159,7 @@
 
 	/*Cast gauss to GaussPenta*/
 	_assert_(gauss_in->Enum()==GaussPentaEnum);
-	GaussPenta* gauss = dynamic_cast<GaussPenta*>(gauss_in);
+	GaussPenta* gauss = xDynamicCast<GaussPenta*>(gauss_in);
 
 	/*Get current coordinates in reference element*/
 	IssmDouble zeta=gauss->coord4;
@@ -364,7 +364,7 @@
 
 	/*Cast gauss to GaussPenta*/
 	_assert_(gauss_in->Enum()==GaussPentaEnum);
-	GaussPenta* gauss = dynamic_cast<GaussPenta*>(gauss_in);
+	GaussPenta* gauss = xDynamicCast<GaussPenta*>(gauss_in);
 
 	/*Get current coordinates in reference element*/
 	IssmDouble zeta=gauss->coord4;
Index: ../trunk-jpl/src/c/classes/Elements/Penta.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Elements/Penta.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Elements/Penta.cpp	(revision 18521)
@@ -1969,7 +1969,7 @@
 	tria->inputs=(Inputs*)this->inputs->SpawnTriaInputs(index1,index2,index3);
 	tria->parameters=this->parameters;
 	tria->element_type=P1Enum; //Only P1 CG for now (TO BE CHANGED)
-	this->SpawnTriaHook(dynamic_cast<ElementHook*>(tria),index1,index2,index3);
+	this->SpawnTriaHook(xDynamicCast<ElementHook*>(tria),index1,index2,index3);
 
 	/*Spawn material*/
 	tria->material=(Material*)this->material->copy2(tria);
Index: ../trunk-jpl/src/c/classes/Elements/TetraRef.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Elements/TetraRef.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Elements/TetraRef.cpp	(revision 18521)
@@ -36,7 +36,7 @@
 
 	/*Cast gauss to GaussTetra*/
 	_assert_(gauss_in->Enum()==GaussTetraEnum);
-	GaussTetra* gauss = dynamic_cast<GaussTetra*>(gauss_in);
+	GaussTetra* gauss = xDynamicCast<GaussTetra*>(gauss_in);
 
 	switch(finiteelement){
 		case P0Enum:
Index: ../trunk-jpl/src/c/classes/Elements/Elements.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Elements/Elements.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Elements/Elements.cpp	(revision 18521)
@@ -40,7 +40,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		element=dynamic_cast<Element*>((*object));
+		element=xDynamicCast<Element*>((*object));
 		element->Configure(elements,loads,nodes,vertices,materials,parameters);
 
 	}
@@ -54,7 +54,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		element=dynamic_cast<Element*>((*object));
+		element=xDynamicCast<Element*>((*object));
 		element->SetCurrentConfiguration(elements,loads,nodes,materials,parameters);
 
 	}
@@ -68,7 +68,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		element=dynamic_cast<Element*>((*object));
+		element=xDynamicCast<Element*>((*object));
 		element->ResetHooks();
 
 	}
@@ -84,7 +84,7 @@
 	/*Now go through all elements, and get how many nodes they own, unless they are clone nodes: */
 	for(int i=0;i<this->Size();i++){
 
-		Element* element=dynamic_cast<Element*>(this->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->GetObjectByOffset(i));
 		numnodes=element->GetNumberOfNodes();
 		if(numnodes>max)max=numnodes;
 	}
@@ -110,7 +110,7 @@
 void Elements::InputDuplicate(int input_enum,int output_enum){/*{{{*/
 
 	for(int i=0;i<this->Size();i++){
-		Element* element=dynamic_cast<Element*>(this->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(this->GetObjectByOffset(i));
 		element->InputDuplicate(input_enum,output_enum);
 	}
 }
Index: ../trunk-jpl/src/c/classes/Elements/Tetra.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Elements/Tetra.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Elements/Tetra.cpp	(revision 18521)
@@ -823,7 +823,7 @@
 	tria->inputs=(Inputs*)this->inputs->SpawnTriaInputs(index1,index2,index3);
 	tria->parameters=this->parameters;
 	tria->element_type=P1Enum; //Only P1 CG for now (TO BE CHANGED)
-	this->SpawnTriaHook(dynamic_cast<ElementHook*>(tria),index1,index2,index3);
+	this->SpawnTriaHook(xDynamicCast<ElementHook*>(tria),index1,index2,index3);
 
 	/*Spawn material*/
 	tria->material=(Material*)this->material->copy2(tria);
Index: ../trunk-jpl/src/c/classes/Elements/TriaRef.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Elements/TriaRef.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Elements/TriaRef.cpp	(revision 18521)
@@ -145,7 +145,7 @@
 
 	/*Cast gauss to GaussTria*/
 	_assert_(gauss_in->Enum()==GaussTriaEnum);
-	GaussTria* gauss = dynamic_cast<GaussTria*>(gauss_in);
+	GaussTria* gauss = xDynamicCast<GaussTria*>(gauss_in);
 
 	switch(finiteelement){
 		case NoneEnum:
@@ -270,7 +270,7 @@
 
 	/*Cast gauss to GaussTria*/
 	_assert_(gauss_in->Enum()==GaussTriaEnum);
-	GaussTria* gauss = dynamic_cast<GaussTria*>(gauss_in);
+	GaussTria* gauss = xDynamicCast<GaussTria*>(gauss_in);
 
 	switch(finiteelement){
 		case P0Enum:
Index: ../trunk-jpl/src/c/classes/Hook.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Hook.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Hook.cpp	(revision 18521)
@@ -167,7 +167,7 @@
 
 		/*Now, for this->objects that did not get resolved, and for which we have no offset, chase them in the dataset, by id: */
 		if(this->objects[i]==NULL){
-			this->objects[i]=dynamic_cast<Object*>(dataset->GetObjectById(this->offsets+i,this->ids[i])); //remember the offset for later on.
+			this->objects[i]=xDynamicCast<Object*>(dataset->GetObjectById(this->offsets+i,this->ids[i])); //remember the offset for later on.
 			/*check the id is correct!: */
 			if (this->objects[i]->Id()!=this->ids[i]) _error_("wrong id: " << this->objects[i]->Id() << " vs " << this->ids[i] << "  in resolved pointer!");
 		}
Index: ../trunk-jpl/src/c/classes/gauss/GaussPenta.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/gauss/GaussPenta.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/gauss/GaussPenta.cpp	(revision 18521)
@@ -7,6 +7,7 @@
 #include "../../shared/io/Print/Print.h"
 #include "../../shared/Exceptions/exceptions.h"
 #include "../../shared/MemOps/MemOps.h"
+#include "../../shared/Numerics/recast.h"
 #include "../../shared/Enum/Enum.h"
 #include "../../shared/Numerics/GaussPoints.h"
 #include "../../shared/Numerics/constants.h"
@@ -749,7 +750,7 @@
 void GaussPenta::SynchronizeGaussBase(Gauss* gauss){/*{{{*/
 
 	_assert_(gauss->Enum()==GaussTriaEnum);
-	GaussTria* gauss_tria = dynamic_cast<GaussTria*>(gauss);
+	GaussTria* gauss_tria = xDynamicCast<GaussTria*>(gauss);
 
 	gauss_tria->coord1=this->coord1;
 	gauss_tria->coord2=this->coord2;
Index: ../trunk-jpl/src/c/classes/Inputs/ControlInput.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Inputs/ControlInput.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Inputs/ControlInput.cpp	(revision 18521)
@@ -86,11 +86,11 @@
 	output->enum_type=this->enum_type;
 	output->control_id=this->control_id;
 
-	if(values)      output->values      = dynamic_cast<Input*>(this->values->copy());
-	if(savedvalues) output->savedvalues = dynamic_cast<Input*>(this->savedvalues->copy());
-	if(minvalues)   output->minvalues   = dynamic_cast<Input*>(this->minvalues->copy());
-	if(maxvalues)   output->maxvalues   = dynamic_cast<Input*>(this->maxvalues->copy());
-	if(gradient)    output->gradient    = dynamic_cast<Input*>(this->gradient->copy());
+	if(values)      output->values      = xDynamicCast<Input*>(this->values->copy());
+	if(savedvalues) output->savedvalues = xDynamicCast<Input*>(this->savedvalues->copy());
+	if(minvalues)   output->minvalues   = xDynamicCast<Input*>(this->minvalues->copy());
+	if(maxvalues)   output->maxvalues   = xDynamicCast<Input*>(this->maxvalues->copy());
+	if(gradient)    output->gradient    = xDynamicCast<Input*>(this->gradient->copy());
 
 	return output;
 }
@@ -233,14 +233,14 @@
 	if(!values) _error_("Values of " << EnumToStringx(this->enum_type) << " not found");
 
 	if(savedvalues) delete this->savedvalues;
-	this->savedvalues=dynamic_cast<Input*>(this->values->copy());
+	this->savedvalues=xDynamicCast<Input*>(this->values->copy());
 }/*}}}*/
 void ControlInput::UpdateValue(IssmDouble scalar){/*{{{*/
 	if(!gradient)    _error_("Gradient of " << EnumToStringx(this->enum_type) << " not found");
 	if(!savedvalues) _error_("Values of " << EnumToStringx(this->enum_type) << " not found");
 
 	if(values) delete this->values;
-	this->values=dynamic_cast<Input*>(this->savedvalues->copy());
+	this->values=xDynamicCast<Input*>(this->savedvalues->copy());
 	this->values->AXPY(gradient,scalar);
 }/*}}}*/
 void ControlInput::VerticallyIntegrate(Input* thickness_input){/*{{{*/
Index: ../trunk-jpl/src/c/classes/Inputs/DatasetInput.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Inputs/DatasetInput.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Inputs/DatasetInput.cpp	(revision 18521)
@@ -80,7 +80,7 @@
 	/*Create new Datasetinput (copy of current input)*/
 	outinput=new DatasetInput();
 	outinput->enum_type=this->enum_type;
-	outinput->inputs=dynamic_cast<Inputs*>(this->inputs->SpawnTriaInputs(index1,index2,index3));
+	outinput->inputs=xDynamicCast<Inputs*>(this->inputs->SpawnTriaInputs(index1,index2,index3));
 	outinput->numids=this->numids;
 	outinput->ids=xNew<int>(this->numids);
 	xMemCpy(outinput->ids,this->ids,this->numids);
@@ -97,7 +97,7 @@
 	/*Create new Datasetinput (copy of current input)*/
 	outinput=new DatasetInput();
 	outinput->enum_type=this->enum_type;
-	outinput->inputs=dynamic_cast<Inputs*>(this->inputs->SpawnSegInputs(index1,index2));
+	outinput->inputs=xDynamicCast<Inputs*>(this->inputs->SpawnSegInputs(index1,index2));
 	outinput->numids=this->numids;
 	outinput->ids=xNew<int>(this->numids);
 	xMemCpy(outinput->ids,this->ids,this->numids);
@@ -156,7 +156,7 @@
 	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 );
 
-	Input* input=dynamic_cast<Input*>(this->inputs->GetObjectByOffset(offset));
+	Input* input=xDynamicCast<Input*>(this->inputs->GetObjectByOffset(offset));
 	input->GetInputValue(pvalue,gauss);
 }
 /*}}}*/
Index: ../trunk-jpl/src/c/classes/Inputs/Inputs.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Inputs/Inputs.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Inputs/Inputs.cpp	(revision 18521)
@@ -37,7 +37,7 @@
 	/*Go through inputs and check whether any input with the same name is already in: */
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 		if (input->InstanceEnum()==enum_type){
 			found=true;
 			break;
@@ -64,7 +64,7 @@
 	/*Go through inputs and check whether any input with the same name is already in: */
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 		if (input->InstanceEnum()==enum_type){
 			found=true;
 			break;
@@ -91,7 +91,7 @@
 	/*Go through inputs and check whether any input with the same name is already in: */
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object); 
+		input=xDynamicCast<Input*>(*object); 
 		if (input->InstanceEnum()==enum_type){
 			found=true;
 			break;
@@ -118,7 +118,7 @@
 	/*Go through inputs and check whether any input with the same name is already in: */
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 		if (input->InstanceEnum()==enum_type){
 			found=true;
 			break;
@@ -149,7 +149,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 
 		if (input->InstanceEnum()==in_input->InstanceEnum()){
 			this->DeleteObject(input);
@@ -170,7 +170,7 @@
 
 	/*Delete existing input of newenumtype if it exists*/
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 
 		if (input->InstanceEnum()==newenumtype){
 			this->DeleteObject(input);
@@ -181,7 +181,7 @@
 	/*Change enum_type of input of oldenumtype*/
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 
 		if (input->InstanceEnum()==oldenumtype){
 			input->ChangeEnum(newenumtype);
@@ -193,7 +193,7 @@
 void  Inputs::ConstrainMin(int constrain_enum, IssmDouble minimum){/*{{{*/
 
 	/*Find x and y inputs: */
-	Input* constrain_input=dynamic_cast<Input*>(this->GetInput(constrain_enum));
+	Input* constrain_input=xDynamicCast<Input*>(this->GetInput(constrain_enum));
 
 	/*some checks: */
 	if(!constrain_input) _error_("input " << EnumToStringx(constrain_enum) << " could not be found!");
@@ -208,7 +208,7 @@
 	IssmDouble norm;
 
 	/*Get input*/
-	Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
+	Input* input=xDynamicCast<Input*>(this->GetInput(enumtype));
 
 	/*Apply ContrainMin: */
 	if (input){
@@ -228,7 +228,7 @@
 	IssmDouble max;
 
 	/*Get input*/
-	Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
+	Input* input=xDynamicCast<Input*>(this->GetInput(enumtype));
 
 	/*Apply ContrainMin: */
 	if (input){
@@ -248,7 +248,7 @@
 	IssmDouble max;
 
 	/*Get input*/
-	Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
+	Input* input=xDynamicCast<Input*>(this->GetInput(enumtype));
 
 	/*Apply ContrainMin: */
 	if (input){
@@ -268,7 +268,7 @@
 	IssmDouble min;
 
 	/*Get input*/
-	Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
+	Input* input=xDynamicCast<Input*>(this->GetInput(enumtype));
 
 	/*Apply ContrainMin: */
 	if (input){
@@ -288,7 +288,7 @@
 	IssmDouble min;
 
 	/*Get input*/
-	Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
+	Input* input=xDynamicCast<Input*>(this->GetInput(enumtype));
 
 	/*Apply ContrainMin: */
 	if (input){
@@ -309,7 +309,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 
 		if (input->InstanceEnum()==enum_name){
 			return input;
@@ -325,7 +325,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 
 		if (input->InstanceEnum()==enum_type){
 			this->DeleteObject(input);
@@ -340,15 +340,15 @@
 void  Inputs::DuplicateInput(int original_enum,int new_enum){/*{{{*/
 
 	/*Make a copy of the original input: */
-	Input* original=dynamic_cast<Input*>(this->GetInput(original_enum));
+	Input* original=xDynamicCast<Input*>(this->GetInput(original_enum));
 	if(!original)_error_("could not find input with enum: " << EnumToStringx(original_enum)); 
-	Input* copy=dynamic_cast<Input*>(original->copy());
+	Input* copy=xDynamicCast<Input*>(original->copy());
 
 	/*Change copy enum to reinitialized_enum: */
 	copy->ChangeEnum(new_enum);
 
 	/*Add copy into inputs, it will wipe off the one already there: */
-	this->AddInput(dynamic_cast<Input*>(copy));
+	this->AddInput(xDynamicCast<Input*>(copy));
 }
 /*}}}*/
 Inputs* Inputs::SpawnTriaInputs(int index1,int index2,int index3){/*{{{*/
@@ -365,7 +365,7 @@
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
 		/*Create new input*/
-		inputin=dynamic_cast<Input*>(*object);
+		inputin=xDynamicCast<Input*>(*object);
 		inputout=inputin->SpawnTriaInput(index1,index2,index3);
 
 		/*Add input to new inputs*/
@@ -390,7 +390,7 @@
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
 		/*Create new input*/
-		inputin=dynamic_cast<Input*>(*object);
+		inputin=xDynamicCast<Input*>(*object);
 		inputout=inputin->SpawnSegInput(index1,index2);
 
 		/*Add input to new inputs*/
@@ -404,8 +404,8 @@
 void  Inputs::AXPY(int inputy_enum, IssmDouble scalar, int inputx_enum){/*{{{*/
 
 	/*Find x and y inputs: */
-	Input* xinput=dynamic_cast<Input*>(this->GetInput(inputx_enum));
-	Input* yinput=dynamic_cast<Input*>(this->GetInput(inputy_enum));
+	Input* xinput=xDynamicCast<Input*>(this->GetInput(inputx_enum));
+	Input* yinput=xDynamicCast<Input*>(this->GetInput(inputy_enum));
 
 	/*some checks: */
 	if(!xinput) _error_("input " << EnumToStringx(inputx_enum) << " could not be found!");
@@ -422,7 +422,7 @@
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
 
-		input=dynamic_cast<Input*>(*object);
+		input=xDynamicCast<Input*>(*object);
 		input->Configure(parameters);
 
 	}
Index: ../trunk-jpl/src/c/classes/Nodes.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Nodes.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Nodes.cpp	(revision 18521)
@@ -48,7 +48,7 @@
 
 	/*Go through objects, and distribute dofs locally, from 0 to numberofdofsperobject*/
 	for(i=0;i<this->Size();i++){
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Check that this node corresponds to our analysis currently being carried out: */
 		if(node->InAnalysis(analysis_type)){
@@ -71,7 +71,7 @@
 	}
 	for(i=0;i<this->Size();i++){
 		/*Check that this node corresponds to our analysis currently being carried out: */
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 		if (node->InAnalysis(analysis_type)){
 			node->OffsetDofs(dofcount,setenum);
 		}
@@ -88,7 +88,7 @@
 	}
 
 	for(i=0;i<this->Size();i++){
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 		if (node->InAnalysis(analysis_type)){
 			node->ShowTrueDofs(truedofs,maxdofspernode,setenum);//give maxdofspernode, column size, so that nodes can index into truedofs
 		}
@@ -98,7 +98,7 @@
 
 	/* Now every cpu knows the true dofs of everyone else that is not a clone*/
 	for(i=0;i<this->Size();i++){
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 		if (node->InAnalysis(analysis_type)){
 			node->UpdateCloneDofs(alltruedofs,maxdofspernode,setenum);
 		}
@@ -106,7 +106,7 @@
 
 	/*Update indexingupdateflag*/
 	for(i=0;i<this->Size();i++){
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 		if (node->InAnalysis(analysis_type)){
 			node->ReindexingDone();
 		}
@@ -147,7 +147,7 @@
 	/*Now go through all objects, and use minranks to flag which objects are cloned: */
 	for(i=0;i<this->Size();i++){
 
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Check that this node corresponds to our analysis currently being carried out: */
 		if (node->InAnalysis(analysis_type)){
@@ -171,7 +171,7 @@
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
 	for(int i=0;i<this->Size();i++){
 
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Check that this node corresponds to our analysis currently being carried out: */
 		if (node->InAnalysis(analysis_type)){
@@ -196,7 +196,7 @@
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
 	if(!sorted){
 		for(int i=0;i<this->Size();i++){
-			Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+			Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 			id=node->Id();
 			if(id>max)max=id;
 		}
@@ -206,7 +206,7 @@
 			max = 0;
 		}
 		else{
-			Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(this->Size()-1));
+			Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(this->Size()-1));
 			max = node->Id();
 		}
 	}
@@ -237,7 +237,7 @@
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
 	for(int i=0;i<this->Size();i++){
 
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Check that this node corresponds to our analysis currently being carried out: */
 		if (node->InAnalysis(analysis_type)){
@@ -261,7 +261,7 @@
 
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
 	for(int i=0;i<this->Size();i++){
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Ok, this object is a node, ask it to plug values into partition: */
 		if (!node->IsClone()) numnodes++;
@@ -283,7 +283,7 @@
 
 	for(i=0;i<this->Size();i++){
 
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Check that this node corresponds to our analysis currently being carried out: */
 		if (node->InAnalysis(analysis_type)){
@@ -315,7 +315,7 @@
 	/*Go through nodes, and for each object, report it cpu: */
 	for(int i=0;i<this->Size();i++){
 
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Check that this node corresponds to our analysis currently being carried out: */
 		if (node->InAnalysis(analysis_type)){
@@ -334,7 +334,7 @@
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
 	for(int i=0;i<this->Size();i++){
 
-		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
+		Node* node=xDynamicCast<Node*>(this->GetObjectByOffset(i));
 
 		/*Check that this node corresponds to our analysis currently being carried out: */
 		if(node->InAnalysis(analysis_type)){
Index: ../trunk-jpl/src/c/classes/Vertices.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/Vertices.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/Vertices.cpp	(revision 18521)
@@ -51,7 +51,7 @@
 
 	/*Go through objects, and distribute pids locally, from 0 to numberofpidsperobject*/
 	for (i=0;i<this->Size();i++){
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		vertex->DistributePids(&pidcount);
 	}
 
@@ -71,7 +71,7 @@
 		}
 	}
 	for (i=0;i<this->Size();i++){
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		vertex->OffsetPids(pidcount);
 	}
 
@@ -81,14 +81,14 @@
 	truepids   =xNewZeroInit<int>(numberofobjects);
 	alltruepids=xNewZeroInit<int>(numberofobjects);
 	for (i=0;i<this->Size();i++){
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		vertex->ShowTruePids(truepids);
 	}
 	ISSM_MPI_Allreduce((void*)truepids,(void*)alltruepids,numberofobjects,ISSM_MPI_INT,ISSM_MPI_MAX,IssmComm::GetComm());
 
 	/* Now every cpu knows the true pids of everyone else that is not a clone*/
 	for(i=0;i<this->Size();i++){
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		vertex->UpdateClonePids(alltruepids);
 	}
 
@@ -127,7 +127,7 @@
 	/*Now go through all objects, and use minranks to flag which objects are cloned: */
 	for(i=0;i<this->Size();i++){
 		/*For this object, decide whether it is a clone: */
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		vertex->SetClone(minranks);
 	}
 
@@ -144,7 +144,7 @@
 	int vertex_max_sid;
 
 	for(i=0;i<this->Size();i++){
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		sid=vertex->Sid();
 		if (sid>max_sid)max_sid=sid;
 	}
@@ -171,7 +171,7 @@
 	/*Go through a dataset, and for each object, report it cpu: */
 	for(int i=0;i<this->Size();i++){
 		/*Plug rank into ranks, according to id: */
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		sid=vertex->Sid();
 		ranks[sid]=my_rank; 
 	}
@@ -201,7 +201,7 @@
 	for(i=0;i<this->Size();i++){
 
 		/*let vertex fill matrix: */
-		Vertex* vertex=dynamic_cast<Vertex*>(this->GetObjectByOffset(i));
+		Vertex* vertex=xDynamicCast<Vertex*>(this->GetObjectByOffset(i));
 		vertex->ToXYZ(xyz);
 	}
 
Index: ../trunk-jpl/src/c/classes/IoModel.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/IoModel.cpp	(revision 18520)
+++ ../trunk-jpl/src/c/classes/IoModel.cpp	(revision 18521)
@@ -258,10 +258,10 @@
 	_assert_(this->constants);
 
 	/*Find constant*/
-	Param* param=dynamic_cast<Param*>(this->constants->FindParamObject(constant_enum));
+	Param* param=xDynamicCast<Param*>(this->constants->FindParamObject(constant_enum));
 	if(!param) _error_("Constant " << EnumToStringx(constant_enum) << " not found in iomodel");
 
-	return dynamic_cast<Param*>(param->copy());
+	return xDynamicCast<Param*>(param->copy());
 }
 /*}}}*/
 IssmDouble* IoModel::Data(int data_enum){/*{{{*/
@@ -1454,7 +1454,7 @@
 	this->FetchData(&doublearray,&M,&N,vector_enum);
 
 	for(int i=0;i<elements->Size();i++){
-		Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 		if(!doublearray) element->AddInput(vector_enum,&default_value,P0Enum); 
 		else             element->InputCreate(doublearray,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
 	}
@@ -1484,21 +1484,21 @@
 		case 1: //boolean constant
 			this->FetchData(&boolean,vector_enum);
 			for(i=0;i<elements->Size();i++){
-				Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+				Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 				element->InputUpdateFromConstant(boolean,vector_enum);
 			}
 			break;
 		case 2: //integer constant
 			this->FetchData(&integer,vector_enum);
 			for(i=0;i<elements->Size();i++){
-				Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+				Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 				element->InputUpdateFromConstant(integer,vector_enum);
 			}
 			break;
 		case 3: //IssmDouble constant
 			this->FetchData(&scalar,vector_enum);
 			for(i=0;i<elements->Size();i++){
-				Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+				Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 				element->InputUpdateFromConstant(scalar,vector_enum);
 			}
 			break; 
@@ -1506,7 +1506,7 @@
 			this->FetchData(&doublearray,&M,&N,vector_enum); //we still have a doublearray, because it might include times in transient mode
 			if(!doublearray) _error_(EnumToStringx(vector_enum)<<" not found in binary file");
 			for(i=0;i<elements->Size();i++){
-				Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+				Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 				element->InputCreate(doublearray,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
 			}
 			break;
@@ -1514,7 +1514,7 @@
 			this->FetchData(&doublearray,&M,&N,vector_enum); //we still have a doublearray, because it might include times in transient mode
 			if(!doublearray) _error_(EnumToStringx(vector_enum)<<" not found in binary file");
 			for(i=0;i<elements->Size();i++){
-				Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+				Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 				element->InputCreate(doublearray,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
 			}
 			break;
@@ -1522,7 +1522,7 @@
 			this->FetchData(&doublearray,&M,&N,vector_enum);
 			if(!doublearray) _error_(EnumToStringx(vector_enum)<<" not found in binary file");
 			for(i=0;i<elements->Size();i++){
-				Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
+				Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
 				element->InputCreate(doublearray,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
 			}
 			break;
